Skip to content

Commit

Permalink
diff: fix comparison of sets
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel B <dbaah@spatialdev.com>
  • Loading branch information
jirikuncar and Daniel B authored Dec 13, 2019
1 parent 2f41d54 commit 5601b11
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dictdiffer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def check(key):
if len(deletion):
yield REMOVE, dotted_node, [(0, deletion)]

return # stop here for sets

if differ:
# Compare if object is a dictionary or list.
#
Expand Down
15 changes: 15 additions & 0 deletions tests/test_dictdiffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ def test_change_set(self):
assert ('add', 'a', [(0, set([4]))]) in diffed
assert ('remove', 'a', [(0, set([0]))]) in diffed

def test_add_set_shift_order(self):
first = set(["changeA", "changeB"])
second = set(["changeA", "changeC", "changeB"])
diffed = list(diff(first, second))
# There should only be 1 change reported
assert len(diffed) == 1
assert ('add', '', [(0, {'changeC'})]) in diffed

def test_change_set_order(self):
first = set(["changeA", "changeC", "changeB"])
second = set(["changeB", "changeC", "changeA"])
diffed = list(diff(first, second))
# There should be zero reported diffs
assert len(diffed) == 0

def test_types(self):
first = {'a': ['a']}
second = {'a': 'a'}
Expand Down

0 comments on commit 5601b11

Please sign in to comment.