Last active
December 21, 2015 12:49
-
-
Save danielrichman/6308435 to your computer and use it in GitHub Desktop.
For when an assertion comparing two massive dicts fails in a python unit test
This file contains 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
import sys | |
import datetime | |
# expect either a single line >> assert {.... dicta ....} == {.... dictb ....} | |
# (as produced from nosetests -d assertion failures) | |
# or two dicts, on two separate lines. | |
# obviously the former breaks if == appears in a key or value... | |
line = sys.stdin.readline() | |
line, split, values = line.partition(">> assert") | |
if len(split): | |
a, b = values.split("==") | |
else: | |
a, b = line, sys.stdin.readline() | |
a = eval(a) | |
b = eval(b) | |
class Undefined(object): | |
def __str__(self): | |
return "<undefined>" | |
for key in set(a) | set(b): | |
ag = a.get(key, Undefined()) | |
bg = b.get(key, Undefined()) | |
if ag != bg: | |
print key, ag, bg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment