GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fixing the tests · benthomasson/deepdiff@6fcb3f8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .travis.yml
  • conftest.py
  • deepdiff
    • diff.py
  • tests
    • test_cache.py
    • test_delta.py
    • test_ignore_order.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.travis.yml‎

Copy file name to clipboardExpand all lines: .travis.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ matrix:
1212
install:
1313
- pip install -r requirements-dev.txt
1414

15-
script: pytest --cov=deepdiff tests/
15+
script: pytest --cov=deepdiff tests/ --runslow
1616

1717
after_success:
1818
- coveralls
Collapse file

‎conftest.py‎

Copy file name to clipboardExpand all lines: conftest.py
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'tests/fixtures/')
99

1010

11+
def pytest_addoption(parser):
12+
parser.addoption(
13+
"--runslow", action="store_true", default=False, help="run slow tests"
14+
)
15+
16+
17+
def pytest_configure(config):
18+
config.addinivalue_line("markers", "slow: mark test as slow to run")
19+
20+
21+
def pytest_collection_modifyitems(config, items):
22+
if config.getoption("--runslow"):
23+
# --runslow given in cli: do not skip slow tests
24+
return
25+
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
26+
for item in items:
27+
if "slow" in item.keywords:
28+
item.add_marker(skip_slow)
29+
30+
1131
@pytest.fixture(scope='class')
1232
def nested_a_t1():
1333
with open(os.path.join(FIXTURES_DIR, 'nested_a_t1.json')) as the_file:
Collapse file

‎deepdiff/diff.py‎

Copy file name to clipboardExpand all lines: deepdiff/diff.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _report_progress(_stats, progress_logger, duration):
7878

7979
# What is the threshold to calculate pairs of items between 2 iterables.
8080
# For example 2 iterables that have nothing in common, do not need their pairs to be calculated.
81-
CUTOFF_INTERSECTION_FOR_PAIRS_DEFAULT = 0.4
81+
CUTOFF_INTERSECTION_FOR_PAIRS_DEFAULT = 0.7
8282

8383
DEEPHASH_PARAM_KEYS = (
8484
'exclude_types',
Collapse file

‎tests/test_cache.py‎

Copy file name to clipboardExpand all lines: tests/test_cache.py
+30-1Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import pytest
12
from deepdiff import DeepDiff
23

34

45
class TestCache:
56

7+
@pytest.mark.slow
68
def test_cache_deeply_nested_a1(self, nested_a_t1, nested_a_t2, nested_a_result):
79

810
# Very slow so it is saved as a fixture
@@ -27,6 +29,7 @@ def test_cache_deeply_nested_a1(self, nested_a_t1, nested_a_t2, nested_a_result)
2729
diff_of_diff = DeepDiff(nested_a_result, diff.to_dict(), ignore_order=True)
2830
assert not diff_of_diff
2931

32+
@pytest.mark.slow
3033
def test_cache_deeply_nested_a2(self, nested_a_t1, nested_a_t2, nested_a_result):
3134

3235
diff = DeepDiff(nested_a_t1, nested_a_t2, ignore_order=True,
@@ -120,7 +123,33 @@ def test_cache_1D_array_of_numbers_that_overlap(self):
120123
}
121124
assert expected_stats == stats
122125

123-
expected = {'values_changed': {'root[11]': {'new_value': 30, 'old_value': 12}, 'root[10]': {'new_value': 31, 'old_value': 11}, 'root[9]': {'new_value': 32, 'old_value': 10}}, 'iterable_item_removed': {'root[0]': 1, 'root[1]': 2, 'root[2]': 3, 'root[3]': 4, 'root[4]': 5, 'root[5]': 6, 'root[6]': 7, 'root[7]': 8, 'root[8]': 9}}
126+
expected = {
127+
'values_changed': {
128+
'root[11]': {
129+
'new_value': 30,
130+
'old_value': 12
131+
},
132+
'root[10]': {
133+
'new_value': 31,
134+
'old_value': 11
135+
},
136+
'root[9]': {
137+
'new_value': 32,
138+
'old_value': 10
139+
}
140+
},
141+
'iterable_item_removed': {
142+
'root[0]': 1,
143+
'root[1]': 2,
144+
'root[2]': 3,
145+
'root[3]': 4,
146+
'root[4]': 5,
147+
'root[5]': 6,
148+
'root[6]': 7,
149+
'root[7]': 8,
150+
'root[8]': 9
151+
}
152+
}
124153
assert expected == diff
125154

126155
def test_cache_does_not_affect_final_results(self):
Collapse file

‎tests/test_delta.py‎

Copy file name to clipboardExpand all lines: tests/test_delta.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ def test_delta_view_and_to_delta_dict_are_equal_when_parameteres_passed(self):
10051005
'number_to_string': number_to_string,
10061006
'cache_tuning_sample_size': 500,
10071007
'cache_size': 500,
1008+
'cutoff_intersection_for_pairs': 0.6,
10081009
}
10091010

