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(): ...@@ -801,34 +801,24 @@ def log_context():
def deep_compare(d, u): def deep_compare(d, u):
"""using logic of deep update used here to compare two dicts """using logic of deep update used here to compare two dicts
""" """
try: stack = [(d, u)]
stack = [(d, u)] while stack:
while stack: d, u = stack.pop(0)
d, u = stack.pop(0) assert set(d.keys()) == set(u.keys())
assert len(d) == len(u) for k, v in u.items():
if isinstance(v, collections.abc.Mapping):
for k, v in u.items(): stack.append((d[k], v))
assert k in d elif isinstance(v, numpy.ndarray) and v.size > 1:
if not isinstance(v, collections.abc.Mapping): assert d[k].shape == v.shape
if isinstance(v, numpy.ndarray) and v.size > 1: d[k].dtype == v.dtype
assert d[k].shape == v.shape if d[k].dtype != object:
d[k].dtype == v.dtype assert all(numpy.isnan(d[k].flatten()) == numpy.isnan(v.flatten()))
if d[k].dtype != object: mask = numpy.logical_not(numpy.isnan(v.flatten()))
assert all( assert all((d[k].flatten() == v.flatten())[mask])
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])
else:
assert all(d[k].flatten() == v.flatten())
else:
assert d[k] == v
else: else:
stack.append((d[k], v)) assert all(d[k].flatten() == v.flatten())
except AssertionError: else:
pprint(d) assert d[k] == v
pprint(u)
raise
@pytest.fixture @pytest.fixture
......
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