Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
deepdiff/tests/test_diff_tree.py at master · Mark90/deepdiff · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Mark90
/
deepdiff
Public
forked from
qlustered/deepdiff
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
deepdiff
/
tests
/
test_diff_tree.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
211 lines (175 loc) · 6.96 KB
master
Breadcrumbs
deepdiff
/
tests
/
test_diff_tree.py
Copy path
Top
File metadata and controls
Code
Blame
211 lines (175 loc) · 6.96 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
To run only the search tests:
python -m unittest tests.test_diff_tree
Or to run all the tests:
python -m unittest discover
Or to run all the tests with coverage:
coverage run --source deepdiff setup.py test
Or using Nose:
nosetests --with-coverage --cover-package=deepdiff
To run a specific test, run this from the root of repo:
python -m unittest tests.test_diff_tree.DeepDiffTreeTestCase.test_same_objects
"""
import
unittest
from
deepdiff
import
DeepDiff
from
deepdiff
.
helper
import
pypy3
,
notpresent
from
deepdiff
.
model
import
DictRelationship
,
NonSubscriptableIterableRelationship
import
logging
logging
.
disable
(
logging
.
CRITICAL
)
class
DeepDiffTreeTestCase
(
unittest
.
TestCase
):
"""DeepDiff Tests."""
def
test_same_objects
(
self
):
t1
=
{
1
:
1
,
2
:
2
,
3
:
3
}
t2
=
t1
ddiff
=
DeepDiff
(
t1
,
t2
)
res
=
ddiff
.
tree
self
.
assertEqual
(
res
, {})
def
test_significant_digits_signed_zero
(
self
):
t1
=
0.00001
t2
=
-
0.0001
ddiff
=
DeepDiff
(
t1
,
t2
,
significant_digits
=
2
)
res
=
ddiff
.
tree
self
.
assertEqual
(
res
, {})
t1
=
1
*
10
**
-
12
t2
=
-
1
*
10
**
-
12
ddiff
=
DeepDiff
(
t1
,
t2
,
significant_digits
=
10
)
res
=
ddiff
.
tree
self
.
assertEqual
(
res
, {})
def
test_item_added_extensive
(
self
):
t1
=
{
'one'
:
1
,
'two'
:
2
,
'three'
:
3
,
'four'
:
4
}
t2
=
{
'one'
:
1
,
'two'
:
2
,
'three'
:
3
,
'four'
:
4
,
'new'
:
1337
}
ddiff
=
DeepDiff
(
t1
,
t2
)
res
=
ddiff
.
tree
(
key
, )
=
res
.
keys
()
self
.
assertEqual
(
key
,
'dictionary_item_added'
)
self
.
assertEqual
(
len
(
res
[
'dictionary_item_added'
]),
1
)
(
added1
, )
=
res
[
'dictionary_item_added'
]
# assert added1 DiffLevel chain is valid at all
self
.
assertEqual
(
added1
.
up
.
down
,
added1
)
self
.
assertIsNone
(
added1
.
down
)
self
.
assertIsNone
(
added1
.
up
.
up
)
self
.
assertEqual
(
added1
.
all_up
,
added1
.
up
)
self
.
assertEqual
(
added1
.
up
.
all_down
,
added1
)
self
.
assertEqual
(
added1
.
report_type
,
'dictionary_item_added'
)
# assert DiffLevel chain points to the objects we entered
self
.
assertEqual
(
added1
.
up
.
t1
,
t1
)
self
.
assertEqual
(
added1
.
up
.
t2
,
t2
)
self
.
assertEqual
(
added1
.
t1
,
notpresent
)
self
.
assertEqual
(
added1
.
t2
,
1337
)
# assert DiffLevel child relationships are correct
self
.
assertIsNone
(
added1
.
up
.
t1_child_rel
)
self
.
assertIsInstance
(
added1
.
up
.
t2_child_rel
,
DictRelationship
)
self
.
assertEqual
(
added1
.
up
.
t2_child_rel
.
parent
,
added1
.
up
.
t2
)
self
.
assertEqual
(
added1
.
up
.
t2_child_rel
.
child
,
added1
.
t2
)
self
.
assertEqual
(
added1
.
up
.
t2_child_rel
.
param
,
'new'
)
self
.
assertEqual
(
added1
.
up
.
path
(),
"root"
)
self
.
assertEqual
(
added1
.
path
(),
"root['new']"
)
def
test_item_added_and_removed
(
self
):
t1
=
{
'one'
:
1
,
'two'
:
2
,
'three'
:
3
,
'four'
:
4
}
t2
=
{
'one'
:
1
,
'two'
:
4
,
'three'
:
3
,
'five'
:
5
,
'six'
:
6
}
ddiff
=
DeepDiff
(
t1
,
t2
,
view
=
'tree'
)
self
.
assertEqual
(
set
(
ddiff
.
keys
()), {
'dictionary_item_added'
,
'dictionary_item_removed'
,
'values_changed'
})
self
.
assertEqual
(
len
(
ddiff
[
'dictionary_item_added'
]),
2
)
self
.
assertEqual
(
len
(
ddiff
[
'dictionary_item_removed'
]),
1
)
def
test_item_added_and_removed2
(
self
):
t1
=
{
2
:
2
,
4
:
4
}
t2
=
{
2
:
"b"
,
5
:
5
}
ddiff
=
DeepDiff
(
t1
,
t2
,
view
=
'tree'
)
self
.
assertEqual
(
set
(
ddiff
.
keys
()), {
'dictionary_item_added'
,
'dictionary_item_removed'
,
'type_changes'
})
self
.
assertEqual
(
len
(
ddiff
[
'dictionary_item_added'
]),
1
)
self
.
assertEqual
(
len
(
ddiff
[
'dictionary_item_removed'
]),
1
)
def
test_non_subscriptable_iterable
(
self
):
t1
=
(
i
for
i
in
[
42
,
1337
,
31337
])
t2
=
(
i
for
i
in
[
42
,
1337
,
])
ddiff
=
DeepDiff
(
t1
,
t2
,
view
=
'tree'
)
(
change
, )
=
ddiff
[
'iterable_item_removed'
]
self
.
assertEqual
(
set
(
ddiff
.
keys
()), {
'iterable_item_removed'
})
self
.
assertEqual
(
len
(
ddiff
[
'iterable_item_removed'
]),
1
)
self
.
assertEqual
(
change
.
up
.
t1
,
t1
)
self
.
assertEqual
(
change
.
up
.
t2
,
t2
)
self
.
assertEqual
(
change
.
report_type
,
'iterable_item_removed'
)
self
.
assertEqual
(
change
.
t1
,
31337
)
self
.
assertEqual
(
change
.
t2
,
notpresent
)
self
.
assertIsInstance
(
change
.
up
.
t1_child_rel
,
NonSubscriptableIterableRelationship
)
self
.
assertIsNone
(
change
.
up
.
t2_child_rel
)
def
test_non_subscriptable_iterable_path
(
self
):
t1
=
(
i
for
i
in
[
42
,
1337
,
31337
])
t2
=
(
i
for
i
in
[
42
,
1337
, ])
ddiff
=
DeepDiff
(
t1
,
t2
,
view
=
'tree'
)
(
change
, )
=
ddiff
[
'iterable_item_removed'
]
# testing path
self
.
assertEqual
(
change
.
path
(),
None
)
self
.
assertEqual
(
change
.
path
(
force
=
'yes'
),
'root(unrepresentable)'
)
self
.
assertEqual
(
change
.
path
(
force
=
'fake'
),
'root[2]'
)
def
test_significant_digits
(
self
):
ddiff
=
DeepDiff
(
[
0.012
,
0.98
],
[
0.013
,
0.99
],
significant_digits
=
1
,
view
=
'tree'
)
self
.
assertEqual
(
ddiff
, {})
def
test_significant_digits_with_sets
(
self
):
ddiff
=
DeepDiff
(
{
0.012
,
0.98
},
{
0.013
,
0.99
},
significant_digits
=
1
,
view
=
'tree'
)
self
.
assertEqual
(
ddiff
, {})
def
test_significant_digits_with_ignore_order
(
self
):
ddiff
=
DeepDiff
(
[
0.012
,
0.98
], [
0.013
,
0.99
],
significant_digits
=
1
,
ignore_order
=
True
,
view
=
'tree'
)
self
.
assertEqual
(
ddiff
, {})
def
test_repr
(
self
):
t1
=
{
1
,
2
,
8
}
t2
=
{
1
,
2
,
3
,
5
}
ddiff
=
DeepDiff
(
t1
,
t2
,
view
=
'tree'
)
try
:
str
(
ddiff
)
except
Exception
as
e
:
self
.
fail
(
"Converting ddiff to string raised: {}"
.
format
(
e
))
class
DeepDiffTreeWithNumpyTestCase
(
unittest
.
TestCase
):
"""DeepDiff Tests with Numpy."""
def
setUp
(
self
):
if
not
pypy3
:
import
numpy
as
np
a1
=
np
.
array
([
1.23
,
1.66
,
1.98
])
a2
=
np
.
array
([
1.23
,
1.66
,
1.98
])
self
.
d1
=
{
'np'
:
a1
}
self
.
d2
=
{
'np'
:
a2
}
@
unittest
.
skipIf
(
pypy3
,
"Numpy is not compatible with pypy3"
)
def
test_diff_with_numpy
(
self
):
ddiff
=
DeepDiff
(
self
.
d1
,
self
.
d2
)
res
=
ddiff
.
tree
self
.
assertEqual
(
res
, {})
@
unittest
.
skipIf
(
pypy3
,
"Numpy is not compatible with pypy3"
)
def
test_diff_with_empty_seq
(
self
):
a1
=
{
"empty"
: []}
a2
=
{
"empty"
: []}
ddiff
=
DeepDiff
(
a1
,
a2
)
self
.
assertEqual
(
ddiff
, {})
class
DeepAdditionsTestCase
(
unittest
.
TestCase
):
"""Tests for Additions and Subtractions."""
@
unittest
.
expectedFailure
def
test_adding_list_diff
(
self
):
t1
=
[
1
,
2
]
t2
=
[
1
,
2
,
3
,
5
]
ddiff
=
DeepDiff
(
t1
,
t2
,
view
=
'tree'
)
addition
=
ddiff
+
t1
self
.
assertEqual
(
addition
,
t2
)
You can’t perform that action at this time.