metrics show: allow falsey values (#4642)

* metrics show: allow falsey values

Fixes #4630

* metrics show: bug in logging to console. Fixes #4630

* repro: fix incorrect usage of _show_metrics

* fix formatting/styling

* metrics: add a simple func test

Co-authored-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Raymond Gasper
2020-09-30 04:53:06 +03:00
committed by GitHub
co-authored by Ruslan Kuprieiev
parent fb756c0538
commit b0dbcdcdb6
5 changed files with 43 additions and 11 deletions
+7
View File
@@ -160,3 +160,10 @@ def test_non_metric_and_recurisve_show(tmp_dir, dvc, run_copy_metrics):
"metrics_t.yaml": {"foo": 1.1},
}
}
def test_show_falsey(tmp_dir, dvc):
tmp_dir.gen("metrics.json", '{"foo": 0, "bar": 0.0, "baz": {}}')
assert dvc.metrics.show(targets=["metrics.json"]) == {
"": {"metrics.json": {"foo": 0, "bar": 0.0}}
}
+20 -1
View File
@@ -1,7 +1,12 @@
import textwrap
from dvc.cli import parse_args
from dvc.command.metrics import CmdMetricsDiff, CmdMetricsShow, _show_diff
from dvc.command.metrics import (
CmdMetricsDiff,
CmdMetricsShow,
_show_diff,
_show_metrics,
)
def test_metrics_diff(dvc, mocker):
@@ -233,3 +238,17 @@ def test_metrics_diff_with_old():
metrics.yaml a.d.e 3 4 1
metrics.yaml x.b 5 6 1"""
)
def test_metrics_show_with_valid_falsey_values():
assert _show_metrics(
{"branch_1": {"metrics.json": {"a": 0, "b": {"ad": 0.0, "bc": 0.0}}}},
all_branches=True,
) == textwrap.dedent(
"""\
branch_1:
\tmetrics.json:
\t\ta: 0
\t\tb.ad: 0.0
\t\tb.bc: 0.0"""
)