Files
dvc/tests/unit/command/test_run.py
T
Saugat PachhaiandRuslan Kuprieiev 65854c4946 refactor: extract stage's relationship with Dvcfile out from Stage (#3619)
* refactor stage into dvcfile

* Split create_stage out of dvcfile to Stage::create() and overwrite

* Remove logging from Repo::run

* tests: stop using --remove-outs

Co-authored-by: Ruslan Kuprieiev <[email protected]>
2020-04-12 23:09:29 +03:00

115 lines
2.8 KiB
Python

from dvc.cli import parse_args
from dvc.command.run import CmdRun
def test_run(mocker, dvc):
cli_args = parse_args(
[
"run",
"--deps",
"deps",
"--outs",
"outs",
"--outs-no-cache",
"outs-no-cache",
"--metrics",
"metrics",
"--metrics-no-cache",
"metrics-no-cache",
"--file",
"file",
"--wdir",
"wdir",
"--no-exec",
"--yes",
"--overwrite-dvcfile",
"--ignore-build-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"],
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,
ignore_build_cache=True,
no_commit=True,
always_changed=True,
cmd="command",
)
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=[],
outs_persist=[],
outs_persist_no_cache=[],
params=[],
fname=None,
wdir=None,
no_exec=False,
overwrite=False,
ignore_build_cache=False,
no_commit=False,
always_changed=False,
cmd="echo foo",
)
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=[],
outs_persist=[],
outs_persist_no_cache=[],
params=[],
fname=None,
wdir=None,
no_exec=False,
overwrite=False,
ignore_build_cache=False,
no_commit=False,
always_changed=False,
cmd='echo "foo bar"',
)