Skip to content

Instantly share code, notes, and snippets.

@danielrichman
Last active December 21, 2015 12:49
Show Gist options
  • Save danielrichman/6308435 to your computer and use it in GitHub Desktop.
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
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