Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Dec 1, 2022
1 parent eb59c16 commit 8715d73
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
4 changes: 3 additions & 1 deletion dvc/repo/metrics/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion dvc/repo/params/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
29 changes: 29 additions & 0 deletions tests/func/metrics/test_diff.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -206,3 +210,28 @@ def _gen(val):
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}
}
}
27 changes: 27 additions & 0 deletions tests/func/params/test_diff.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from os.path import join

import pytest

from dvc.utils import relpath
Expand Down Expand Up @@ -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}
}
}

0 comments on commit 8715d73

Please sign in to comment.