-
Notifications
You must be signed in to change notification settings - Fork 1.3k
metrics: show: do not throw on no metric present on branch #1937
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
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 |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| from dvc.repo import Repo as DvcRepo | ||
| from dvc.main import main | ||
| from dvc.exceptions import DvcException, BadMetricError, NoMetricsError | ||
| from dvc.repo.metrics.show import NO_METRICS_FILE_AT_REFERENCE_WARNING | ||
| from dvc.stage import Stage | ||
| from tests.basic_env import TestDvc | ||
|
|
||
|
|
||
|
|
@@ -775,3 +777,50 @@ def _do_show(self, file_name, xpath): | |
| self.assertSequenceEqual(ret[branch][file_name], [branch]) | ||
| else: | ||
| self.assertSequenceEqual(ret[branch][file_name], branch) | ||
|
|
||
|
|
||
| class TestShouldDisplayMetricsEvenIfMetricIsMissing(object): | ||
| BRANCH_MISSING_METRIC = "missing_metric_branch" | ||
| METRIC_FILE = "metric" | ||
| METRIC_FILE_STAGE = METRIC_FILE + Stage.STAGE_FILE_SUFFIX | ||
|
|
||
| def _write_metric(self): | ||
| with open(self.METRIC_FILE, "w+") as fd: | ||
| fd.write("0.5") | ||
| fd.flush() | ||
|
|
||
| def _commit_metric(self, dvc, branch): | ||
| dvc.scm.add([self.METRIC_FILE_STAGE]) | ||
| dvc.scm.commit("{} commit".format(branch)) | ||
|
|
||
| def setUp(self, dvc): | ||
|
||
| dvc.scm.branch(self.BRANCH_MISSING_METRIC) | ||
|
|
||
| self._write_metric() | ||
|
|
||
| ret = main(["run", "-m", self.METRIC_FILE]) | ||
| assert 0 == ret | ||
|
|
||
| self._commit_metric(dvc, "master") | ||
|
|
||
| def test(self, dvc, caplog): | ||
| self.setUp(dvc) | ||
|
|
||
| dvc.scm.checkout(self.BRANCH_MISSING_METRIC) | ||
|
|
||
| self._write_metric() | ||
| ret = main(["run", "-M", self.METRIC_FILE]) | ||
| assert 0 == ret | ||
|
|
||
| self._commit_metric(dvc, self.BRANCH_MISSING_METRIC) | ||
| os.remove(self.METRIC_FILE) | ||
|
|
||
| ret = main(["metrics", "show", "-a"]) | ||
|
|
||
| assert ( | ||
| NO_METRICS_FILE_AT_REFERENCE_WARNING.format( | ||
| self.METRIC_FILE, self.BRANCH_MISSING_METRIC | ||
| ) | ||
| in caplog.text | ||
| ) | ||
| assert 0 == ret | ||
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.
But in this case
Metrics file '{}' does not exist at branch: '{}'doesn't really fit, since path is a cache file for metric file 🙂Uh oh!
There was an error while loading. Please reload this page.
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 exactly, we pass out.relpath to warning message, which is "common part" for both use cases. We always get relative path of our out.
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.
Ah, right. Thanks!