xref: /aosp_15_r20/external/cronet/testing/merge_scripts/common_merge_script_tests.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2018 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import json
6import os
7import shutil
8import tempfile
9import unittest
10
11
12class CommandLineTest(unittest.TestCase):
13  # pylint: disable=super-with-arguments
14  def __init__(self, methodName, module):
15    super(CommandLineTest, self).__init__(methodName)
16    self._module = module
17  # pylint: disable=super-with-arguments
18
19  def setUp(self):
20    self.temp_dir = tempfile.mkdtemp(prefix='common_merge_script_tests')
21
22  def tearDown(self):
23    shutil.rmtree(self.temp_dir)
24
25  def test_accepts_task_output_dir(self):
26    task_output_dir = os.path.join(self.temp_dir, 'task_output_dir')
27    shard0_dir = os.path.join(task_output_dir, '0')
28    os.makedirs(shard0_dir)
29    summary_json = os.path.join(task_output_dir, 'summary.json')
30    with open(summary_json, 'w') as summary_file:
31      summary_contents = {
32        u'shards': [
33          {
34            u'state': u'COMPLETED',
35          },
36        ],
37      }
38      json.dump(summary_contents, summary_file)
39
40    shard0_json = os.path.join(shard0_dir, 'output.json')
41    with open(shard0_json, 'w') as shard0_file:
42      json.dump({}, shard0_file)
43
44    output_json = os.path.join(self.temp_dir, 'merged.json')
45
46    raw_args = [
47      '--task-output-dir', task_output_dir,
48      '--summary-json', summary_json,
49      '--output-json', output_json,
50      shard0_json,
51    ]
52    self.assertEqual(0, self._module.main(raw_args))
53