• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
18  # pylint: disable=super-with-arguments
19
20  def setUp(self):
21    self.temp_dir = tempfile.mkdtemp(prefix='common_merge_script_tests')
22
23  def tearDown(self):
24    shutil.rmtree(self.temp_dir)
25
26  def test_accepts_task_output_dir(self):
27    task_output_dir = os.path.join(self.temp_dir, 'task_output_dir')
28    shard0_dir = os.path.join(task_output_dir, '0')
29    os.makedirs(shard0_dir)
30    summary_json = os.path.join(task_output_dir, 'summary.json')
31    with open(summary_json, 'w') as summary_file:
32      summary_contents = {
33          u'shards': [
34              {
35                  u'state': u'COMPLETED',
36              },
37          ],
38      }
39      json.dump(summary_contents, summary_file)
40
41    shard0_json = os.path.join(shard0_dir, 'output.json')
42    with open(shard0_json, 'w') as shard0_file:
43      json.dump({}, shard0_file)
44
45    output_json = os.path.join(self.temp_dir, 'merged.json')
46
47    raw_args = [
48        '--task-output-dir',
49        task_output_dir,
50        '--summary-json',
51        summary_json,
52        '--output-json',
53        output_json,
54        shard0_json,
55    ]
56    self.assertEqual(0, self._module.main(raw_args))
57