metrics: accept any viable target in DvcRepo (#4590)

This commit is contained in:
Paweł Redzyński
2020-09-22 22:53:55 +03:00
committed by GitHub
parent ebaffd728e
commit 2b3c30cb0c
3 changed files with 71 additions and 16 deletions
+14
View File
@@ -195,3 +195,17 @@ def test_metrics_diff_cli(tmp_dir, scm, dvc, run_copy_metrics, caplog, capsys):
"Path Metric Old New Change\n"
"m.yaml foo 1.23457 3.45679 2.22222"
)
def test_metrics_diff_non_metrics(tmp_dir, scm, dvc):
def _gen(val):
tmp_dir.scm_gen({"some_file.yaml": f"foo: {val}"}, commit=str(val))
_gen(1)
_gen(2)
_gen(3)
result = dvc.metrics.diff(targets=["some_file.yaml"], a_rev="HEAD~2")
assert result == {
"some_file.yaml": {"foo": {"old": 1, "new": 3, "diff": 2}}
}
+38
View File
@@ -110,3 +110,41 @@ def test_missing_cache(tmp_dir, dvc, run_copy_metrics):
remove(stage.outs[0].cache_path)
assert dvc.metrics.show() == {"": {"metrics.yaml": 1.1}}
def test_show_non_metric(tmp_dir, dvc):
tmp_dir.gen("metrics.yaml", "foo: 1.1")
assert dvc.metrics.show(targets=["metrics.yaml"]) == {
"": {"metrics.yaml": {"foo": 1.1}}
}
def test_show_non_metric_branch(tmp_dir, scm, dvc):
tmp_dir.scm_gen("metrics.yaml", "foo: 1.1", commit="init")
with tmp_dir.branch("branch", new=True):
tmp_dir.scm_gen("metrics.yaml", "foo: 2.2", commit="other")
assert dvc.metrics.show(targets=["metrics.yaml"], revs=["branch"]) == {
"workspace": {"metrics.yaml": {"foo": 1.1}},
"branch": {"metrics.yaml": {"foo": 2.2}},
}
def test_non_metric_and_recurisve_show(tmp_dir, dvc, run_copy_metrics):
tmp_dir.gen(
{"metrics_t.yaml": "foo: 1.1", "metrics": {"metric1.yaml": "bar: 1.2"}}
)
metric2 = os.fspath(tmp_dir / "metrics" / "metric2.yaml")
run_copy_metrics("metrics_t.yaml", metric2, metrics=[metric2])
assert dvc.metrics.show(
targets=["metrics_t.yaml", "metrics"], recursive=True
) == {
"": {
os.path.join("metrics", "metric1.yaml"): {"bar": 1.2},
os.path.join("metrics", "metric2.yaml"): {"foo": 1.1},
"metrics_t.yaml": {"foo": 1.1},
}
}