Skip to content

Commit

Permalink
fixing the issue with None in type group
Browse files Browse the repository at this point in the history
  • Loading branch information
seperman committed Jul 23, 2020
1 parent ab93181 commit 47a141f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
3 changes: 3 additions & 0 deletions deepdiff/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,9 @@ def __diff(self, level, parents_ids=frozenset(), _original_type=None):
if report_type_change:
self.__diff_types(level)
return
# This is an edge case where t1=None and None is in the ignore type group.
if level.t1 is None:
self.__report_result('values_changed', level)

if self.ignore_nan_inequality and isinstance(level.t1, float) and str(level.t1) == str(level.t2) == 'nan':
return
Expand Down
34 changes: 19 additions & 15 deletions tests/test_diff_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ class ClassB:
assert result == ddiff

def test_custom_class_changes_none_when_ignore_type(self):
ddiff = DeepDiff({'a': None}, {'a': 1}, ignore_type_subclasses=True, ignore_type_in_groups=[(int, float)])
ddiff1 = DeepDiff({'a': None}, {'a': 1}, ignore_type_subclasses=True, ignore_type_in_groups=[(int, float)])
result = {
'type_changes': {
"root['a']": {
Expand All @@ -582,20 +582,13 @@ def test_custom_class_changes_none_when_ignore_type(self):
}
}
}
assert result == ddiff
assert result == ddiff1

ddiff = DeepDiff({'a': 1}, {'a': None}, ignore_type_subclasses=True, ignore_type_in_groups=[(int, float)])
result = {
'type_changes': {
"root['a']": {
'old_type': int,
'new_type': type(None),
'old_value': 1,
'new_value': None
}
}
}
assert result == ddiff
ddiff2 = DeepDiff({'a': None}, {'a': 1}, ignore_type_subclasses=True, ignore_type_in_groups=[(int, float, None)])
assert {'values_changed': {"root['a']": {'new_value': 1, 'old_value': None}}} == ddiff2

ddiff3 = DeepDiff({'a': 1}, {'a': None}, ignore_type_subclasses=True, ignore_type_in_groups=[(int, float, None)])
assert {'values_changed': {"root['a']": {'new_value': None, 'old_value': 1}}} == ddiff3

def test_custom_object_changes_when_ignore_type_in_groups(self):
class ClassA:
Expand Down Expand Up @@ -1130,7 +1123,18 @@ def test_ignore_type_in_groups_none_and_objects(self):
t1 = [1, 2, 3, 'a', None]
t2 = [1.0, 2.0, 3.3, b'a', 'hello']
ddiff = DeepDiff(t1, t2, ignore_type_in_groups=[(1, 1.0), (None, str, bytes)])
result = {'values_changed': {'root[2]': {'new_value': 3.3, 'old_value': 3}}}
result = {
'values_changed': {
'root[2]': {
'new_value': 3.3,
'old_value': 3
},
'root[4]': {
'new_value': 'hello',
'old_value': None
}
}
}
assert result == ddiff

def test_ignore_type_in_groups_str_and_datetime(self):
Expand Down

0 comments on commit 47a141f

Please sign in to comment.