2 # Copyright 2017 The Chromium Authors
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
13 import common_merge_script_tests
15 THIS_DIR = os.path.dirname(__file__)
18 0, os.path.abspath(os.path.join(THIS_DIR, '..', 'resources')))
22 class NoopMergeTest(unittest.TestCase):
24 # pylint: disable=super-with-arguments
26 super(NoopMergeTest, self).setUp()
27 self.temp_dir = tempfile.mkdtemp()
28 # pylint: enable=super-with-arguments
30 # pylint: disable=super-with-arguments
32 shutil.rmtree(self.temp_dir)
33 super(NoopMergeTest, self).tearDown()
34 # pylint: enable=super-with-arguments
36 def test_copies_first_json(self):
37 input_json = os.path.join(self.temp_dir, 'input.json')
38 input_json_contents = {'foo': ['bar', 'baz']}
39 with open(input_json, 'w') as f:
40 json.dump(input_json_contents, f)
41 output_json = os.path.join(self.temp_dir, 'output.json')
42 self.assertEqual(0, noop_merge.noop_merge(output_json, [input_json]))
43 with open(output_json) as f:
44 self.assertEqual(input_json_contents, json.load(f))
46 def test_no_jsons(self):
47 output_json = os.path.join(self.temp_dir, 'output.json')
48 self.assertEqual(0, noop_merge.noop_merge(output_json, []))
49 with open(output_json) as f:
50 self.assertEqual({}, json.load(f))
52 def test_multiple_jsons(self):
53 input_json1 = os.path.join(self.temp_dir, 'input1.json')
54 input_json1_contents = {'test1': ['foo1', 'bar1']}
55 with open(input_json1, 'w') as f:
56 json.dump(input_json1_contents, f)
57 input_json2 = os.path.join(self.temp_dir, 'input2.json')
58 input_json2_contents = {'test2': ['foo2', 'bar2']}
59 with open(input_json2, 'w') as f:
60 json.dump(input_json2_contents, f)
61 output_json = os.path.join(self.temp_dir, 'output.json')
63 0, noop_merge.noop_merge(output_json, [input_json1, input_json2]))
66 class CommandLineTest(common_merge_script_tests.CommandLineTest):
67 # pylint: disable=super-with-arguments
68 def __init__(self, methodName='runTest'):
69 super(CommandLineTest, self).__init__(methodName, noop_merge)
70 # pylint: enable=super-with-arguments
72 if __name__ == '__main__':