def test_show_running_workspace(tmp_dir, scm, dvc, exp_stage, capsys): pid_dir = os.path.join(dvc.tmp_dir, dvc.experiments.EXEC_PID_DIR) makedirs(pid_dir, True) info = ExecutorInfo(None, None, None, BaseExecutor.DEFAULT_LOCATION) pidfile = os.path.join(pid_dir, f"workspace{BaseExecutor.PIDFILE_EXT}") (tmp_dir / pidfile).dump(info.to_dict()) assert dvc.experiments.show()["workspace"] == { "baseline": { "data": { "metrics": {"metrics.yaml": {"data": {"foo": 1}}}, "params": {"params.yaml": {"data": {"foo": 1}}}, "queued": False, "running": True, "executor": info.location, "timestamp": None, } } } capsys.readouterr() assert main(["exp", "show", "--no-pager"]) == 0 cap = capsys.readouterr() assert "Running" in cap.out assert info.location in cap.out
def test_show_running_executor(tmp_dir, scm, dvc, exp_stage): baseline_rev = scm.get_rev() dvc.experiments.run(exp_stage.addressing, params=["foo=2"], queue=True) exp_rev = dvc.experiments.scm.resolve_rev(f"{EXPS_STASH}@{{0}}") pid_dir = os.path.join(dvc.tmp_dir, dvc.experiments.EXEC_PID_DIR) makedirs(pid_dir, True) info = ExecutorInfo(None, None, None, BaseExecutor.DEFAULT_LOCATION) pidfile = os.path.join(pid_dir, f"{exp_rev}{BaseExecutor.PIDFILE_EXT}") (tmp_dir / pidfile).dump(info.to_dict()) results = dvc.experiments.show() exp_data = get_in(results, [baseline_rev, exp_rev, "data"]) assert not exp_data["queued"] assert exp_data["running"] assert exp_data["executor"] == info.location assert not results["workspace"]["baseline"]["data"]["running"]
def test_show_running_checkpoint( tmp_dir, scm, dvc, checkpoint_stage, workspace, mocker ): from dvc.repo.experiments.base import EXEC_BRANCH from dvc.repo.experiments.executor.local import TempDirExecutor baseline_rev = scm.get_rev() dvc.experiments.run( checkpoint_stage.addressing, params=["foo=2"], queue=True ) stash_rev = dvc.experiments.scm.resolve_rev(f"{EXPS_STASH}@{{0}}") run_results = dvc.experiments.run(run_all=True) checkpoint_rev = first(run_results) exp_ref = first(exp_refs_by_rev(scm, checkpoint_rev)) pid_dir = os.path.join(dvc.tmp_dir, dvc.experiments.EXEC_PID_DIR) makedirs(pid_dir, True) executor = ( BaseExecutor.DEFAULT_LOCATION if workspace else TempDirExecutor.DEFAULT_LOCATION ) info = ExecutorInfo(123, "foo.git", baseline_rev, executor) rev = "workspace" if workspace else stash_rev pidfile = os.path.join(pid_dir, f"{rev}{BaseExecutor.PIDFILE_EXT}") (tmp_dir / pidfile).dump(info.to_dict()) mocker.patch.object( BaseExecutor, "fetch_exps", return_value=[str(exp_ref)] ) if workspace: scm.set_ref(EXEC_BRANCH, str(exp_ref), symbolic=True) results = dvc.experiments.show() checkpoint_res = get_in(results, [baseline_rev, checkpoint_rev, "data"]) assert checkpoint_res["running"] assert checkpoint_res["executor"] == info.location assert not results["workspace"]["baseline"]["data"]["running"]