10101011
expected = {'iterable_items_added_at_indexes': {'root': {1: 1, 2: 1, 3: 1}}, 'iterable_items_removed_at_indexes': {'root': {1: 2, 2: 2}}}
Collapse file

‎tests/test_ignore_order.py‎

Copy file name to clipboardExpand all lines: tests/test_ignore_order.py
+20-21Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,13 @@ def test_bool_vs_number(self):
564564
],
565565
}
566566

567-
ddiff = DeepDiff(t1, t2, ignore_order=True)
567+
ddiff = DeepDiff(t1, t2, ignore_order=True, cutoff_intersection_for_pairs=1)
568568
assert ddiff == {}
569569

570570
@pytest.mark.parametrize('max_passes, expected', [
571571
(0, {'values_changed': {'root[0]': {'new_value': {'key5': 'CHANGE', 'key6': 'val6'}, 'old_value': {'key3': [[[[[1, 2, 4, 5]]]]], 'key4': [7, 8]}}, 'root[1]': {'new_value': {'key3': [[[[[1, 3, 5, 4]]]]], 'key4': [7, 8]}, 'old_value': {'key5': 'val5', 'key6': 'val6'}}}}),
572572
(1, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}, "root[0]['key3'][0]": {'new_value': [[[[1, 3, 5, 4]]]], 'old_value': [[[[1, 2, 4, 5]]]]}}}),
573-
(20, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}, "root[0]['key3'][0][0][0][0][1]": {'new_value': 3, 'old_value': 2}}})
573+
(22, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}, "root[0]['key3'][0][0][0][0][1]": {'new_value': 3, 'old_value': 2}}})
574574
])
575575
def test_ignore_order_max_passes(self, max_passes, expected):
576576
t1 = [
@@ -595,13 +595,13 @@ def test_ignore_order_max_passes(self, max_passes, expected):
595595
},
596596
]
597597

598-
ddiff = DeepDiff(t1, t2, ignore_order=True, max_passes=max_passes, verbose_level=2, cache_size=5000)
598+
ddiff = DeepDiff(t1, t2, ignore_order=True, max_passes=max_passes, verbose_level=2, cache_size=5000, cutoff_intersection_for_pairs=1)
599599
assert expected == ddiff
600600

601601
@pytest.mark.parametrize('max_diffs, expected', [
602602
(1, {}),
603-
(50, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}}}),
604-
(63, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}, "root[0]['key3'][0][0][0][0][1]": {'new_value': 3, 'old_value': 2}}}),
603+
(65, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}}}),
604+
(80, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}, "root[0]['key3'][0][0][0][0][1]": {'new_value': 3, 'old_value': 2}}}),
605605
])
606606
def test_ignore_order_max_diffs(self, max_diffs, expected):
607607
t1 = [
@@ -627,7 +627,7 @@ def test_ignore_order_max_diffs(self, max_diffs, expected):
627627
]
628628

629629
# Note: these tests are not exactly deterministic
630-
ddiff = DeepDiff(t1, t2, ignore_order=True, max_diffs=max_diffs, verbose_level=2, cache_size=5000)
630+
ddiff = DeepDiff(t1, t2, ignore_order=True, max_diffs=max_diffs, verbose_level=2, cache_size=5000, cutoff_intersection_for_pairs=1)
631631
assert expected == ddiff
632632

633633
def test_stats_that_include_distance_cache_hits(self):
@@ -639,11 +639,10 @@ def test_stats_that_include_distance_cache_hits(self):
639639
[1, 2, 4, 10], [4, 2, 5]
640640
]
641641

