Files
dvc/tests/unit/command/test_run.py
T
Ruslan Kuprieiev 09136f2378 plots: add plot markers to DVC files (#3807)
* 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
2020-05-20 04:48:53 +03:00

132 lines
3.2 KiB
Python

from dvc.cli import parse_args
from dvc.command.run import CmdRun
def test_run(mocker, dvc):
cli_args = parse_args(
[
"run",
"--name",
"nam",
"--deps",
"deps",
"--outs",
"outs",
"--outs-no-cache",
"outs-no-cache",
"--metrics",
"metrics",
"--metrics-no-cache",
"metrics-no-cache",
"--plots",
"plots",
"--plots-no-cache",
"plots-no-cache",
"--file",
"file",
"--wdir",
"wdir",
"--no-exec",
"--overwrite-dvcfile",
"--no-run-cache",
"--no-commit",
"--outs-persist",
"outs-persist",
"--outs-persist-no-cache",
"outs-persist-no-cache",
"--always-changed",
"--params",
"file:param1,param2",
"--params",
"param3",
"command",
]
)
assert cli_args.func == CmdRun
cmd = cli_args.func(cli_args)
m = mocker.patch.object(cmd.repo, "run", autospec=True)
assert cmd.run() == 0
m.assert_called_once_with(
deps=["deps"],
outs=["outs"],
outs_no_cache=["outs-no-cache"],
metrics=["metrics"],
metrics_no_cache=["metrics-no-cache"],
plots=["plots"],
plots_no_cache=["plots-no-cache"],
outs_persist=["outs-persist"],
outs_persist_no_cache=["outs-persist-no-cache"],
params=["file:param1,param2", "param3"],
fname="file",
wdir="wdir",
no_exec=True,
overwrite=True,
run_cache=False,
no_commit=True,
always_changed=True,
cmd="command",
name="nam",
single_stage=False,
)
def test_run_args_from_cli(mocker, dvc):
args = parse_args(["run", "echo", "foo"])
cmd = args.func(args)
m = mocker.patch.object(cmd.repo, "run", autospec=True)
assert cmd.run() == 0
m.assert_called_once_with(
deps=[],
outs=[],
outs_no_cache=[],
metrics=[],
metrics_no_cache=[],
plots=[],
plots_no_cache=[],
outs_persist=[],
outs_persist_no_cache=[],
params=[],
fname=None,
wdir=None,
no_exec=False,
overwrite=False,
run_cache=True,
no_commit=False,
always_changed=False,
cmd="echo foo",
name=None,
single_stage=False,
)
def test_run_args_with_spaces(mocker, dvc):
args = parse_args(["run", "echo", "foo bar"])
cmd = args.func(args)
m = mocker.patch.object(cmd.repo, "run", autospec=True)
assert cmd.run() == 0
m.assert_called_once_with(
deps=[],
outs=[],
outs_no_cache=[],
metrics=[],
metrics_no_cache=[],
plots=[],
plots_no_cache=[],
outs_persist=[],
outs_persist_no_cache=[],
params=[],
fname=None,
wdir=None,
no_exec=False,
overwrite=False,
run_cache=True,
no_commit=False,
always_changed=False,
cmd='echo "foo bar"',
name=None,
single_stage=False,
)