• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
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.
5
6import json
7import os
8import shutil
9import tempfile
10import unittest
11
12import common_merge_script_tests
13import noop_merge
14
15
16class NoopMergeTest(unittest.TestCase):
17
18  # pylint: disable=super-with-arguments
19  def setUp(self):
20    super(NoopMergeTest, self).setUp()
21    self.temp_dir = tempfile.mkdtemp()
22
23  # pylint: enable=super-with-arguments
24
25  # pylint: disable=super-with-arguments
26  def tearDown(self):
27    shutil.rmtree(self.temp_dir)
28    super(NoopMergeTest, self).tearDown()
29
30  # pylint: enable=super-with-arguments
31
32  def test_copies_first_json(self):
33    input_json = os.path.join(self.temp_dir, 'input.json')
34    input_json_contents = {'foo': ['bar', 'baz']}
35    with open(input_json, 'w') as f:
36      json.dump(input_json_contents, f)
37    output_json = os.path.join(self.temp_dir, 'output.json')
38    self.assertEqual(0, noop_merge.noop_merge(output_json, [input_json]))
39    with open(output_json) as f:
40      self.assertEqual(input_json_contents, json.load(f))
41
42  def test_no_jsons(self):
43    output_json = os.path.join(self.temp_dir, 'output.json')
44    self.assertEqual(0, noop_merge.noop_merge(output_json, []))
45    with open(output_json) as f:
46      self.assertEqual({}, json.load(f))
47
48  def test_multiple_jsons(self):
49    input_json1 = os.path.join(self.temp_dir, 'input1.json')
50    input_json1_contents = {'test1': ['foo1', 'bar1']}
51    with open(input_json1, 'w') as f:
52      json.dump(input_json1_contents, f)
53    input_json2 = os.path.join(self.temp_dir, 'input2.json')
54    input_json2_contents = {'test2': ['foo2', 'bar2']}
55    with open(input_json2, 'w') as f:
56      json.dump(input_json2_contents, f)
57    output_json = os.path.join(self.temp_dir, 'output.json')
58    self.assertNotEqual(
59        0, noop_merge.noop_merge(output_json, [input_json1, input_json2]))
60
61
62class CommandLineTest(common_merge_script_tests.CommandLineTest):
63  # pylint: disable=super-with-arguments
64  def __init__(self, methodName='runTest'):
65    super(CommandLineTest, self).__init__(methodName, noop_merge)
66
67  # pylint: enable=super-with-arguments
68
69
70if __name__ == '__main__':
71  unittest.main()
72