-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from textwrap import dedent | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def repo_with_plots(tmp_dir, scm, dvc): | ||
num_files = 20 | ||
CODE = dedent( | ||
""" | ||
from random import random | ||
import sys | ||
num_files = {num_files} | ||
linspace_size = 1000 | ||
def load_params(): | ||
import yaml | ||
with open('params.yaml') as fd: | ||
return yaml.safe_load(fd) | ||
params = load_params() | ||
p = params['p'] | ||
def calc_metric(index): | ||
metric = [(i/linspace_size)**p + (random()-0.5)/index | ||
for i in range(1,linspace_size)] | ||
result=[] | ||
for elem in list(metric): | ||
result.append({{f'val_{{index}}': elem}}) | ||
return result | ||
import json | ||
if __name__ == '__main__': | ||
for i in range(1, num_files+1): | ||
metric = calc_metric(i) | ||
with open(f'metric_{{i}}.json', 'w') as fd: | ||
json.dump(metric, fd) | ||
""" | ||
).format(num_files=num_files) | ||
|
||
tmp_dir.gen("train.py", CODE) | ||
tmp_dir.gen("params.yaml", "p: 1") | ||
scm.add(["train.py", "params.yaml"]) | ||
scm.commit("initial") | ||
|
||
dvc.run( | ||
name="generate_plots", | ||
deps=["train.py"], | ||
plots=[f"metric_{i}.json" for i in range(1, num_files + 1)], | ||
params=["p"], | ||
cmd="python train.py", | ||
) | ||
|
||
scm.add(["dvc.lock", "dvc.yaml"]) | ||
scm.commit("initial run, p=1") | ||
|
||
tmp_dir.gen("params.yaml", "p: 3") | ||
dvc.reproduce() | ||
|
||
yield | ||
|
||
|
||
def test_plots_diff(tmp_dir, bench_dvc, repo_with_plots): | ||
bench_dvc("plots", "diff") | ||
|
||
assert (tmp_dir / "dvc_plots" / "index.html").is_file() |