Skip to content

Commit

Permalink
Merge pull request #81 from MJedr/comparator-fix
Browse files Browse the repository at this point in the history
fix comparator for empty fields
  • Loading branch information
MJedr authored Nov 24, 2021
2 parents b207476 + 2a2f83e commit 97f1d19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions json_merger/comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def _get_compared_objects_at_field_path(self, obj1, obj2, field):

def _have_field_equal(self, obj1, obj2, field):
o1, o2 = self._get_compared_objects_at_field_path(obj1, obj2, field)
if o1 == NOTHING and o2 == NOTHING:
return True
if o1 == NOTHING or o2 == NOTHING:
return False

Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class MyComp(PrimaryKeyComparator):

inst = MyComp(lst1, lst2)

assert not inst.get_matches('l1', 0)
assert not inst.get_matches('l1', 1)
assert not inst.get_matches('l2', 0)
assert not inst.get_matches('l2', 1)
assert inst.get_matches('l1', 0)
assert inst.get_matches('l1', 1)
assert inst.get_matches('l2', 0)
assert inst.get_matches('l2', 1)
assert not inst.get_matches('l2', 3)

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

inst = MyComp(lst1, lst2)

assert not inst.get_matches('l1', 0)
assert not inst.get_matches('l1', 1)
assert not inst.get_matches('l2', 0)
assert not inst.get_matches('l2', 1)
assert inst.get_matches('l1', 0)
assert inst.get_matches('l1', 1)
assert inst.get_matches('l2', 0)
assert inst.get_matches('l2', 1)
assert not inst.get_matches('l2', 3)

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

0 comments on commit 97f1d19

Please sign in to comment.