mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-11 15:28:27 +01:00
* 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]>
42 lines
1.4 KiB
Python
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)
|