|
20 | 20 | NoFieldInDataError,
|
21 | 21 | TemplateNotFoundError,
|
22 | 22 | )
|
| 23 | +from dvc.utils.fs import remove |
23 | 24 | from dvc.utils.serialize import dump_yaml, dumps_yaml
|
24 | 25 |
|
25 | 26 |
|
@@ -342,6 +343,38 @@ def test_plot_even_if_metric_missing(
|
342 | 343 | assert plot_content["encoding"]["y"]["field"] == "y"
|
343 | 344 |
|
344 | 345 |
|
| 346 | +def test_plot_cache_missing(tmp_dir, scm, dvc, caplog, run_copy_metrics): |
| 347 | + metric = [{"y": 2}, {"y": 3}] |
| 348 | + _write_json(tmp_dir, metric, "metric_t.json") |
| 349 | + stage = run_copy_metrics( |
| 350 | + "metric_t.json", |
| 351 | + "metric.json", |
| 352 | + plots=["metric.json"], |
| 353 | + commit="there is metric", |
| 354 | + ) |
| 355 | + scm.tag("v1") |
| 356 | + |
| 357 | + # Make a different plot and then remove its datafile |
| 358 | + metric = [{"y": 3}, {"y": 4}] |
| 359 | + _write_json(tmp_dir, metric, "metric_t.json") |
| 360 | + stage = run_copy_metrics( |
| 361 | + "metric_t.json", |
| 362 | + "metric.json", |
| 363 | + plots=["metric.json"], |
| 364 | + commit="there is an another metric", |
| 365 | + ) |
| 366 | + scm.tag("v2") |
| 367 | + remove(stage.outs[0].fspath) |
| 368 | + remove(stage.outs[0].cache_path) |
| 369 | + |
| 370 | + plots = dvc.plots.show(revs=["v1", "v2"], targets=["metric.json"]) |
| 371 | + plot_content = json.loads(plots["metric.json"]) |
| 372 | + assert plot_content["data"]["values"] == [ |
| 373 | + {"y": 2, PlotData.INDEX_FIELD: 0, "rev": "v1"}, |
| 374 | + {"y": 3, PlotData.INDEX_FIELD: 1, "rev": "v1"}, |
| 375 | + ] |
| 376 | + |
| 377 | + |
345 | 378 | def test_throw_on_no_metric_at_all(tmp_dir, scm, dvc, caplog):
|
346 | 379 | tmp_dir.scm_gen("some_file", "content", commit="there is no metric")
|
347 | 380 | scm.tag("v1")
|
|
0 commit comments