mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 07:18:27 +01:00
add tests
This commit is contained in:
committed by
David de la Iglesia Castro
parent
df60f5d9bf
commit
28402dedf1
@@ -34,7 +34,9 @@ def _collect_top_level_metrics(repo):
|
||||
wdir = repo.dvcfs.path.relpath(
|
||||
repo.dvcfs.path.parent(dvcfile), repo.root_dir
|
||||
)
|
||||
yield from (repo.dvcfs.path.join(wdir, file) for file in metrics)
|
||||
for file in metrics:
|
||||
path = repo.dvcfs.path.join(wdir, file)
|
||||
yield repo.dvcfs.path.normpath(path)
|
||||
|
||||
|
||||
def _collect_metrics(repo, targets, revision, recursive):
|
||||
|
||||
@@ -41,7 +41,9 @@ def _collect_top_level_params(repo):
|
||||
wdir = repo.dvcfs.path.relpath(
|
||||
repo.dvcfs.path.parent(dvcfile), repo.root_dir
|
||||
)
|
||||
yield from (repo.dvcfs.path.join(wdir, file) for file in params)
|
||||
for file in params:
|
||||
path = repo.dvcfs.path.join(wdir, file)
|
||||
yield repo.dvcfs.path.normpath(path)
|
||||
|
||||
|
||||
def _collect_configs(
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import json
|
||||
from os.path import join
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.cli import main
|
||||
from dvc.utils import relpath
|
||||
|
||||
|
||||
def test_metrics_diff_simple(tmp_dir, scm, dvc, run_copy_metrics):
|
||||
@@ -206,3 +210,28 @@ def test_metrics_diff_non_metrics(tmp_dir, scm, dvc):
|
||||
assert result == {
|
||||
"some_file.yaml": {"foo": {"old": 1, "new": 3, "diff": 2}}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"dvcfile, metrics_file",
|
||||
[
|
||||
("dvc.yaml", "my_metrics.yaml"),
|
||||
("dir/dvc.yaml", "my_metrics.yaml"),
|
||||
("dir/dvc.yaml", join("..", "my_metrics.yaml")),
|
||||
],
|
||||
)
|
||||
def test_diff_top_level_metrics(tmp_dir, dvc, scm, dvcfile, metrics_file):
|
||||
directory = (tmp_dir / dvcfile).parent
|
||||
directory.mkdir(exist_ok=True)
|
||||
(tmp_dir / dvcfile).dump({"metrics": [metrics_file]})
|
||||
|
||||
metrics_file = directory / metrics_file
|
||||
metrics_file.dump({"foo": 3})
|
||||
scm.add_commit([metrics_file, tmp_dir / dvcfile], message="add metrics")
|
||||
|
||||
metrics_file.dump({"foo": 5})
|
||||
assert dvc.metrics.diff() == {
|
||||
relpath(directory / metrics_file): {
|
||||
"foo": {"diff": 2, "new": 5, "old": 3}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from os.path import join
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.utils import relpath
|
||||
@@ -241,3 +243,28 @@ def test_diff_without_targets_specified(tmp_dir, dvc, scm, file):
|
||||
"y": {"new": "100", "old": None},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"dvcfile, params_file",
|
||||
[
|
||||
("dvc.yaml", "my_params.yaml"),
|
||||
("dir/dvc.yaml", "my_params.yaml"),
|
||||
("dir/dvc.yaml", join("..", "my_params.yaml")),
|
||||
],
|
||||
)
|
||||
def test_diff_top_level_params(tmp_dir, dvc, scm, dvcfile, params_file):
|
||||
directory = (tmp_dir / dvcfile).parent
|
||||
directory.mkdir(exist_ok=True)
|
||||
(tmp_dir / dvcfile).dump({"params": [params_file]})
|
||||
|
||||
params_file = directory / params_file
|
||||
params_file.dump({"foo": 3})
|
||||
scm.add_commit([params_file, tmp_dir / dvcfile], message="add params")
|
||||
|
||||
params_file.dump({"foo": 5})
|
||||
assert dvc.params.diff() == {
|
||||
relpath(directory / params_file): {
|
||||
"foo": {"diff": 2, "new": 5, "old": 3}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user