From 04b50c5cd099fcbd41676e7b1234d869bf6ae18e Mon Sep 17 00:00:00 2001 From: dberenbaum Date: Mon, 19 Jun 2023 13:28:43 -0400 Subject: [PATCH] exp push/pull: default to head rev --- dvc/repo/experiments/pull.py | 2 +- dvc/repo/experiments/push.py | 2 +- tests/func/experiments/test_remote.py | 11 +++++++++++ tests/unit/command/test_experiments.py | 14 ++------------ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/dvc/repo/experiments/pull.py b/dvc/repo/experiments/pull.py index 50d54fdc5..6841cfd4c 100644 --- a/dvc/repo/experiments/pull.py +++ b/dvc/repo/experiments/pull.py @@ -21,7 +21,7 @@ logger = logging.getLogger(__name__) def pull( # noqa: C901 repo, git_remote: str, - exp_names: Union[Iterable[str], str], + exp_names: Optional[Union[Iterable[str], str]] = None, all_commits=False, rev: Optional[Union[List[str], str]] = None, num=1, diff --git a/dvc/repo/experiments/push.py b/dvc/repo/experiments/push.py index 81c6ed473..f7b81baa2 100644 --- a/dvc/repo/experiments/push.py +++ b/dvc/repo/experiments/push.py @@ -97,7 +97,7 @@ def exp_refs_from_rev(scm: "Git", rev: List[str], num: int = 1) -> Set["ExpRefIn def push( repo: "Repo", git_remote: str, - exp_names: Union[List[str], str], + exp_names: Optional[Union[List[str], str]] = None, all_commits: bool = False, rev: Optional[Union[List[str], str]] = None, num: int = 1, diff --git a/tests/func/experiments/test_remote.py b/tests/func/experiments/test_remote.py index 1d244a399..8a3d898b7 100644 --- a/tests/func/experiments/test_remote.py +++ b/tests/func/experiments/test_remote.py @@ -35,6 +35,9 @@ def test_push(tmp_dir, scm, dvc, git_upstream, exp_stage, use_url): dvc.experiments.push(remote, [ref_info1.name]) assert git_upstream.tmp_dir.scm.get_ref(str(ref_info1)) == exp1 + dvc.experiments.push(remote) + assert git_upstream.tmp_dir.scm.get_ref(str(ref_info3)) == exp3 + @pytest.mark.parametrize("all_,rev,result3", [(True, False, True), (False, True, None)]) def test_push_args(tmp_dir, scm, dvc, git_upstream, exp_stage, all_, rev, result3): @@ -173,6 +176,11 @@ def test_list_remote(tmp_dir, scm, dvc, git_downstream, exp_stage, use_url): def test_pull(tmp_dir, scm, dvc, git_downstream, exp_stage, use_url): from dvc.exceptions import InvalidArgumentError + # fetch and checkout to downstream so both repos start from same commit + downstream_repo = git_downstream.tmp_dir.scm.gitpython.repo + fetched = downstream_repo.remote(git_downstream.remote).fetch() + downstream_repo.git.checkout(fetched) + remote = git_downstream.url if use_url else git_downstream.remote downstream_exp = git_downstream.tmp_dir.dvc.experiments with pytest.raises(InvalidArgumentError): @@ -200,6 +208,9 @@ def test_pull(tmp_dir, scm, dvc, git_downstream, exp_stage, use_url): downstream_exp.pull(remote, [str(ref_info1)]) assert git_downstream.tmp_dir.scm.get_ref(str(ref_info1)) == exp1 + downstream_exp.pull(remote) + assert git_downstream.tmp_dir.scm.get_ref(str(ref_info3)) == exp3 + @pytest.mark.parametrize("all_,rev,result3", [(True, False, True), (False, True, None)]) def test_pull_args(tmp_dir, scm, dvc, git_downstream, exp_stage, all_, rev, result3): diff --git a/tests/unit/command/test_experiments.py b/tests/unit/command/test_experiments.py index 9d8c6c82c..126ae1af6 100644 --- a/tests/unit/command/test_experiments.py +++ b/tests/unit/command/test_experiments.py @@ -294,12 +294,7 @@ def test_experiments_push(dvc, scm, mocker): ) cmd = cli_args.func(cli_args) - with pytest.raises(InvalidArgumentError) as exp_info: - cmd.run() - assert ( - str(exp_info.value) == "Either provide an `experiment` argument" - ", or use the `--rev` or `--all-commits` flag." - ) + assert cmd.run() == 0 def test_experiments_pull(dvc, scm, mocker): @@ -351,12 +346,7 @@ def test_experiments_pull(dvc, scm, mocker): ) cmd = cli_args.func(cli_args) - with pytest.raises(InvalidArgumentError) as exp_info: - cmd.run() - assert ( - str(exp_info.value) == "Either provide an `experiment` argument" - ", or use the `--rev` or `--all-commits` flag." - ) + assert cmd.run() == 0 def test_experiments_remove_flag(dvc, scm, mocker, capsys, caplog):