From bea7d56bd596b6bc09ea9114746fbebeb112352c Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Wed, 27 Apr 2022 11:14:13 +0200 Subject: [PATCH] `plots`: Fix repo with removed plots Changes in dvc-render 0.0.5 caused error. --- dvc/render/convert.py | 18 ++++++++++-------- setup.cfg | 2 +- tests/integration/plots/test_json.py | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/dvc/render/convert.py b/dvc/render/convert.py index e98c5a68f..99e02c135 100644 --- a/dvc/render/convert.py +++ b/dvc/render/convert.py @@ -52,14 +52,16 @@ def to_json(renderer, split: bool = False) -> List[Dict]: content = renderer.get_filled_template(skip_anchors=["data"]) else: content = renderer.get_filled_template() - return [ - { - TYPE_KEY: renderer.TYPE, - REVISIONS_KEY: sorted(grouped.keys()), - "content": json.loads(content), - "datapoints": grouped, - } - ] + if grouped: + return [ + { + TYPE_KEY: renderer.TYPE, + REVISIONS_KEY: sorted(grouped.keys()), + "content": json.loads(content), + "datapoints": grouped, + } + ] + return [] if renderer.TYPE == "image": return [ { diff --git a/setup.cfg b/setup.cfg index 63f5d812c..c026504c9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -73,7 +73,7 @@ install_requires = diskcache>=5.2.1 jaraco.windows>=5.7.0; python_version < '3.8' and sys_platform == 'win32' scmrepo==0.0.18 - dvc-render==0.0.4 + dvc-render==0.0.5 dvclive>=0.7.2 [options.extras_require] diff --git a/tests/integration/plots/test_json.py b/tests/integration/plots/test_json.py index f3bbb8cd4..854c9f944 100644 --- a/tests/integration/plots/test_json.py +++ b/tests/integration/plots/test_json.py @@ -235,12 +235,22 @@ def test_repo_with_plots( split_json_result, ) verify_vega_props("confusion.json", json_result, **confusion_props) + + +@pytest.mark.vscode +def test_repo_with_removed_plots(tmp_dir, capsys, repo_with_plots): from dvc.utils.fs import remove + next(repo_with_plots()) + # even if there is no data, call should be successful remove(tmp_dir / ".dvc" / "cache") remove("linear.json") remove("confusion.json") remove("image.png") - call(capsys) - call(capsys, subcommand="diff") + + for s in {"show", "diff"}: + _, json_result, split_json_result = call(capsys, subcommand=s) + for p in {"linear.json", "confusion.json", "image.png"}: + assert json_result[p] == [] + assert split_json_result[p] == []