def test_merge(self): # parse the readme and check that the merging scenarios are corrects with open('README.rst', 'r') as f: doc, pub = docutils.examples.internals(f.read(), input_encoding='utf8') for table in doc.traverse(condition=docutils.nodes.table): for row in table.traverse(condition=docutils.nodes.row)[1:]: if len(row) != 3: continue before, data, after = (yaml.load(c.astext()) for c in row) merged = stack._merge_dict(copy.deepcopy(before), copy.deepcopy(data)) before_yml, data_yml, after_yml, merged_yml = (yaml.dump( yml, default_flow_style=False) for yml in (before, data, after, merged)) self.assertEqual(merged, after, msg='\n'.join([ '\nBEFORE =>', before_yml, 'DATA =>', data_yml, 'MERGES TO =>', merged_yml, 'INSTEAD OF =>', after_yml, ]))
def test_merge(self): # parse the readme and check that the merging scenarios are corrects with open("README.rst", "r") as f: doc, pub = docutils.examples.internals(f.read(), input_encoding="utf8") for table in doc.traverse(condition=docutils.nodes.table): for row in table.traverse(condition=docutils.nodes.row)[1:]: if len(row) != 3: continue before, data, after = (yaml.load(c.astext()) for c in row) merged = stack._merge_dict(copy.deepcopy(before), copy.deepcopy(data)) before_yml, data_yml, after_yml, merged_yml = ( yaml.dump(yml, default_flow_style=False) for yml in (before, data, after, merged) ) self.assertEqual( merged, after, msg="\n".join( [ "\nBEFORE =>", before_yml, "DATA =>", data_yml, "MERGES TO =>", merged_yml, "INSTEAD OF =>", after_yml, ] ), )
def _merge(pathname, common): """ Merge the files via stack.py """ merged = {} for filename in common[pathname]: with open(filename, "r") as content: content = yaml.safe_load(content) # pylint: disable=protected-access merged = _merge_dict(merged, content) return merged