Coverage for tests/test_merge_documents.py: 54%
20 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 02:51 -0700
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 02:51 -0700
1# This file is part of verify.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
21"""Test yamlutils.merge_documents."""
23import unittest
24from collections import OrderedDict
25from copy import deepcopy
27from lsst.verify.yamlutils import merge_documents
30class TestMergeDocuments(unittest.TestCase):
31 """Test merge_documents, demonstrating how embedded dictionaries and
32 lists are merged.
33 """
35 def setUp(self):
36 self.base_doc = OrderedDict([
37 ('A', 'a value'),
38 ('B', 'b value'),
39 ('C', [1, 2]),
40 ('D', OrderedDict([
41 ('a', 'a value'),
42 ('b', 'b value'),
43 ('c', OrderedDict([
44 ('alpha', 1),
45 ('beta', 3)
46 ]))
47 ])),
48 ('E', OrderedDict(hello='world'))
49 ])
50 self.base_doc_copy = deepcopy(self.base_doc)
52 self.new_doc = OrderedDict([
53 ('B', 'over-written value'),
54 ('Z', 'new value'),
55 ('C', [3, 4]),
56 ('D', OrderedDict([
57 ('d', 'd value'),
58 ('c', OrderedDict([
59 ('beta', 2),
60 ('gamma', 3)
61 ]))
62 ])),
63 ('E', 'good-bye'),
64 ])
65 self.new_doc_copy = deepcopy(self.new_doc)
67 self.expected = OrderedDict([
68 ('A', 'a value'),
69 ('B', 'over-written value'),
70 ('C', [1, 2, 3, 4]),
71 ('D', OrderedDict([
72 ('a', 'a value'),
73 ('b', 'b value'),
74 ('c', OrderedDict([
75 ('alpha', 1),
76 ('beta', 2),
77 ('gamma', 3)
78 ])),
79 ('d', 'd value')
80 ])),
81 ('E', 'good-bye'),
82 ('Z', 'new value'),
83 ])
85 self.merged = merge_documents(self.base_doc, self.new_doc)
87 def test_merge(self):
88 self.assertEqual(self.merged, self.expected)
90 def test_immutability(self):
91 """Ensure the inputs are unchanged."""
92 self.assertEqual(self.base_doc, self.base_doc_copy)
93 self.assertEqual(self.new_doc, self.new_doc_copy)
96if __name__ == "__main__": 96 ↛ 97line 96 didn't jump to line 97, because the condition on line 96 was never true
97 unittest.main()