Skip to content

Instantly share code, notes, and snippets.

@adriansr
Created February 4, 2019 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adriansr/816bcf1b8b4cd3e8c39c99886a0786a1 to your computer and use it in GitHub Desktop.
Save adriansr/816bcf1b8b4cd3e8c39c99886a0786a1 to your computer and use it in GitHub Desktop.
Compare two -expected.json ES events
# 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)
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment