Created
August 28, 2018 22:22
-
-
Save nicwolff/12ce6f2061c4937fd0e3f38f30f825e2 to your computer and use it in GitHub Desktop.
assert_contains: Is every value in nested data structure p at the same path in f?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def assert_contains(full, partial): | |
"""Is every value in nested data structure p at the same path in f?""" | |
assert isinstance(full, type(partial)), '{} != {}'.format(full, partial) | |
if isinstance(partial, dict): | |
for k, v in partial.items(): | |
assert k in full, "No key '{}' in {}".format(k, dict(full)) | |
assert_contains(full[k], v) | |
return True | |
if isinstance(partial, (list, tuple)): | |
for i, partial_item in enumerate(partial): | |
assert_contains(full[i], partial_item) | |
return True | |
assert full == partial, '{} != {}'.format(full, partial) | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment