Commit a33bdd2c authored by Wout De Nolf's avatar Wout De Nolf
Browse files

tests: adapt deep_compare to large dictionaries

parent fb59f53e
......@@ -801,34 +801,24 @@ def log_context():
def deep_compare(d, u):
"""using logic of deep update used here to compare two dicts
stack = [(d, u)]
while stack:
d, u = stack.pop(0)
assert len(d) == len(u)
assert set(d.keys()) == set(u.keys())
for k, v in u.items():
assert k in d
if not isinstance(v,
if isinstance(v, numpy.ndarray) and v.size > 1:
if isinstance(v,
stack.append((d[k], v))
elif isinstance(v, numpy.ndarray) and v.size > 1:
assert d[k].shape == v.shape
d[k].dtype == v.dtype
if d[k].dtype != object:
assert all(
numpy.isnan(d[k].flatten()) == numpy.isnan(v.flatten())
assert all(numpy.isnan(d[k].flatten()) == numpy.isnan(v.flatten()))
mask = numpy.logical_not(numpy.isnan(v.flatten()))
assert all((d[k].flatten() == v.flatten())[mask])
assert all(d[k].flatten() == v.flatten())
assert d[k] == v
stack.append((d[k], v))
except AssertionError:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment