Files
dvc/tests/func/experiments/test_utils.py
T
David de la Iglesia Castro bb7512687c exp: Generate a human-readable name beforehand.
- Add `get_random_exp_name` to utils.
Generates a name (`f"{adjective}-{noun}"`) by randomly chosing pairs of adjetive, noun.
Recieves `scm` and `baseline_rev` and retries the random choice until a non-existing ref is found.

Closes https://github.com/iterative/dvc/issues/8650
2022-12-09 10:32:38 +01:00

30 lines
880 B
Python

from funcy import first
def test_generate_random_exp_name(tmp_dir, dvc, scm, exp_stage, mocker):
mocker.patch(
"dvc.repo.experiments.utils.random.choice",
side_effect=[
0,
0,
0,
0,
1,
1,
0,
0,
],
)
ref = first(dvc.experiments.run(exp_stage.addressing, params=["foo=1"]))
assert dvc.experiments.get_exact_name([ref])[ref] == "0-0"
# Causes 1 retry
ref = first(dvc.experiments.run(exp_stage.addressing, params=["foo=2"]))
assert dvc.experiments.get_exact_name([ref])[ref] == "1-1"
tmp_dir.scm_gen({"foo": "bar"}, commit="foo")
# Can use same name because of different baseline_rev
ref = first(dvc.experiments.run(exp_stage.addressing, params=["foo=1"]))
assert dvc.experiments.get_exact_name([ref])[ref] == "0-0"