Files
dvc/tests/unit/repo/experiments/test_utils.py
T
4cc06339c8 Clean up remotes's exps (#6471)
* Clean up remotes's exps

fix #6006
1. add a new argument `--git-remote` to `dvc exp remove`
2. support remote a special remote exp
3. add tests for it
4. fix  #6421
5. add a test for #6421.
6. extract some functions from the `dvc pull`, `dvc push`, `dvc remove` to utils.
7. add a tests for this new util function `resolve_exp_ref`
8. add `__init__.py` to some test package for the pytest fail

Co-authored-by: Jorge Orpinel <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Dave Berenbaum <[email protected]>
2021-09-05 10:06:07 +08:00

28 lines
1.0 KiB
Python

import pytest
from dvc.repo.experiments.base import EXPS_NAMESPACE, ExpRefInfo
from dvc.repo.experiments.utils import 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