Skip to content

Commit 70c53bd

Browse files
committed
Extend deepdiff-hello.py
1 parent 5b150bf commit 70c53bd

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

Python/deepdiff-hello/deepdiff-hello.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,25 @@
1010
from deepdiff import DeepDiff
1111
from pydantic import BaseModel
1212

13-
print("--- 1 simple DeepDiff ---\n")
13+
print("--- 1 simple DeepDiff with dicts ---\n")
1414

1515
d = {
1616
"my": {
1717
"nested": "dict",
1818
"value": 42,
19+
"timestamp": 123,
1920
},
2021
}
2122
e = {
2223
"my": {
2324
"other": "dict",
2425
"value": 42,
26+
"timestamp": 345,
2527
},
2628
}
2729
print(f"{DeepDiff(d, e) = }")
2830

29-
print("\n--- 2 DeepDiff with Pydantic models ---\n")
31+
print("\n--- 2 with Pydantic models ---\n")
3032

3133

3234
class Nested(BaseModel):
@@ -45,20 +47,47 @@ class MyModel(BaseModel):
4547

4648
print(f"{DeepDiff(m, n) = }")
4749

48-
print("\n--- 2 DeepDiff exclude_paths with Pydantic models ---\n")
50+
print("\n--- 2 exclude_paths with Pydantic models ---\n")
4951

5052
exclude_paths = ["root.status", "root.nested.v"]
51-
print(f"{DeepDiff(m, n, exclude_paths=["root.status"]) = }")
52-
print(f"{DeepDiff(m, n, exclude_paths=["root.nested.v"]) = }")
53-
print(f"{DeepDiff(m, n, exclude_paths=["root.status", "root.nested.v"]) = }")
53+
print(f"{DeepDiff(m, n, exclude_paths=["status"]) = }")
54+
print(f"{DeepDiff(m, n, exclude_paths=["root.status"]) = }") # just the same
55+
56+
print(f"{DeepDiff(m, n, exclude_paths=["nested.v"]) = }")
57+
print(f"{DeepDiff(m, n, exclude_paths=["root.nested.v"]) = }") # just the same
5458

59+
print(f"{DeepDiff(m, n, exclude_paths=["root.status", "root.nested.v"]) = }")
5560

56-
print("\n--- 3 DeepDiff exclude_paths with lists of Pydantic models ---\n")
61+
print("\n--- 3 exclude_regex_paths with lists of Pydantic models ---\n")
5762

5863
l = [Nested(v=1, w=2), Nested(v=2, w=3), Nested(v=3, w=4)]
5964
k = [Nested(v=4, w=2), Nested(v=5, w=3), Nested(v=6, w=5)]
6065

6166
print(f"{DeepDiff(l, k) = }")
6267

6368
# ignore all .v's
64-
print(f"{DeepDiff(l, k, exclude_regex_paths=[r"root\[\d+\].v"]) = }")
69+
my_regex = r"root\[\d+\].v"
70+
print(f"{DeepDiff(l, k, exclude_regex_paths=[my_regex]) = }")
71+
72+
73+
print("\n--- 4 exclude_paths with dicts ---\n")
74+
75+
print(f"{DeepDiff(d, e, exclude_paths=["root['my']['timestamp']"]) = }")
76+
77+
print(f"{DeepDiff(d, e, exclude_paths=["root['my']['timestamp']","root['my']['nested']","root['my']['other']"]) = }")
78+
79+
80+
print("\n--- 5 dict against None works ---\n")
81+
82+
print(f"{DeepDiff(None, d) =}")
83+
84+
print("\n--- 5 Pydantic model against None with exclude works ---\n")
85+
86+
print(f"{DeepDiff(None, Nested(v=11, w=12), exclude_paths=['v'])}")
87+
88+
print("\n--- 6 Falsiness of DeepDiff when identical objects ---\n")
89+
90+
if DeepDiff(None, None):
91+
print("Deepdiff is truthy")
92+
else:
93+
print("Deepdiff is falsy") # this holds

0 commit comments

Comments
 (0)