Skip to content

Commit 97f1d19

Browse files
authored
Merge pull request #81 from MJedr/comparator-fix
fix comparator for empty fields
2 parents b207476 + 2a2f83e commit 97f1d19

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

json_merger/comparator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def _get_compared_objects_at_field_path(self, obj1, obj2, field):
113113

114114
def _have_field_equal(self, obj1, obj2, field):
115115
o1, o2 = self._get_compared_objects_at_field_path(obj1, obj2, field)
116+
if o1 == NOTHING and o2 == NOTHING:
117+
return True
116118
if o1 == NOTHING or o2 == NOTHING:
117119
return False
118120

tests/unit/test_comparator.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ class MyComp(PrimaryKeyComparator):
5656

5757
inst = MyComp(lst1, lst2)
5858

59-
assert not inst.get_matches('l1', 0)
60-
assert not inst.get_matches('l1', 1)
61-
assert not inst.get_matches('l2', 0)
62-
assert not inst.get_matches('l2', 1)
59+
assert inst.get_matches('l1', 0)
60+
assert inst.get_matches('l1', 1)
61+
assert inst.get_matches('l2', 0)
62+
assert inst.get_matches('l2', 1)
6363
assert not inst.get_matches('l2', 3)
6464

6565
assert inst.get_matches('l1', 2) == [(2, lst2[2])]
@@ -81,10 +81,10 @@ class MyComp(PrimaryKeyComparator):
8181

8282
inst = MyComp(lst1, lst2)
8383

84-
assert not inst.get_matches('l1', 0)
85-
assert not inst.get_matches('l1', 1)
86-
assert not inst.get_matches('l2', 0)
87-
assert not inst.get_matches('l2', 1)
84+
assert inst.get_matches('l1', 0)
85+
assert inst.get_matches('l1', 1)
86+
assert inst.get_matches('l2', 0)
87+
assert inst.get_matches('l2', 1)
8888
assert not inst.get_matches('l2', 3)
8989

9090
assert inst.get_matches('l1', 2) == [(2, lst2[2])]

0 commit comments

Comments
 (0)