add more extensive tests

This commit is contained in:
AlexandreKempf
2024-02-29 13:50:30 -05:00
committed by Dave Berenbaum
parent 7c34370464
commit 0ee6d6eba8
3 changed files with 83 additions and 19 deletions
+20 -16
View File
@@ -3,36 +3,36 @@ import dpath
from dvc.repo.plots import Plots
def test_plots_definitions_works_with_nested_plots(tmp_dir, scm, dvc):
data_v1 = [
def test_subdir_config_not_overwritten_by_parents(tmp_dir, scm, dvc):
plot_data = [
{"x": 1, "y": 0.1},
{"x": 2, "y": 0.2},
{"x": 3, "y": 0.3},
]
data_subdir_v1 = [
subdir_plot_data = [
{"x": 1, "y": 0.2, "z": 0.1},
{"x": 2, "y": 0.3, "z": 0.2},
{"x": 3, "y": 0.4, "z": 0.3},
]
plots_dir = tmp_dir / "plots"
subdir = plots_dir / "subdir"
(tmp_dir / "plots").mkdir()
(tmp_dir / "plots" / "subdir").mkdir()
plots_dir.mkdir()
subdir.mkdir()
(plots_dir / "data_v1.json").dump_json(data_v1)
(subdir / "data_subdir_v1.json").dump_json(data_subdir_v1)
(tmp_dir / "plots" / "plot.json").dump_json(plot_data)
(tmp_dir / "plots" / "subdir" / "plot.json").dump_json(subdir_plot_data)
plots_config = [
{
"plots/subdir/": {
"x": "z",
"y": "x",
}
},
{"plots": {"x": "x", "y": "y"}},
{
"plots": {
"x": "x",
"subdir axis defined by filename": {
"x": {"plots/subdir/plot.json": "x"},
"y": {"plots/subdir/plot.json": "y"},
}
},
]
@@ -44,8 +44,8 @@ def test_plots_definitions_works_with_nested_plots(tmp_dir, scm, dvc):
scm.add(
[
"plots/data_v1.json",
"plots/subdir/data_subdir_v1.json",
"plots/plot.json",
"plots/subdir/plot.json",
"dvc.yaml",
]
)
@@ -54,6 +54,10 @@ def test_plots_definitions_works_with_nested_plots(tmp_dir, scm, dvc):
plots = next(Plots(dvc).collect())
assert dpath.get(plots, "workspace/definitions/data/dvc.yaml/data") == {
"plots/data_v1.json": {"x": "x"},
"plots/subdir/data_subdir_v1.json": {"x": "z"},
"plots/plot.json": {"x": "x", "y": "y"},
"plots/subdir/plot.json": {"x": "z", "y": "x"},
"subdir axis defined by filename": {
"x": {"plots/subdir/plot.json": "x"},
"y": {"plots/subdir/plot.json": "y"},
},
}
+45 -3
View File
@@ -86,15 +86,27 @@ def repo_with_plots(tmp_dir, scm, dvc, run_copy_metrics):
@pytest.fixture
def repo_with_config_plots(tmp_dir, scm, dvc, run_copy_metrics):
def make():
# test subdir functionality
linear_subdirA_v1 = [
{"x": 1, "y": 0.2},
{"x": 2, "y": 0.3},
{"x": 3, "y": 0.4},
]
# test subdir default values for x = step
linear_subdirB_v1 = [
{"step": 1, "y": 0.2},
{"step": 2, "y": 0.3},
{"step": 3, "y": 0.4},
]
linear_train_v1 = [
{"x": 1, "y": 0.1},
{"x": 2, "y": 0.2},
{"x": 3, "y": 0.3},
]
linear_test_v1 = [
{"x": 1, "y": 0.2},
{"x": 2, "y": 0.3},
{"x": 3, "y": 0.4},
{"x": 1, "y": 0.3},
{"x": 2, "y": 0.4},
{"x": 3, "y": 0.5},
]
confusion_train_v1 = [
@@ -110,6 +122,10 @@ def repo_with_config_plots(tmp_dir, scm, dvc, run_copy_metrics):
{"actual": 1, "predicted": 0},
]
(tmp_dir / "subdirA").mkdir()
(tmp_dir / "subdirB").mkdir()
(tmp_dir / "subdirA" / "linear_subdir_src.json").dump_json(linear_subdirA_v1)
(tmp_dir / "subdirB" / "linear_subdir_src.json").dump_json(linear_subdirB_v1)
(tmp_dir / "linear_train_src.json").dump_json(linear_train_v1)
(tmp_dir / "linear_test_src.json").dump_json(linear_test_v1)
(tmp_dir / "confusion_train_src.json").dump_json(confusion_train_v1)
@@ -117,6 +133,8 @@ def repo_with_config_plots(tmp_dir, scm, dvc, run_copy_metrics):
scm.add(
[
"subdirA/linear_subdir_src.json",
"subdirB/linear_subdir_src.json",
"linear_train_src.json",
"linear_test_src.json",
"confusion_train_src.json",
@@ -125,6 +143,20 @@ def repo_with_config_plots(tmp_dir, scm, dvc, run_copy_metrics):
)
scm.commit("add data sources")
run_copy_metrics(
"subdirA/linear_subdir_src.json",
"subdirA/linear_subdir.json",
name="linear_subdir",
outs=["subdirA/linear_subdir.json"],
commit="linear_subdir",
)
run_copy_metrics(
"subdirB/linear_subdir_src.json",
"subdirB/linear_subdir.json",
name="linear_subdir",
outs=["subdirB/linear_subdir.json"],
commit="linear_subdir",
)
run_copy_metrics(
"linear_train_src.json",
"linear_train.json",
@@ -154,6 +186,14 @@ def repo_with_config_plots(tmp_dir, scm, dvc, run_copy_metrics):
commit="confusion_test",
)
plots_config = [
{
"subdirA": {
"x": "x",
"y": "y",
"title": "subdir plots with x and y defined",
}
},
{"subdirB": {"title": "subdir plots with default x and y"}},
{
"linear_train_vs_test": {
"x": "x",
@@ -182,6 +222,8 @@ def repo_with_config_plots(tmp_dir, scm, dvc, run_copy_metrics):
scm.commit("commit dvc files")
yield {
"data": {
"subdirA/linear_subdir.json": linear_subdirA_v1,
"subdirB/linear_subdir.json": linear_subdirB_v1,
"linear_train.json": linear_train_v1,
"linear_test.json": linear_test_v1,
"confusion_train.json": confusion_train_v1,
+18
View File
@@ -440,6 +440,8 @@ def test_repo_with_config_plots(tmp_dir, capsys, repo_with_config_plots):
html_result = extract_vega_specs(
html_path,
[
"subdirA/linear_subdir.json",
"subdirB/linear_subdir.json",
"linear_train_vs_test",
"confusion_train_vs_test",
],
@@ -466,6 +468,22 @@ def test_repo_with_config_plots(tmp_dir, capsys, repo_with_config_plots):
]
== ble
)
assert (
html_result["subdirA/linear_subdir.json"]["layer"][1]["encoding"]["x"]["field"]
== "x"
)
assert (
html_result["subdirA/linear_subdir.json"]["layer"][1]["encoding"]["y"]["field"]
== "y"
)
assert (
html_result["subdirB/linear_subdir.json"]["layer"][1]["encoding"]["x"]["field"]
== "step"
)
assert (
html_result["subdirB/linear_subdir.json"]["layer"][1]["encoding"]["y"]["field"]
== "y"
)
@pytest.mark.vscode