-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plots/metrics: fix some communication disrepancies #4837
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,9 @@ | |
import pytest | ||
|
||
from dvc.repo import Repo | ||
from dvc.repo.metrics.show import NoMetricsError | ||
from dvc.utils.fs import remove | ||
|
||
|
||
def test_show_empty(dvc): | ||
with pytest.raises(NoMetricsError): | ||
dvc.metrics.show() | ||
|
||
|
||
Comment on lines
-10
to
-14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
||
def test_show_simple(tmp_dir, dvc, run_copy_metrics): | ||
tmp_dir.gen("metrics_t.yaml", "1.1") | ||
run_copy_metrics( | ||
|
@@ -36,15 +30,6 @@ def test_show_multiple(tmp_dir, dvc, run_copy_metrics): | |
assert dvc.metrics.show() == {"": {"foo": {"foo": 1}, "baz": {"baz": 2}}} | ||
|
||
|
||
def test_show_invalid_metric(tmp_dir, dvc, run_copy_metrics): | ||
tmp_dir.gen("metrics_temp.yaml", "foo:\n- bar\n- baz\nxyz: string") | ||
run_copy_metrics( | ||
"metrics_temp.yaml", "metrics.yaml", metrics=["metrics.yaml"] | ||
) | ||
with pytest.raises(NoMetricsError): | ||
dvc.metrics.show() | ||
Comment on lines
-39
to
-45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
||
|
||
|
||
def test_show_branch(tmp_dir, scm, dvc, run_copy_metrics): | ||
tmp_dir.gen("metrics_temp.yaml", "foo: 1") | ||
run_copy_metrics( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,13 +398,6 @@ def _replace(path, src, dst): | |
path.write_text(path.read_text().replace(src, dst)) | ||
|
||
|
||
def test_no_plots(tmp_dir, dvc): | ||
from dvc.exceptions import NoPlotsError | ||
|
||
with pytest.raises(NoPlotsError): | ||
dvc.plots.show() | ||
Comment on lines
-401
to
-405
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to test_common.py::test_show_no_metrics_files |
||
|
||
|
||
def test_should_raise_on_no_template(tmp_dir, dvc, run_copy_metrics): | ||
metric = [{"val": 2}, {"val": 3}] | ||
_write_json(tmp_dir, metric, "metric_t.json") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,57 @@ | |
|
||
import pytest | ||
|
||
from dvc.main import main | ||
from tests.func.metrics.utils import _write_json | ||
|
||
|
||
def metrics_diff(dvc, filename, revision): | ||
dvc.metrics.diff(targets=[filename], a_rev=revision) | ||
|
||
|
||
def plots_diff(dvc, filename, revision): | ||
dvc.plots.diff(targets=[filename], revs=[revision]) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"diff_fun, metric_value", | ||
((metrics_diff, {"m": 1}), (plots_diff, [{"m": 1}, {"m": 2}])), | ||
"command, metric_value", | ||
(("metrics", {"m": 1}), ("plots", [{"m": 1}, {"m": 2}])), | ||
) | ||
def test_diff_no_file_on_target_rev( | ||
tmp_dir, scm, dvc, caplog, diff_fun, metric_value | ||
tmp_dir, scm, dvc, caplog, command, metric_value | ||
): | ||
with tmp_dir.branch("new_branch", new=True): | ||
_write_json(tmp_dir, metric_value, "metric.json") | ||
|
||
with caplog.at_level(logging.WARNING, "dvc"): | ||
diff_fun(dvc, "metric.json", "master") | ||
assert ( | ||
main([command, "diff", "master", "--targets", "metric.json"]) | ||
== 0 | ||
) | ||
|
||
assert "'metric.json' was not found at: 'master'." in caplog.text | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command, malformed_metric", | ||
(("metrics", '{"m": 1'), ("plots", '[{"m": 1}, {"m": 2}'),), | ||
) | ||
def test_show_malformed_metric( | ||
tmp_dir, scm, dvc, caplog, command, malformed_metric | ||
): | ||
tmp_dir.gen("metric.json", malformed_metric) | ||
|
||
with caplog.at_level(logging.ERROR, "dvc"): | ||
assert main([command, "show", "metric.json"]) == 1 | ||
|
||
assert ( | ||
f"Could not parse {command} files. " | ||
"Use `-v` option to see more details." | ||
) in caplog.text | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command, run_options", | ||
(("metrics", "-m/-M"), ("plots", "--plots/--plots-no-cache"),), | ||
) | ||
def test_show_no_metrics_files(tmp_dir, dvc, caplog, command, run_options): | ||
with caplog.at_level(logging.ERROR, "dvc"): | ||
assert main([command, "show"]) == 1 | ||
|
||
assert ( | ||
f"No {command} files in this repository. " | ||
f"Use `{run_options}` options for " | ||
f"`dvc run` to mark stage outputs as {command}." | ||
) in caplog.text | ||
Comment on lines
+54
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is really an exception that you are testing, it would be better to test it without going through CLI, as we did before. Just a bit cleaner. Same with tests above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for a post-merge review, but we are going away from these obvious messages and deleting them everywhere. Are you sure we need it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessarily, I added it only to make it consistent with
metrics
- I guess we could remove it in both places. How about that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pared Yeah, better to remove in both cases.