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.

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

167167 '' if len(missing) == 1 else 's',
168168 self._fmt_items(missing)))
169169
170+ # calc val keys given ignores and includes
170171 if ignore and include:
171172 k1 = set([k for k in val if k not in ignores and k in includes])
172173 elif ignore:
174175 else: # include
175176 k1 = set([k for k in val if k in includes])
176177
178+ # calc other keys given ignores and includes
177179 if ignore and include:
178180 k2 = set([k for k in other if k not in ignores and k in includes])
179181 elif ignore:
182184 k2 = set([k for k in other if k in includes])
183185
184186 if k1 != k2:
187+ # different set of keys, so not equal
185188 return True
186189 else:
187190 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(
192194 val[k],
193195 other[k],
194196 ignore=[i[1:] for i in ignores if type(i) is tuple and i[0] == k] if ignore else None,
195197 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
196201 elif val[k] != other[k]:
202+ # fast fail inside the loop since values are not equal
197203 return True
198204 return False
199205 else:

The check that tells the two apart

failpass·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.

Other bugs found in assertpy/assertpy