|
| 1 | +import pytest |
| 2 | +from deepdiff import DeepDiff |
| 3 | + |
| 4 | +@pytest.mark.parametrize( |
| 5 | + "data, result", |
| 6 | + [ |
| 7 | + ( |
| 8 | + { |
| 9 | + "old": { |
| 10 | + 'name': 'Testname Old', |
| 11 | + 'desciption': 'Desc Old', |
| 12 | + 'sub_path': { |
| 13 | + 'name': 'Testname Subpath old', |
| 14 | + 'desciption': 'Desc Subpath old', |
| 15 | + }, |
| 16 | + }, |
| 17 | + "new": { |
| 18 | + 'name': 'Testname New', |
| 19 | + 'desciption': 'Desc New', |
| 20 | + 'new_attribute': 'New Value', |
| 21 | + 'sub_path': { |
| 22 | + 'name': 'Testname Subpath old', |
| 23 | + 'desciption': 'Desc Subpath old', |
| 24 | + }, |
| 25 | + }, |
| 26 | + "include_paths": "root['sub_path']", |
| 27 | + }, |
| 28 | + {} |
| 29 | + ), |
| 30 | + ( |
| 31 | + { |
| 32 | + "old": { |
| 33 | + 'name': 'Testname Old', |
| 34 | + 'desciption': 'Desc Old', |
| 35 | + 'sub_path': { |
| 36 | + 'name': 'Testname Subpath old', |
| 37 | + 'desciption': 'Desc Subpath old', |
| 38 | + }, |
| 39 | + }, |
| 40 | + "new": { |
| 41 | + 'name': 'Testname New', |
| 42 | + 'desciption': 'Desc New', |
| 43 | + 'new_attribute': 'New Value', |
| 44 | + 'sub_path': { |
| 45 | + 'name': 'Testname Subpath New', |
| 46 | + 'desciption': 'Desc Subpath old', |
| 47 | + }, |
| 48 | + }, |
| 49 | + "include_paths": "root['sub_path']", |
| 50 | + }, |
| 51 | + {"values_changed": {"root['sub_path']['name']": {"old_value": "Testname Subpath old", "new_value": "Testname Subpath New"}}} |
| 52 | + ), |
| 53 | + ( |
| 54 | + { |
| 55 | + "old": { |
| 56 | + 'name': 'Testname Old', |
| 57 | + 'desciption': 'Desc Old', |
| 58 | + 'sub_path': { |
| 59 | + 'name': 'Testname Subpath old', |
| 60 | + 'desciption': 'Desc Subpath old', |
| 61 | + 'old_attr': 'old attr value', |
| 62 | + }, |
| 63 | + }, |
| 64 | + "new": { |
| 65 | + 'name': 'Testname New', |
| 66 | + 'desciption': 'Desc New', |
| 67 | + 'new_attribute': 'New Value', |
| 68 | + 'sub_path': { |
| 69 | + 'name': 'Testname Subpath old', |
| 70 | + 'desciption': 'Desc Subpath New', |
| 71 | + 'new_sub_path_attr': 'new sub path attr value', |
| 72 | + }, |
| 73 | + }, |
| 74 | + "include_paths": "root['sub_path']['name']", |
| 75 | + }, |
| 76 | + {} |
| 77 | + ), |
| 78 | + ( |
| 79 | + { |
| 80 | + "old": { |
| 81 | + 'name': 'Testname old', |
| 82 | + 'desciption': 'Desc old', |
| 83 | + 'new_attribute': 'old Value', |
| 84 | + 'sub_path': { |
| 85 | + 'name': 'Testname', |
| 86 | + 'removed_attr': 'revemod attr value', |
| 87 | + }, |
| 88 | + }, |
| 89 | + "new": { |
| 90 | + 'name': 'Testname new', |
| 91 | + 'desciption': 'Desc new', |
| 92 | + 'new_attribute': 'new Value', |
| 93 | + 'sub_path': { |
| 94 | + 'added_attr': 'Added Attr Value', |
| 95 | + 'name': 'Testname', |
| 96 | + }, |
| 97 | + }, |
| 98 | + "include_paths": "root['sub_path']['name']", |
| 99 | + }, |
| 100 | + {} |
| 101 | + ), |
| 102 | + ( |
| 103 | + { |
| 104 | + "old": { |
| 105 | + 'name': 'Testname', |
| 106 | + 'removed_attr': 'revemod attr value', |
| 107 | + }, |
| 108 | + "new": { |
| 109 | + 'added_attr': 'Added Attr Value', |
| 110 | + 'name': 'Testname', |
| 111 | + }, |
| 112 | + "include_paths": "root['name']", |
| 113 | + }, |
| 114 | + {} |
| 115 | + ), |
| 116 | + ( |
| 117 | + { |
| 118 | + "old": { |
| 119 | + 'name': 'Testname', |
| 120 | + 'removed_attr': 'revemod attr value', |
| 121 | + 'removed_attr_2': 'revemod attr value', |
| 122 | + }, |
| 123 | + "new": { |
| 124 | + 'added_attr': 'Added Attr Value', |
| 125 | + 'name': 'Testname', |
| 126 | + }, |
| 127 | + "include_paths": "root['name']", |
| 128 | + }, |
| 129 | + {} |
| 130 | + ), |
| 131 | + ( |
| 132 | + { |
| 133 | + "old": { |
| 134 | + 'name': 'Testname old', |
| 135 | + 'desciption': 'Desc old', |
| 136 | + 'new_attribute': 'old Value', |
| 137 | + 'sub_path': { |
| 138 | + 'name': 'Testname', |
| 139 | + 'removed_attr': 'revemod attr value', |
| 140 | + 'removed_attr_2': 'blu', |
| 141 | + }, |
| 142 | + }, |
| 143 | + "new": { |
| 144 | + 'name': 'Testname new', |
| 145 | + 'desciption': 'Desc new', |
| 146 | + 'new_attribute': 'new Value', |
| 147 | + 'sub_path': { |
| 148 | + 'added_attr': 'Added Attr Value', |
| 149 | + 'name': 'Testname', |
| 150 | + }, |
| 151 | + }, |
| 152 | + "include_paths": "root['sub_path']['name']", |
| 153 | + }, |
| 154 | + {} |
| 155 | + ), |
| 156 | + ] |
| 157 | +) |
| 158 | +def test_diff_include_paths_root(data, result): |
| 159 | + diff = DeepDiff(data["old"], data["new"], include_paths=data["include_paths"]) |
| 160 | + assert diff == result |
0 commit comments