forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plots: tests: integration tests for studio
Related: iterative#7549
- Loading branch information
Showing
7 changed files
with
228 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def repo_with_plots(tmp_dir, scm, dvc, run_copy_metrics): | ||
def make(): | ||
linear_v1 = [ | ||
{"x": 1, "y": 0.1}, | ||
{"x": 2, "y": 0.2}, | ||
{"x": 3, "y": 0.3}, | ||
] | ||
|
||
confusion_v1 = [ | ||
{"actual": 0, "predicted": 1}, | ||
{"actual": 0, "predicted": 1}, | ||
{"actual": 1, "predicted": 0}, | ||
{"actual": 1, "predicted": 0}, | ||
] | ||
|
||
image_v1 = b"content" | ||
|
||
(tmp_dir / "linear_src.json").dump_json(linear_v1) | ||
(tmp_dir / "confusion_src.json").dump_json(confusion_v1) | ||
(tmp_dir / "image_src.png").write_bytes(image_v1) | ||
|
||
scm.add(["linear_src.json", "confusion_src.json", "image_src.png"]) | ||
scm.commit("add data sources") | ||
|
||
run_copy_metrics( | ||
"linear_src.json", | ||
"linear.json", | ||
name="linear", | ||
plots=["linear.json"], | ||
commit="linear", | ||
) | ||
run_copy_metrics( | ||
"confusion_src.json", | ||
"confusion.json", | ||
name="confusion", | ||
plots=["confusion.json"], | ||
commit="confusion", | ||
) | ||
confusion_props = { | ||
"title": "confusion matrix", | ||
"x": "predicted", | ||
"y": "actual", | ||
"template": "confusion", | ||
} | ||
dvc.plots.modify("confusion.json", confusion_props) | ||
run_copy_metrics( | ||
"image_src.png", | ||
"image.png", | ||
name="image", | ||
plots=["image.png"], | ||
commit="image", | ||
) | ||
|
||
scm.add(["dvc.yaml", "dvc.lock"]) | ||
scm.commit("commit dvc files") | ||
yield image_v1, linear_v1, confusion_v1, confusion_props | ||
linear_v2 = [ | ||
{"x": 1, "y": 0.2}, | ||
{"x": 2, "y": 0.3}, | ||
{"x": 3, "y": 0.4}, | ||
] | ||
confusion_v2 = [ | ||
{"actual": 0, "predicted": 0}, | ||
{"actual": 0, "predicted": 0}, | ||
{"actual": 1, "predicted": 1}, | ||
{"actual": 1, "predicted": 1}, | ||
] | ||
image_v2 = b"content2" | ||
|
||
(tmp_dir / "linear_src.json").dump_json(linear_v2) | ||
(tmp_dir / "confusion_src.json").dump_json(confusion_v2) | ||
(tmp_dir / "image_src.png").write_bytes(image_v2) | ||
|
||
dvc.reproduce() | ||
yield image_v2, linear_v2, confusion_v2, confusion_props | ||
|
||
return make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import dpath.util | ||
import pytest | ||
|
||
|
||
@pytest.mark.studio | ||
def test_api(tmp_dir, dvc, repo_with_plots): | ||
repo_state = repo_with_plots() | ||
image_v1, linear_v1, confusion_v1, confusion_params = next(repo_state) | ||
|
||
workspace_data = next(dvc.plots.collect()) | ||
|
||
assert ( | ||
dpath.util.get( | ||
workspace_data, ["workspace", "data", "image.png", "props"] | ||
) | ||
== {} | ||
) | ||
image_source = dpath.util.get( | ||
workspace_data, ["workspace", "data", "image.png", "data_source"] | ||
) | ||
assert callable(image_source) | ||
assert image_source() == {"data": image_v1} | ||
|
||
assert ( | ||
dpath.util.get( | ||
workspace_data, ["workspace", "data", "linear.json", "props"] | ||
) | ||
== {} | ||
) | ||
linear_source = dpath.util.get( | ||
workspace_data, ["workspace", "data", "linear.json", "data_source"] | ||
) | ||
assert callable(linear_source) | ||
assert linear_source() == {"data": linear_v1} | ||
|
||
assert ( | ||
dpath.util.get( | ||
workspace_data, ["workspace", "data", "confusion.json", "props"] | ||
) | ||
== confusion_params | ||
) | ||
confusion_source = dpath.util.get( | ||
workspace_data, ["workspace", "data", "confusion.json", "data_source"] | ||
) | ||
assert callable(confusion_source) | ||
assert confusion_source() == {"data": confusion_v1} | ||
|
||
image_v2, linear_v2, confusion_v2, _ = next(repo_state) | ||
data_generator = dvc.plots.collect(revs=["workspace", "HEAD"]) | ||
|
||
workspace_data = next(data_generator) | ||
|
||
assert ( | ||
dpath.util.get( | ||
workspace_data, ["workspace", "data", "image.png", "props"] | ||
) | ||
== {} | ||
) | ||
image_source = dpath.util.get( | ||
workspace_data, ["workspace", "data", "image.png", "data_source"] | ||
) | ||
assert callable(image_source) | ||
assert image_source() == {"data": image_v2} | ||
|
||
assert ( | ||
dpath.util.get( | ||
workspace_data, ["workspace", "data", "linear.json", "props"] | ||
) | ||
== {} | ||
) | ||
linear_source = dpath.util.get( | ||
workspace_data, ["workspace", "data", "linear.json", "data_source"] | ||
) | ||
assert callable(linear_source) | ||
assert linear_source() == {"data": linear_v2} | ||
|
||
assert ( | ||
dpath.util.get( | ||
workspace_data, ["workspace", "data", "confusion.json", "props"] | ||
) | ||
== confusion_params | ||
) | ||
confusion_source = dpath.util.get( | ||
workspace_data, ["workspace", "data", "confusion.json", "data_source"] | ||
) | ||
assert callable(confusion_source) | ||
assert confusion_source() == {"data": confusion_v2} | ||
|
||
head_data = next(data_generator) | ||
|
||
assert ( | ||
dpath.util.get(head_data, ["HEAD", "data", "image.png", "props"]) == {} | ||
) | ||
image_source = dpath.util.get( | ||
head_data, ["HEAD", "data", "image.png", "data_source"] | ||
) | ||
assert callable(image_source) | ||
assert image_source() == {"data": image_v1} | ||
|
||
assert ( | ||
dpath.util.get(head_data, ["HEAD", "data", "linear.json", "props"]) | ||
== {} | ||
) | ||
linear_source = dpath.util.get( | ||
head_data, ["HEAD", "data", "linear.json", "data_source"] | ||
) | ||
assert callable(linear_source) | ||
assert linear_source() == {"data": linear_v1} | ||
|
||
assert ( | ||
dpath.util.get(head_data, ["HEAD", "data", "confusion.json", "props"]) | ||
== confusion_params | ||
) | ||
confusion_source = dpath.util.get( | ||
head_data, ["HEAD", "data", "confusion.json", "data_source"] | ||
) | ||
assert callable(confusion_source) | ||
assert confusion_source() == {"data": confusion_v1} |