Created
February 4, 2019 17:29
-
-
Save adriansr/816bcf1b8b4cd3e8c39c99886a0786a1 to your computer and use it in GitHub Desktop.
Compare two -expected.json ES events
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
# Usage: | |
# compare-golden-events.py <old.json> <new.json> | |
import json | |
import sys | |
def missing(keys, dct): | |
r = [] | |
for key in keys: | |
if key not in dct: | |
r.append(key) | |
return r | |
def changed(a, b): | |
c = [] | |
for key in a.keys(): | |
if key in b and b[key] != a[key]: | |
c.append("{0} [`{1}` -> `{2}`]".format(key, a[key], b[key])) | |
return c | |
def kprint(prefix, keys): | |
for k in keys: | |
print prefix, k | |
oldf = open(sys.argv[1], 'rb') | |
newf = open(sys.argv[2], 'rb') | |
old = json.load(oldf) | |
new = json.load(newf) | |
assert len(old) == len(new), "Size differs" | |
for i in range(len(old)): | |
oldK = old[i].keys() | |
newK = new[i].keys() | |
removed = missing(oldK, new[i]) | |
added = missing(newK, old[i]) | |
chg = changed(old[i], new[i]) | |
print 'event', i | |
kprint('-', removed) | |
kprint('+', added) | |
kprint('(change)', chg) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment