Files
dvc/tests/func/experiments/test_diff.py
T
David de la Iglesia Castro 2cef130191 repo: Handle no commits for exp show and plots diff.
Make it consistent with all the other commands that use `brancher` (i.e. `dvc diff`, `metrics diff`, `params diff`)

Closes #8163
2022-08-29 01:50:14 +03:00

39 lines
1.2 KiB
Python

from funcy import first
def test_diff_no_commits(tmp_dir):
from scmrepo.git import Git
from dvc.repo import Repo
git = Git.init(tmp_dir.fs_path)
assert git.no_commits
assert Repo.init().experiments.diff() == {}
def test_diff_empty(tmp_dir, scm, dvc, exp_stage):
assert dvc.experiments.diff() == {"params": {}, "metrics": {}}
def test_diff_head(tmp_dir, scm, dvc, exp_stage):
results = dvc.experiments.run(exp_stage.addressing, params=["foo=2"])
exp = first(results)
assert dvc.experiments.diff(a_rev="HEAD", b_rev=exp) == {
"params": {"params.yaml": {"foo": {"diff": 1, "old": 1, "new": 2}}},
"metrics": {"metrics.yaml": {"foo": {"diff": 1, "old": 1, "new": 2}}},
}
def test_diff_exp(tmp_dir, scm, dvc, exp_stage):
results = dvc.experiments.run(exp_stage.addressing, params=["foo=2"])
exp_a = first(results)
results = dvc.experiments.run(exp_stage.addressing, params=["foo=3"])
exp_b = first(results)
assert dvc.experiments.diff(a_rev=exp_a, b_rev=exp_b) == {
"params": {"params.yaml": {"foo": {"diff": 1, "old": 2, "new": 3}}},
"metrics": {"metrics.yaml": {"foo": {"diff": 1, "old": 2, "new": 3}}},
}