mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
* run: add --plot/--plot-no-cache Part of #3409 * plot: move show/diff to API * plots: show marked plots by default Involves some refactoring to make plots comply with the rest of the code base. * dvc.yaml: use top-level metrics and plots * dvc.yaml: add support for plot template * plots: add support for templates in dvc.yaml * dvc.yaml: allow metrics/plots to have persist/cache * plots: render single page by-default and introduce --show-json * plot: use "working tree" instead of "workspace" Just to sync this with the rest of the codebase. We should consider renaming it to "workspace" everywhere, but for now I opt to not touch it to not break something that depends on it. * plots: rename -f|--file to -o|--out Better corresponds to other commands like `import`. * plots: use RepoTree and brancher instead of api * stage: get rid of OutputParams * tests: plots: add simple diff test * plots: use `--targets` instead of `--datafile` Makes it comply with `dvc metrics/params` CLI options. * tests: unit: plots: add --show-json test * stage: cleanup exception for format error Based on feedback from the users. * lockfile: use relpath in corruption error
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
import json
|
|
|
|
from .test_plots import PlotData, _run_with, _write_json
|
|
|
|
|
|
def test_diff_dirty(tmp_dir, scm, dvc):
|
|
metric_1 = [{"y": 2}, {"y": 3}]
|
|
_write_json(tmp_dir, metric_1, "metric.json")
|
|
_run_with(tmp_dir, plots_no_cache=["metric.json"], commit="init")
|
|
|
|
metric_2 = [{"y": 3}, {"y": 5}]
|
|
_write_json(tmp_dir, metric_2, "metric.json")
|
|
_run_with(tmp_dir, plots_no_cache=["metric.json"], commit="second")
|
|
|
|
metric_3 = [{"y": 5}, {"y": 6}]
|
|
_write_json(tmp_dir, metric_3, "metric.json")
|
|
_run_with(tmp_dir, plots_no_cache=["metric.json"])
|
|
|
|
plot_string = dvc.plots.diff(fields={"y"})["metric.json"]
|
|
|
|
plot_content = json.loads(plot_string)
|
|
assert plot_content["data"]["values"] == [
|
|
{"y": 5, PlotData.INDEX_FIELD: 0, "rev": "working tree"},
|
|
{"y": 6, PlotData.INDEX_FIELD: 1, "rev": "working tree"},
|
|
{"y": 3, PlotData.INDEX_FIELD: 0, "rev": "HEAD"},
|
|
{"y": 5, PlotData.INDEX_FIELD: 1, "rev": "HEAD"},
|
|
]
|
|
assert plot_content["encoding"]["x"]["field"] == PlotData.INDEX_FIELD
|
|
assert plot_content["encoding"]["y"]["field"] == "y"
|