Whole file
assertpy/assertpy
The author described this change as “fixes #101 - fix dict compare with deep nested ignores”. It counts as a record because the check below fails on the code as it stood at 6474f1eca and passes on 0b43d0621, with nothing else changed between the two runs.
Projectassertpy/assertpy
Fix saved2020-07-10
Sharing licenceBSD-3-Clause · LICENSE
Change size+10 −4
What the code was meant to do, written into the code itself as a save note
fixes #101 - fix dict compare with deep nested ignores
The change
| 167 | 167 | '' if len(missing) == 1 else 's', | |
| 168 | 168 | self._fmt_items(missing))) | |
| 169 | 169 | ||
| 170 | + | # calc val keys given ignores and includes | |
| 170 | 171 | if ignore and include: | |
| 171 | 172 | k1 = set([k for k in val if k not in ignores and k in includes]) | |
| 172 | 173 | elif ignore: | |
| ⋯ | |||
| 174 | 175 | else: # include | |
| 175 | 176 | k1 = set([k for k in val if k in includes]) | |
| 176 | 177 | ||
| 178 | + | # calc other keys given ignores and includes | |
| 177 | 179 | if ignore and include: | |
| 178 | 180 | k2 = set([k for k in other if k not in ignores and k in includes]) | |
| 179 | 181 | elif ignore: | |
| ⋯ | |||
| 182 | 184 | k2 = set([k for k in other if k in includes]) | |
| 183 | 185 | ||
| 184 | 186 | if k1 != k2: | |
| 187 | + | # different set of keys, so not equal | |
| 185 | 188 | return True | |
| 186 | 189 | else: | |
| 187 | 190 | for k in k1: | |
| 188 | - | if self._check_dict_like( | |
| 189 | - | val[k], check_values=False, return_as_bool=True) and self._check_dict_like( | |
| 190 | - | other[k], check_values=False, return_as_bool=True): | |
| 191 | - | return self._dict_not_equal( | |
| 191 | + | if self._check_dict_like(val[k], check_values=False, return_as_bool=True) and \ | |
| 192 | + | self._check_dict_like(other[k], check_values=False, return_as_bool=True): | |
| 193 | + | subdicts_not_equal = self._dict_not_equal( | |
| 192 | 194 | val[k], | |
| 193 | 195 | other[k], | |
| 194 | 196 | ignore=[i[1:] for i in ignores if type(i) is tuple and i[0] == k] if ignore else None, | |
| 195 | 197 | include=[i[1:] for i in self._dict_ignore(include) if type(i) is tuple and i[0] == k] if include else None) | |
| 198 | + | if subdicts_not_equal: | |
| 199 | + | # fast fail inside the loop since sub-dicts are not equal | |
| 200 | + | return True | |
| 196 | 201 | elif val[k] != other[k]: | |
| 202 | + | # fast fail inside the loop since values are not equal | |
| 197 | 203 | return True | |
| 198 | 204 | return False | |
| 199 | 205 | else: | |
The check that tells the two apart
fail→pass·tests/test_dict_compare.py::test_failure_deep_mismatch_when_ignoring_double_nested_sibling_key
Check file tests/test_dict_compare.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it6474f1eca944999afec002bfa9836dafa9b19777
Broken version dated2020-07-10
Moduleassertpy.helpers
Units changedHelpersMixin
Fingerprintc6e819fd25c553df
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.