def test_stage_overwrites_if_already_exists(tmp_dir, dvc): lockfile = Lockfile(dvc, "path.lock",) stage = PipelineStage(name="s2", repo=dvc, path="path", cmd="command2") lockfile.dump(stage) stage = PipelineStage(name="s2", repo=dvc, path="path", cmd="command3") lockfile.dump(stage) assert lockfile.load() == { "s2": {"cmd": "command3"}, }
def test_stage_dump_with_deps_and_outs(tmp_dir, dvc): data = { "s1": { "cmd": "command", "deps": [{ "md5": "1.txt", "path": "checksum" }], "outs": [{ "md5": "2.txt", "path": "checksum" }], } } dump_yaml("path.lock", data) lockfile = Lockfile(dvc, "path.lock") stage = PipelineStage(name="s2", repo=dvc, path="path", cmd="command2") lockfile.dump(stage) assert lockfile.load() == { "schema": "2.0", "stages": { **data, "s2": { "cmd": "command2" } }, }
def test_dumpd(dvc): stages = [ PipelineStage(dvc, "dvc.yaml", name="stage1"), Stage(dvc, "path"), ] index = Index(dvc, stages=stages) assert index.dumpd() == {"dvc.yaml:stage1": {}, "path": {}} assert index.identifier == "d43da84e9001540c26abf2bf4541c275"
def test_stage_dump_no_outs_deps(tmp_dir, dvc): stage = PipelineStage(name="s1", repo=dvc, path="path", cmd="command") lockfile = Lockfile(dvc, "path.lock") lockfile.dump(stage) assert lockfile.load() == { "schema": "2.0", "stages": {"s1": {"cmd": "command"}}, }
def test_stage_on_no_path_string_repr(tmp_dir, dvc): s = Stage(dvc) assert s.addressing == "No path" assert repr(s) == "Stage: 'No path'" assert str(s) == "stage: 'No path'" p = PipelineStage(dvc, name="stage_name") assert p.addressing == "No path:stage_name" assert repr(p) == "Stage: 'No path:stage_name'" assert str(p) == "stage: 'No path:stage_name'"
def test_stage_dump_when_already_exists(tmp_dir, dvc): data = {"s1": {"cmd": "command", "deps": [], "outs": []}} dump_yaml("path.lock", data) stage = PipelineStage(name="s2", repo=dvc, path="path", cmd="command2") lockfile = Lockfile(dvc, "path.lock") lockfile.dump(stage) assert lockfile.load() == { "schema": "2.0", "stages": {**data, "s2": {"cmd": "command2"}}, }
def test_stage_dump_when_already_exists(tmp_dir, dvc): data = {"s1": {"cmd": "command", "deps": [], "outs": []}} with open("path.lock", "w+") as f: yaml.dump(data, f) stage = PipelineStage(name="s2", repo=dvc, path="path", cmd="command2") lockfile = Lockfile(dvc, "path.lock") lockfile.dump(stage) assert lockfile.load() == { **data, "s2": {"cmd": "command2"}, }
def test_dump_stage(tmp_dir, dvc): stage = PipelineStage( dvc, cmd="command", name="stage_name", path="dvc.yaml" ) dvcfile = Dvcfile(dvc, "dvc.yaml") dvcfile.dump(stage, no_lock=True) assert not (tmp_dir / PIPELINE_FILE).exists() assert not (tmp_dir / PIPELINE_LOCK).exists() dvcfile.dump(stage, no_lock=False) assert not (tmp_dir / PIPELINE_FILE).exists() assert dvcfile._lockfile.load() dvcfile.dump(stage, update_pipeline=True, no_lock=False) assert (tmp_dir / PIPELINE_FILE).exists() assert (tmp_dir / PIPELINE_LOCK).exists() assert list(dvcfile.stages.values()) == [stage]
def test_experiments_init(dvc, scm, mocker, capsys, extra_args): m = mocker.patch( "dvc.repo.experiments.init.init", return_value=PipelineStage(dvc, path="dvc.yaml", name="stage1"), ) runner = mocker.patch("dvc.repo.experiments.run.run", return_value=0) cli_args = parse_args(["exp", "init", *extra_args, "cmd"]) cmd = cli_args.func(cli_args) assert isinstance(cmd, CmdExperimentsInit) assert cmd.run() == 0 m.assert_called_once_with( ANY(Repo), name=None, type="default", defaults={ "code": "src", "models": "models", "data": "data", "metrics": "metrics.json", "params": "params.yaml", "plots": "plots", "live": "dvclive", }, overrides={"cmd": "cmd"}, interactive=False, force=False, ) expected = "Created default stage in dvc.yaml." if not extra_args: expected += ( ' To run, use "dvc exp run".\n' "See https://dvc.org/doc/user-guide/experiment-management" "/running-experiments." ) assert capsys.readouterr() == (expected + "\n", "") if extra_args: # `parse_args` creates a new `Repo` object runner.assert_called_once_with(ANY(Repo), targets=["stage1"])