642-
diff = DeepDiff(t1, t2, ignore_order=True, cache_size=5000)
642+
diff = DeepDiff(t1, t2, ignore_order=True, cache_size=5000, cutoff_intersection_for_pairs=1)
643643
expected = {
644-
'PASSES COUNT': 5,
645-
'DIFF COUNT': 29,
646-
'LEVEL CACHE HIT COUNT': 2,
644+
'PASSES COUNT': 7,
645+
'DIFF COUNT': 37,
647646
'DISTANCE CACHE HIT COUNT': 0,
648647
'MAX PASS LIMIT REACHED': False,
649648
'MAX DIFF LIMIT REACHED': False,
@@ -659,7 +658,7 @@ def test_decreasing_max_distances_to_keep_track_per_item(self):
659658
[1, 2, 4, 10], [4, 2, 5]
660659
]
661660

662-
diff = DeepDiff(t1, t2, ignore_order=True)
661+
diff = DeepDiff(t1, t2, ignore_order=True, cutoff_intersection_for_pairs=1)
663662
expected = {
664663
'values_changed': {
665664
'root[0][2]': {
@@ -685,7 +684,8 @@ def test_decreasing_max_distances_to_keep_track_per_item(self):
685684
diff = DeepDiff(t1,
686685
t2,
687686
ignore_order=True,
688-
max_distances_to_keep_track_per_item=1)
687+
max_distances_to_keep_track_per_item=1,
688+
cutoff_intersection_for_pairs=1)
689689
expected = {
690690
'values_changed': {
691691
'root[0][2]': {
@@ -711,7 +711,7 @@ def test_ignore_order_report_repetition_and_self_loop(self):
711711
t2 = [[1, 2, 2, 2, 4]]
712712
t2.append(t2)
713713

714-
diff = DeepDiff(t1, t2, ignore_order=True)
714+
diff = DeepDiff(t1, t2, ignore_order=True, cutoff_intersection_for_pairs=1)
715715
expected = {
716716
'values_changed': {
717717
'root[0][3]': {
@@ -726,7 +726,7 @@ def test_ignore_order_report_repetition_and_self_loop(self):
726726
}
727727
assert expected == diff
728728

729-
diff2 = DeepDiff(t1, t2, ignore_order=True, cache_size=0)
729+
diff2 = DeepDiff(t1, t2, ignore_order=True, cache_size=5000, cutoff_intersection_for_pairs=1)
730730
assert expected == diff2
731731

732732
def test_ignore_order_with_sha256_hash(self):
@@ -737,7 +737,7 @@ def test_ignore_order_with_sha256_hash(self):
737737
t2 = [
738738
[1, 2, 3, 10], [8, 2, 5]
739739
]
740-
diff = DeepDiff(t1, t2, ignore_order=True, hasher=sha256hex)
740+
diff = DeepDiff(t1, t2, ignore_order=True, hasher=sha256hex, cutoff_intersection_for_pairs=1)
741741
expected = {
742742
'values_changed': {
743743
'root[0][3]': {
@@ -755,7 +755,7 @@ def test_ignore_order_with_sha256_hash(self):
755755
def test_ignore_order_cache_for_individual_distances(self):
756756
t1 = [[1, 2, 'B', 3], 'B']
757757
t2 = [[1, 2, 3, 5], 5]
758-
diff = DeepDiff(t1, t2, ignore_order=True, cache_size=5000)
758+
diff = DeepDiff(t1, t2, ignore_order=True, cache_size=5000, cutoff_intersection_for_pairs=1)
759759
expected = {
760760
'values_changed': {
761761
'root[1]': {
@@ -774,16 +774,15 @@ def test_ignore_order_cache_for_individual_distances(self):
774774

775775
stats = diff.get_stats()
776776
expected_stats = {
777-
'PASSES COUNT': 2,
778-
'DIFF COUNT': 11,
779-
'LEVEL CACHE HIT COUNT': 1,
777+
'PASSES COUNT': 3,
778+
'DIFF COUNT': 13,
780779
'DISTANCE CACHE HIT COUNT': 1,
781780
'MAX PASS LIMIT REACHED': False,
782-
'MAX DIFF LIMIT REACHED': False,
781+
'MAX DIFF LIMIT REACHED': False
783782
}
784783
assert expected_stats == stats
785784

786785
t1 = [[1, 2, 'B', 3], 5]
787786
t2 = [[1, 2, 3, 5], 'B']
788-
diff2 = DeepDiff(t1, t2, ignore_order=True, cache_size=5000)
787+
diff2 = DeepDiff(t1, t2, ignore_order=True, cache_size=5000, cutoff_intersection_for_pairs=1)
789788
assert expected_stats == diff2.get_stats()

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.