Skip to content

Commit

Permalink
plots: tests: integration test for vscode
Browse files Browse the repository at this point in the history
Closes: #7549
  • Loading branch information
pared authored and daavoo committed Apr 26, 2022
1 parent f84f9cf commit 700b648
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 45 deletions.
10 changes: 7 additions & 3 deletions dvc/commands/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ def run(self):
"visualization file will not be created."
)

out: str = self.args.out or "dvc_plots"

renderers_out = (
out if self.args.json else os.path.join(out, "static")
)
renderers = match_renderers(
plots_data=plots_data, out=self.args.out
plots_data=plots_data, out=renderers_out
)

if self.args.show_vega:
Expand All @@ -95,8 +100,7 @@ def run(self):
self.repo.dvc_dir, html_template_path
)

rel: str = self.args.out or "dvc_plots"
output_file: Path = (Path.cwd() / rel).resolve() / "index.html"
output_file: Path = (Path.cwd() / out).resolve() / "index.html"

render_html(
renderers=renderers,
Expand Down
7 changes: 5 additions & 2 deletions dvc/render/convert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
from collections import defaultdict
from typing import Dict, List, Union

Expand Down Expand Up @@ -42,8 +43,10 @@ def _group_by_rev(datapoints):


def to_json(renderer, split: bool = False) -> List[Dict]:
from copy import deepcopy

if renderer.TYPE == "vega":
grouped = _group_by_rev(renderer.datapoints)
grouped = _group_by_rev(deepcopy(renderer.datapoints))
if split:
content = renderer.get_filled_template(skip_anchors=["data"])
else:
Expand All @@ -61,7 +64,7 @@ def to_json(renderer, split: bool = False) -> List[Dict]:
{
TYPE_KEY: renderer.TYPE,
REVISIONS_KEY: [datapoint.get(REVISION_FIELD)],
"url": datapoint.get(SRC_FIELD),
"url": os.path.abspath(datapoint.get(SRC_FIELD)),
}
for datapoint in renderer.datapoints
]
Expand Down
4 changes: 1 addition & 3 deletions dvc/render/image_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def convert(
if path:
if not os.path.isdir(path):
os.makedirs(path, exist_ok=True)
src = self._write_image(
os.path.abspath(path), revision, filename, data
)
src = self._write_image(path, revision, filename, data)
else:
src = self._encode_image(data)
datapoint = {
Expand Down
35 changes: 35 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,38 @@ def isolate(tmp_path_factory, monkeypatch) -> None:
import pygit2

pygit2.settings.search_path[pygit2.GIT_CONFIG_LEVEL_GLOBAL] = str(home_dir)


@pytest.fixture
def run_copy_metrics(tmp_dir, run_copy):
def run(
file1,
file2,
commit=None,
tag=None,
single_stage=True,
name=None,
**kwargs,
):
if name:
single_stage = False

stage = tmp_dir.dvc.run(
cmd=f"python copy.py {file1} {file2}",
deps=[file1],
single_stage=single_stage,
name=name,
**kwargs,
)

if hasattr(tmp_dir.dvc, "scm"):
files = [stage.path]
files += [out.fs_path for out in stage.outs if not out.use_cache]
tmp_dir.dvc.scm.add(files)
if commit:
tmp_dir.dvc.scm.commit(commit)
if tag:
tmp_dir.dvc.scm.tag(tag)
return stage

return run
36 changes: 0 additions & 36 deletions tests/func/conftest.py

This file was deleted.

Loading

0 comments on commit 700b648

Please sign in to comment.