metrics: diff: fix bug with unchanged raw metrics (#3535)

This commit is contained in:
Ruslan Kuprieiev
2020-03-26 03:02:34 +02:00
committed by GitHub
parent 42e3b8aa25
commit 912a98e05e
2 changed files with 38 additions and 1 deletions
+5 -1
View File
@@ -68,7 +68,11 @@ def _diff(old_raw, new_raw):
if isinstance(new, dict) or isinstance(old, dict):
return _diff_dicts(old, new)
return {"": _diff_vals(old, new)}
val_diff = _diff_vals(old, new)
if val_diff:
return {"": val_diff}
return {}
def _get_metrics(repo, *args, rev=None, **kwargs):
+33
View File
@@ -895,6 +895,20 @@ def test_metrics_diff_raw(tmp_dir, scm, dvc):
}
def test_metrics_diff_raw_unchanged(tmp_dir, scm, dvc):
def _gen(val):
tmp_dir.gen({"metrics": val})
dvc.run(cmd="", metrics=["metrics"])
dvc.scm.add(["metrics.dvc"])
dvc.scm.commit(str(val))
_gen("raw 1")
_gen("raw 2")
_gen("raw 1")
assert dvc.metrics.diff(a_rev="HEAD~2") == {}
@pytest.mark.parametrize("xpath", [True, False])
def test_metrics_diff_json(tmp_dir, scm, dvc, xpath):
def _gen(val):
@@ -919,6 +933,25 @@ def test_metrics_diff_json(tmp_dir, scm, dvc, xpath):
assert expected == dvc.metrics.diff(a_rev="HEAD~2")
@pytest.mark.parametrize("xpath", [True, False])
def test_metrics_diff_json_unchanged(tmp_dir, scm, dvc, xpath):
def _gen(val):
metrics = {"a": {"b": {"c": val, "d": 1, "e": str(val)}}}
tmp_dir.gen({"m.json": json.dumps(metrics)})
dvc.run(cmd="", metrics=["m.json"])
dvc.metrics.modify("m.json", typ="json")
if xpath:
dvc.metrics.modify("m.json", xpath="a.b.c")
dvc.scm.add(["m.json.dvc"])
dvc.scm.commit(str(val))
_gen(1)
_gen(2)
_gen(1)
assert dvc.metrics.diff(a_rev="HEAD~2") == {}
def test_metrics_diff_broken_json(tmp_dir, scm, dvc):
metrics = {"a": {"b": {"c": 1, "d": 1, "e": "3"}}}
tmp_dir.gen({"m.json": json.dumps(metrics)})