def test_experiments_init(dvc, scm, mocker, capsys, extra_args): stage = mocker.Mock(outs=[], addressing="train") m = mocker.patch("dvc.repo.experiments.init.init", return_value=(stage, [], [])) 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="train", type="default", defaults={ "code": "src", "models": "models", "data": "data", "metrics": "metrics.json", "params": "params.yaml", "plots": "plots", }, overrides={"cmd": "cmd"}, interactive=False, force=False, ) if extra_args: # `parse_args` creates a new `Repo` object runner.assert_called_once_with(ANY(Repo), targets=["train"])
def test_experiments_init_config(dvc, scm, mocker): with dvc.config.edit() as conf: conf["exp"] = {"code": "new_src", "models": "new_models"} m = mocker.patch("dvc.repo.experiments.init.init") cli_args = parse_args(["exp", "init", "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": "new_src", "models": "new_models", "data": "data", "metrics": "metrics.json", "params": "params.yaml", "plots": "plots", "live": "dvclive", }, overrides={"cmd": "cmd"}, interactive=False, force=False, )
def test_experiments_init_extra_args(extra_args, expected_kw, mocker): cli_args = parse_args(["exp", "init", *extra_args, "cmd"]) cmd = cli_args.func(cli_args) assert isinstance(cmd, CmdExperimentsInit) m = mocker.patch("dvc.repo.experiments.init.init") assert cmd.run() == 0 assert called_once_with_subset(m, ANY(Repo), **expected_kw)
def test_experiments_init_cmd_not_required_for_interactive_mode(dvc, mocker): cli_args = parse_args(["exp", "init", "--interactive"]) cmd = cli_args.func(cli_args) assert isinstance(cmd, CmdExperimentsInit) m = mocker.patch("dvc.repo.experiments.init.init") assert cmd.run() == 0 assert called_once_with_subset(m, ANY(Repo), interactive=True)
def test_collect_and_send_report(mocker, dvc, mock_daemon): mock_post = mocker.patch("requests.post") collect_and_send_report() assert mock_daemon.call_count == 1 assert mock_post.call_count == 1 assert mock_post.call_args == call( "https://analytics.dvc.org", json=ANY(dict), headers={"content-type": "application/json"}, timeout=5, )
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"])
def test_experiments_init_explicit(dvc, mocker): m = mocker.patch("dvc.repo.experiments.init.init") cli_args = parse_args(["exp", "init", "--explicit", "cmd"]) cmd = cli_args.func(cli_args) assert cmd.run() == 0 m.assert_called_once_with( ANY(Repo), name=None, type="default", defaults={}, overrides={"cmd": "cmd"}, interactive=False, force=False, )
def test_experiments_init_explicit(dvc, mocker): stage = mocker.Mock(outs=[]) m = mocker.patch("dvc.repo.experiments.init.init", return_value=(stage, [], [])) cli_args = parse_args(["exp", "init", "--explicit", "cmd"]) cmd = cli_args.func(cli_args) assert cmd.run() == 0 m.assert_called_once_with( ANY(Repo), name="train", type="default", defaults={}, overrides={"cmd": "cmd"}, interactive=False, force=False, )