Files
dvc/tests/unit/repo/experiments/test_utils.py
T
GaoandPeter Rowlands c07592131a exp run: add experiment name check. (#6848)
* Add experiment name check.

1. Add experiment name check (https://git-scm.com/docs/git-check-ref-format)
2. Add duplicate exp name check.
3. Add some unit test for it.

* Ban slash / in dvc exp names

* Use dulwich backend for ref name checking

* Some bug fix

* Update dvc/repo/experiments/__init__.py

Co-authored-by: Peter Rowlands (변기호) <[email protected]>

* Update dvc/repo/experiments/__init__.py

Co-authored-by: Peter Rowlands (변기호) <[email protected]>

* Some review changes

* Make some funtion more reusable.

Co-authored-by: Peter Rowlands (변기호) <[email protected]>
2021-10-25 20:16:37 +09:00

42 lines
1.4 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_exp_ref
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)
ref_info = resolve_exp_ref(scm, "foo" if name_only else ref)
assert isinstance(ref_info, ExpRefInfo)
assert str(ref_info) == ref
scm.push_refspec(git_upstream.url, ref, ref)
remote = git_upstream.url if use_url else git_upstream.remote
remote_ref_info = resolve_exp_ref(scm, "foo" if name_only else ref, remote)
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)