Files
dvc/tests/unit/repo/experiments/test_utils.py
T
karajan1001 c81d841fd7 exp pull/push: better result handling in exp sharing(#7448)
fix: #7448
Current we skip on those experiments which already existed on both sides, but
do not exclude them from the result list. And if we have diverged experiment,
pulling/pushing them will stop the current progress and raise an exception, but
didn't give any information on the condition of other experiments.

1. Change the exp pull and push to match the new API in `scmrepo`.
2. Handle sync status after `exp pull/push` finished.
3. Bump scmrepo to 0.0.19

Co-authored-by:
2022-04-28 19:56:15 +08:00

45 lines
1.5 KiB
Python

import pytest
from dvc.exceptions import InvalidArgumentError
from dvc.repo.experiments.base import EXPS_NAMESPACE, ExpRefInfo
from dvc.repo.experiments.utils import check_ref_format, resolve_name
def commit_exp_ref(tmp_dir, scm, file="foo", contents="foo", name="foo"):
tmp_dir.scm_gen(file, contents, commit="init")
rev = scm.get_rev()
ref = "/".join([EXPS_NAMESPACE, "ab", "c123", name])
scm.gitpython.set_ref(ref, rev)
return ref, rev
@pytest.mark.parametrize("use_url", [True, False])
@pytest.mark.parametrize("name_only", [True, False])
def test_resolve_exp_ref(tmp_dir, scm, git_upstream, name_only, use_url):
ref, _ = commit_exp_ref(tmp_dir, scm)
name = "foo" if name_only else ref
result = resolve_name(scm, [name, "notexist"])
assert isinstance(result[name], ExpRefInfo)
assert str(result[name]) == ref
assert result["notexist"] is None
scm.push_refspecs(git_upstream.url, f"{ref}:{ref}")
remote = git_upstream.url if use_url else git_upstream.remote
name = "foo" if name_only else ref
remote_ref_info = resolve_name(scm, [name], remote)[name]
assert isinstance(remote_ref_info, ExpRefInfo)
assert str(remote_ref_info) == ref
@pytest.mark.parametrize(
"name,result", [("name", True), ("group/name", False), ("na me", False)]
)
def test_run_check_ref_format(scm, name, result):
ref = ExpRefInfo("abc123", name)
if result:
check_ref_format(scm, ref)
else:
with pytest.raises(InvalidArgumentError):
check_ref_format(scm, ref)