GeezerVison is showing github.com — fixing the tests · benthomasson/deepdiff@6fcb3f8
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .travis.yml +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,7 @@ matrix: | 12 | 12 | install: | 13 | 13 | - pip install -r requirements-dev.txt | 14 | 14 |
| 15 | | -script: pytest --cov=deepdiff tests/ | | 15 | +script: pytest --cov=deepdiff tests/ --runslow | 16 | 16 |
| 17 | 17 | after_success: | 18 | 18 | - coveralls |
Collapse file Copy file name to clipboardExpand all lines: conftest.py +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'tests/fixtures/') | 9 | 9 |
| 10 | 10 |
| | 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 | + | 11 | 31 | @pytest.fixture(scope='class') | 12 | 32 | def nested_a_t1(): | 13 | 33 | with open(os.path.join(FIXTURES_DIR, 'nested_a_t1.json')) as the_file: | |
Collapse file Copy file name to clipboardExpand all lines: deepdiff/diff.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,7 +78,7 @@ def _report_progress(_stats, progress_logger, duration): | 78 | 78 |
| 79 | 79 | # What is the threshold to calculate pairs of items between 2 iterables. | 80 | 80 | # 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 | 82 | 82 |
| 83 | 83 | DEEPHASH_PARAM_KEYS = ( | 84 | 84 | 'exclude_types', | |
Collapse file Copy file name to clipboardExpand all lines: tests/test_cache.py +30-1Lines changed: 30 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import pytest | 1 | 2 | from deepdiff import DeepDiff | 2 | 3 |
| 3 | 4 |
| 4 | 5 | class TestCache: | 5 | 6 |
| | 7 | + @pytest.mark.slow | 6 | 8 | def test_cache_deeply_nested_a1(self, nested_a_t1, nested_a_t2, nested_a_result): | 7 | 9 |
| 8 | 10 | # 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) | 27 | 29 | diff_of_diff = DeepDiff(nested_a_result, diff.to_dict(), ignore_order=True) | 28 | 30 | assert not diff_of_diff | 29 | 31 |
| | 32 | + @pytest.mark.slow | 30 | 33 | def test_cache_deeply_nested_a2(self, nested_a_t1, nested_a_t2, nested_a_result): | 31 | 34 |
| 32 | 35 | 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): | 120 | 123 | } | 121 | 124 | assert expected_stats == stats | 122 | 125 |
| 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 | + } | 124 | 153 | assert expected == diff | 125 | 154 |
| 126 | 155 | def test_cache_does_not_affect_final_results(self): | |
Collapse file Copy file name to clipboardExpand all lines: tests/test_delta.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1005,6 +1005,7 @@ def test_delta_view_and_to_delta_dict_are_equal_when_parameteres_passed(self): | 1005 | 1005 | 'number_to_string': number_to_string, | 1006 | 1006 | 'cache_tuning_sample_size': 500, | 1007 | 1007 | 'cache_size': 500, | | 1008 | + 'cutoff_intersection_for_pairs': 0.6, | 1008 | 1009 | } | 1009 | 1010 |
| 1010 | 1011 | 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 Copy file name to clipboardExpand all lines: tests/test_ignore_order.py +20-21Lines changed: 20 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -564,13 +564,13 @@ def test_bool_vs_number(self): | 564 | 564 | ], | 565 | 565 | } | 566 | 566 |
| 567 | | - ddiff = DeepDiff(t1, t2, ignore_order=True) | | 567 | + ddiff = DeepDiff(t1, t2, ignore_order=True, cutoff_intersection_for_pairs=1) | 568 | 568 | assert ddiff == {} | 569 | 569 |
| 570 | 570 | @pytest.mark.parametrize('max_passes, expected', [ | 571 | 571 | (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'}}}}), | 572 | 572 | (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}}}) | 574 | 574 | ]) | 575 | 575 | def test_ignore_order_max_passes(self, max_passes, expected): | 576 | 576 | t1 = [ | @@ -595,13 +595,13 @@ def test_ignore_order_max_passes(self, max_passes, expected): | 595 | 595 | }, | 596 | 596 | ] | 597 | 597 |
| 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) | 599 | 599 | assert expected == ddiff | 600 | 600 |
| 601 | 601 | @pytest.mark.parametrize('max_diffs, expected', [ | 602 | 602 | (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}}}), | 605 | 605 | ]) | 606 | 606 | def test_ignore_order_max_diffs(self, max_diffs, expected): | 607 | 607 | t1 = [ | @@ -627,7 +627,7 @@ def test_ignore_order_max_diffs(self, max_diffs, expected): | 627 | 627 | ] | 628 | 628 |
| 629 | 629 | # 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) | 631 | 631 | assert expected == ddiff | 632 | 632 |
| 633 | 633 | def test_stats_that_include_distance_cache_hits(self): | @@ -639,11 +639,10 @@ def test_stats_that_include_distance_cache_hits(self): | 639 | 639 | [1, 2, 4, 10], [4, 2, 5] | 640 | 640 | ] | 641 | 641 |
| 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) | 643 | 643 | expected = { | 644 | | - 'PASSES COUNT': 5, | 645 | | - 'DIFF COUNT': 29, | 646 | | - 'LEVEL CACHE HIT COUNT': 2, | | 644 | + 'PASSES COUNT': 7, | | 645 | + 'DIFF COUNT': 37, | 647 | 646 | 'DISTANCE CACHE HIT COUNT': 0, | 648 | 647 | 'MAX PASS LIMIT REACHED': False, | 649 | 648 | 'MAX DIFF LIMIT REACHED': False, | @@ -659,7 +658,7 @@ def test_decreasing_max_distances_to_keep_track_per_item(self): | 659 | 658 | [1, 2, 4, 10], [4, 2, 5] | 660 | 659 | ] | 661 | 660 |
| 662 | | - diff = DeepDiff(t1, t2, ignore_order=True) | | 661 | + diff = DeepDiff(t1, t2, ignore_order=True, cutoff_intersection_for_pairs=1) | 663 | 662 | expected = { | 664 | 663 | 'values_changed': { | 665 | 664 | 'root[0][2]': { | @@ -685,7 +684,8 @@ def test_decreasing_max_distances_to_keep_track_per_item(self): | 685 | 684 | diff = DeepDiff(t1, | 686 | 685 | t2, | 687 | 686 | 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) | 689 | 689 | expected = { | 690 | 690 | 'values_changed': { | 691 | 691 | 'root[0][2]': { | @@ -711,7 +711,7 @@ def test_ignore_order_report_repetition_and_self_loop(self): | 711 | 711 | t2 = [[1, 2, 2, 2, 4]] | 712 | 712 | t2.append(t2) | 713 | 713 |
| 714 | | - diff = DeepDiff(t1, t2, ignore_order=True) | | 714 | + diff = DeepDiff(t1, t2, ignore_order=True, cutoff_intersection_for_pairs=1) | 715 | 715 | expected = { | 716 | 716 | 'values_changed': { | 717 | 717 | 'root[0][3]': { | @@ -726,7 +726,7 @@ def test_ignore_order_report_repetition_and_self_loop(self): | 726 | 726 | } | 727 | 727 | assert expected == diff | 728 | 728 |
| 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) | 730 | 730 | assert expected == diff2 | 731 | 731 |
| 732 | 732 | def test_ignore_order_with_sha256_hash(self): | @@ -737,7 +737,7 @@ def test_ignore_order_with_sha256_hash(self): | 737 | 737 | t2 = [ | 738 | 738 | [1, 2, 3, 10], [8, 2, 5] | 739 | 739 | ] | 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) | 741 | 741 | expected = { | 742 | 742 | 'values_changed': { | 743 | 743 | 'root[0][3]': { | @@ -755,7 +755,7 @@ def test_ignore_order_with_sha256_hash(self): | 755 | 755 | def test_ignore_order_cache_for_individual_distances(self): | 756 | 756 | t1 = [[1, 2, 'B', 3], 'B'] | 757 | 757 | 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) | 759 | 759 | expected = { | 760 | 760 | 'values_changed': { | 761 | 761 | 'root[1]': { | @@ -774,16 +774,15 @@ def test_ignore_order_cache_for_individual_distances(self): | 774 | 774 |
| 775 | 775 | stats = diff.get_stats() | 776 | 776 | expected_stats = { | 777 | | - 'PASSES COUNT': 2, | 778 | | - 'DIFF COUNT': 11, | 779 | | - 'LEVEL CACHE HIT COUNT': 1, | | 777 | + 'PASSES COUNT': 3, | | 778 | + 'DIFF COUNT': 13, | 780 | 779 | 'DISTANCE CACHE HIT COUNT': 1, | 781 | 780 | 'MAX PASS LIMIT REACHED': False, | 782 | | - 'MAX DIFF LIMIT REACHED': False, | | 781 | + 'MAX DIFF LIMIT REACHED': False | 783 | 782 | } | 784 | 783 | assert expected_stats == stats | 785 | 784 |
| 786 | 785 | t1 = [[1, 2, 'B', 3], 5] | 787 | 786 | 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) | 789 | 788 | assert expected_stats == diff2.get_stats() |
|