:return: Iterator over text lines
"""
for diff_type, cnf, ancestry in self:
- ancestral_string = ' > '.join(f"{anc.name}={anc.value}" for anc in ancestry)
- output_func(f"cnf diff: {diff_type} {cnf.name} ({cnf.instance}) = {cnf.value!r} in "
+ if ancestry:
+ ancestral_string = 'in ' + ' > '.join(f"{anc.name}={anc.value}" for anc in ancestry)
+ else:
+ ancestral_string = ''
+ output_func(f"cnf diff: {diff_type} {cnf.name} ({cnf.instance}) = {cnf.value!r} "
+ ancestral_string)
"""Compare data to itself."""
self.assertEqual(CnfDiff(), self.DATA.compare(self.DATA))
- def test_remove(self):
- """Remove entry from data, check it is found."""
+ def test_remove_child(self):
+ """Remove child entry from data, check it is found."""
other = deepcopy(self.DATA)
removed = other.single_with_value("Star Trek").children\
.single_with_value("The Original Series").children\
"in franchise=Star Trek > series=The Original Series > ship=Enterprise (original)"
self.assertEqual(expect, diff_text[0])
+ def test_remove_root(self):
+ """Remove entry from data at root level, check it is found and properly textified"""
+ other = deepcopy(self.DATA)
+ removed = other.remove_where(lambda cnf: cnf.value == "Babylon 5")
+ self.assertEqual(1, len(removed))
+ diff = self.DATA.compare(other)
+ self.assertEqual(1, len(diff))
+ diff_text = []
+ diff.print(output_func=lambda s: diff_text.append(s))
+ self.assertEqual(1, len(diff_text))
+ expect = "cnf diff: - franchise (4) = 'Babylon 5' "
+ self.assertEqual(expect, diff_text[0])
+
def test_add(self):
"""Add entry to data, check it is found."""
other = deepcopy(self.DATA)