mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 15:28:27 +01:00
* experiments: refactor regular/checkpoint experiment separation * fix scm_checkout pull bug * experiments: return stages from executor.reproduce * since executor has to move to threadpool execution anyways, we no longer have to work around the pickle repro result limitation * refactor new/resume behavior * refactor checkpoints tests * use -f to force checkpoints reset/restart * checkpoints: use 'exp run' and 'exp res[ume]' commands * stage: all outs can be missing for checkpoint stages * regular outputs may not be written at the time a checkpoint is generated, but subsequent checkouts of that stage should not fail due to the missing outs * commit stage on checkpoint generation otherwise non-persist cached outs are lost * checkpoints: wait for stage proc to end after killing via terminate() * stage: fix issues with killing checkpoint stage * refactor signaling (use threading.Event instead of Condition) * fix windows bug (kill all child processes via taskkill) * experiments: refactor executor collection * tests: move checkpoint tests into separate module * refactor experiment tests to use stage fixture
126 lines
2.9 KiB
Python
126 lines
2.9 KiB
Python
import pytest
|
|
|
|
from dvc.cli import parse_args
|
|
from dvc.command.experiments import (
|
|
CmdExperimentsDiff,
|
|
CmdExperimentsGC,
|
|
CmdExperimentsRun,
|
|
CmdExperimentsShow,
|
|
)
|
|
from dvc.dvcfile import PIPELINE_FILE
|
|
from dvc.exceptions import InvalidArgumentError
|
|
|
|
from .test_repro import default_arguments as repro_arguments
|
|
|
|
|
|
def test_experiments_diff(dvc, mocker):
|
|
cli_args = parse_args(
|
|
[
|
|
"experiments",
|
|
"diff",
|
|
"HEAD~10",
|
|
"HEAD~1",
|
|
"--all",
|
|
"--show-json",
|
|
"--show-md",
|
|
"--old",
|
|
"--precision",
|
|
"10",
|
|
]
|
|
)
|
|
assert cli_args.func == CmdExperimentsDiff
|
|
|
|
cmd = cli_args.func(cli_args)
|
|
m = mocker.patch("dvc.repo.experiments.diff.diff", return_value={})
|
|
|
|
assert cmd.run() == 0
|
|
|
|
m.assert_called_once_with(
|
|
cmd.repo, a_rev="HEAD~10", b_rev="HEAD~1", all=True
|
|
)
|
|
|
|
|
|
def test_experiments_show(dvc, mocker):
|
|
cli_args = parse_args(
|
|
[
|
|
"experiments",
|
|
"show",
|
|
"--all-tags",
|
|
"--all-branches",
|
|
"--all-commits",
|
|
"--sha",
|
|
]
|
|
)
|
|
assert cli_args.func == CmdExperimentsShow
|
|
|
|
cmd = cli_args.func(cli_args)
|
|
m = mocker.patch("dvc.repo.experiments.show.show", return_value={})
|
|
|
|
assert cmd.run() == 0
|
|
|
|
m.assert_called_once_with(
|
|
cmd.repo,
|
|
all_tags=True,
|
|
all_branches=True,
|
|
all_commits=True,
|
|
sha_only=True,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"args, resume", [(["exp", "run"], None), (["exp", "resume"], ":last")]
|
|
)
|
|
def test_experiments_run(dvc, mocker, args, resume):
|
|
default_arguments = {
|
|
"params": [],
|
|
"queue": False,
|
|
"run_all": False,
|
|
"jobs": None,
|
|
"checkpoint_resume": resume,
|
|
}
|
|
|
|
default_arguments.update(repro_arguments)
|
|
|
|
cmd = CmdExperimentsRun(parse_args(args))
|
|
mocker.patch.object(cmd.repo, "reproduce")
|
|
mocker.patch.object(cmd.repo.experiments, "run")
|
|
cmd.run()
|
|
cmd.repo.experiments.run.assert_called_with(
|
|
PIPELINE_FILE, **default_arguments
|
|
)
|
|
|
|
|
|
def test_experiments_gc(dvc, mocker):
|
|
cli_args = parse_args(
|
|
[
|
|
"exp",
|
|
"gc",
|
|
"--workspace",
|
|
"--all-tags",
|
|
"--all-branches",
|
|
"--all-commits",
|
|
"--queued",
|
|
"--force",
|
|
]
|
|
)
|
|
assert cli_args.func == CmdExperimentsGC
|
|
|
|
cmd = cli_args.func(cli_args)
|
|
m = mocker.patch("dvc.repo.experiments.gc.gc", return_value={})
|
|
|
|
assert cmd.run() == 0
|
|
|
|
m.assert_called_once_with(
|
|
cmd.repo,
|
|
workspace=True,
|
|
all_tags=True,
|
|
all_branches=True,
|
|
all_commits=True,
|
|
queued=True,
|
|
)
|
|
|
|
cli_args = parse_args(["exp", "gc"])
|
|
cmd = cli_args.func(cli_args)
|
|
with pytest.raises(InvalidArgumentError):
|
|
cmd.run()
|