Files
dvc/tests/unit/command/test_experiments.py
T
Peter Rowlands (변기호) 176a23e291 experiments: store experiments in refs/exps instead of heads (#4910)
* experiments: commit to refs/exps/... instead of branch heads

* update exp show

* restore checkpoint_resume kwarg

* refactor new() to use experiments stash

* experiments: use refspecs to populate and collect executors

* experiments: use new stash and merge on exp checkout

* experiments: fix executor chdir

* experiments: update run and show

* skip checkout after reproduce

* checkpoints: use experiments refspecs

* check if workspace was stashed before applying

* exp show: unify checkpoint/standalone experiment collection

* git: move iter_refs to backend

* update for scm changes

* experiments: replace exp checkout in favor of exp apply

* git: handle rev_parse errors in resolve_commit

* update refs containing and baseline check

* fix sigint handling for checkpoints

* update checkpoint exists behavior

* fix checkpoint baseline behavior

* update tests

* experiments: update gc

* update show tests

* fix type checking errors

* update diff

* scm: add diff, describe

* experiments: generate human readable names

* exp run/resume: allow user specified exp name with -n/--name

* update tests

* experiments: add `exp branch` for promoting experiment to full branch

* fix test

* fix missing file

* experiments: explicitly close scm instances before cleaning up tmp dir
2020-12-02 21:20:57 +09:00

153 lines
3.6 KiB
Python

import pytest
from dvc.cli import parse_args
from dvc.command.experiments import (
CmdExperimentsApply,
CmdExperimentsBranch,
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_apply(dvc, mocker):
cli_args = parse_args(["experiments", "apply", "exp_rev"])
assert cli_args.func == CmdExperimentsApply
cmd = cli_args.func(cli_args)
m = mocker.patch("dvc.repo.experiments.apply.apply", return_value={})
assert cmd.run() == 0
m.assert_called_once_with(cmd.repo, "exp_rev")
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": [],
"name": None,
"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()
def test_experiments_branch(dvc, mocker):
cli_args = parse_args(["experiments", "branch", "expname", "branchname"])
assert cli_args.func == CmdExperimentsBranch
cmd = cli_args.func(cli_args)
m = mocker.patch("dvc.repo.experiments.branch.branch", return_value={})
assert cmd.run() == 0
m.assert_called_once_with(cmd.repo, "expname", "branchname")