Skip to content
Snippets Groups Projects
Commit d445ed02 authored by Pierre-Yves David's avatar Pierre-Yves David :octopus:
Browse files

add a `full` variant for diff-result

That variant display difference for all items in the result
parent 163aba8e
No related branches found
No related tags found
No related merge requests found
Pipeline #55368 passed
......@@ -2,6 +2,7 @@
#
# Small tool to manipulaote
import argparse
import collections
import os
import sys
......@@ -13,7 +14,7 @@
err = poulpe.err
def compare(old_path, new_path):
def compare(old_path, new_path, full=False):
old = poulpe.get_data(old_path)
if old is None:
err(f'old file not found: {old_path}')
......@@ -23,6 +24,15 @@
err(f'new file not found: {new_path}')
return 1
if full:
full_compare(old, new)
else:
simple_compare(old, new)
return 0
def simple_compare(old, new):
old_median = old['result']['time']['median']
new_median = new['result']['time']['median']
......@@ -34,6 +44,46 @@
return 0
def _linear_data(data, prefix=""):
"""call to display data"""
if not isinstance(data, dict):
yield (prefix, data)
return
for k, v in sorted(data.items()):
if prefix:
p = f"{prefix}.{k}"
else:
p = k
if isinstance(v, dict):
yield from _linear_data(v, p)
elif isinstance(v, list):
for idx, i in enumerate(v):
yield from _linear_data(i, f"{p}.{idx}")
else:
yield from _linear_data(v, p)
def full_compare(old, new):
all_values = collections.defaultdict(lambda: [None, None])
for k, v in _linear_data(old):
all_values[k][0] = v
for k, v in _linear_data(new):
all_values[k][1] = v
for k, v in sorted(all_values.items()):
if v[0] != v[1]:
if v[0] is None:
o = "ø"
else:
o = v[0]
if v[1] is None:
n = "ø"
else:
n = v[1]
print(f"{k}: {o} -> {n}")
return 0
def _parsers():
cmd_parser = argparse.ArgumentParser(prog='poulpe-bin-env-util')
......@@ -45,9 +95,11 @@
'NEW_RESULT',
help="the path to the data environment directory",
)
cmd_parser.add_argument('--full', action='store_const', const=True)
return cmd_parser
def main(args):
parser = _parsers()
param = parser.parse_args(args)
......@@ -48,10 +100,10 @@
return cmd_parser
def main(args):
parser = _parsers()
param = parser.parse_args(args)
ret = compare(param.OLD_RESULT, param.NEW_RESULT)
ret = compare(param.OLD_RESULT, param.NEW_RESULT, full=param.full)
return ret
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment