plots: fix plots path when calling from different dir (#4843)

This commit is contained in:
Paweł Redzyński
2020-11-05 08:11:24 +01:00
committed by GitHub
parent 4b17685351
commit edd8344659
2 changed files with 20 additions and 3 deletions
+2 -3
View File
@@ -65,12 +65,11 @@ class CmdPlots(CmdBase):
html = PAGE_HTML.format(divs="\n".join(divs))
path = self.args.out or "plots.html"
path = os.path.join(os.getcwd(), path)
with open(path, "w") as fobj:
fobj.write(html)
logger.info(
"file://{}".format(os.path.join(self.repo.root_dir, path))
)
logger.info(f"file://{path}")
except DvcException:
logger.exception("")
+18
View File
@@ -6,6 +6,7 @@ from collections import OrderedDict
import pytest
from dvc.main import main
from dvc.repo import Repo
from dvc.repo.plots.data import (
JSONPlotData,
@@ -693,3 +694,20 @@ def test_show_no_repo(tmp_dir):
dvc = Repo(uninitialized=True)
dvc.plots.show(["metric.json"])
def test_show_from_subdir(tmp_dir, dvc, caplog):
subdir = tmp_dir / "subdir"
subdir.mkdir()
metric = [
{"first_val": 100, "val": 2},
{"first_val": 200, "val": 3},
]
_write_json(subdir, metric, "metric.json")
with subdir.chdir(), caplog.at_level(logging.INFO, "dvc"):
assert main(["plots", "show", "metric.json"]) == 0
assert f"file://{str(subdir)}" in caplog.text
assert (subdir / "plots.html").exists()