MCPcopy Create free account
hub / github.com/PowerGridModel/power-grid-model / assert_almost_equal

Function assert_almost_equal

tests/unit/test_serialization.py:491–513  ·  view source on GitHub ↗

Recursively walk through the values and references, assert almost equal. Correctly handle: * Both the sparse and dense data representations * None in the reference type maps to not a value.

(value: np.ndarray, reference: Any)

Source from the content-addressed store, hash-verified

489
490
491def assert_almost_equal(value: np.ndarray, reference: Any):
492 """Recursively walk through the values and references, assert almost equal.
493
494 Correctly handle:
495 * Both the sparse and dense data representations
496 * None in the reference type maps to not a value.
497 """
498 if isinstance(reference, list):
499 assert len(value) == len(reference)
500 for v, r in zip(value, reference):
501 assert_almost_equal(v, r)
502 elif isinstance(reference, dict):
503 assert len(value) == len(reference)
504 assert value.dtype.names is not None
505 for attribute in value.dtype.names:
506 if attribute in reference:
507 assert_almost_equal(value[attribute], reference[attribute])
508 else:
509 assert_not_a_value(reference[attribute])
510 elif reference is None:
511 assert_not_a_value(value)
512 else:
513 np.testing.assert_almost_equal(value, reference)
514
515
516def assert_single_dataset_entries(

Callers 1

Calls 1

assert_not_a_valueFunction · 0.85

Tested by

no test coverage detected