-
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from datetime import date, datetime, time | ||
from deepdiff import DeepDiff | ||
|
||
|
||
class TestDiffDatetime: | ||
def test_datetime_diff(self): | ||
"""Testing for the correct setting and usage of epsilon.""" | ||
d1 = {"a": datetime(2023, 7, 5, 10, 11, 12)} | ||
d2 = {"a": datetime(2023, 7, 5, 10, 11, 12)} | ||
res = DeepDiff(d1, d2) | ||
assert res == {} | ||
|
||
res = DeepDiff(d1, d2, ignore_numeric_type_changes=True) | ||
assert res == {} | ||
|
||
d1 = {"a": datetime(2023, 7, 5, 10, 11, 12)} | ||
d2 = {"a": datetime(2023, 7, 5, 11, 11, 12)} | ||
res = DeepDiff(d1, d2) | ||
expected = { | ||
"values_changed": { | ||
"root['a']": { | ||
"new_value": datetime(2023, 7, 5, 11, 11, 12), | ||
"old_value": datetime(2023, 7, 5, 10, 11, 12), | ||
} | ||
} | ||
} | ||
assert res == expected | ||
|
||
|
||
def test_date_diff(self): | ||
"""Testing for the correct setting and usage of epsilon.""" | ||
d1 = {"a": date(2023, 7, 5)} | ||
d2 = {"a": date(2023, 7, 5)} | ||
res = DeepDiff(d1, d2) | ||
assert res == {} | ||
|
||
# this usage failed in version >=6.0, <=6.3.0 | ||
res = DeepDiff(d1, d2, ignore_numeric_type_changes=True) | ||
assert res == {} | ||
|
||
d1 = {"a": date(2023, 7, 5)} | ||
d2 = {"a": date(2023, 7, 6)} | ||
res = DeepDiff(d1, d2) | ||
expected = { | ||
"values_changed": { | ||
"root['a']": { | ||
"new_value": date(2023, 7, 6), | ||
"old_value": date(2023, 7, 5), | ||
} | ||
} | ||
} | ||
assert res == expected | ||
|
||
def test_time_diff(self): | ||
"""Testing for the correct setting and usage of epsilon.""" | ||
d1 = {"a": time(10, 11, 12)} | ||
d2 = {"a": time(10, 11, 12)} | ||
res = DeepDiff(d1, d2) | ||
assert res == {} | ||
|
||
res = DeepDiff(d1, d2, ignore_numeric_type_changes=True) | ||
assert res == {} | ||
|
||
d1 = {"a": time(10, 11, 12)} | ||
d2 = {"a": time(11, 11, 12)} | ||
res = DeepDiff(d1, d2) | ||
expected = { | ||
"values_changed": { | ||
"root['a']": { | ||
"new_value": time(11, 11, 12), | ||
"old_value": time(10, 11, 12), | ||
} | ||
} | ||
} | ||
assert res == expected |