|
| 1 | +import json |
| 2 | + |
1 | 3 | import pytest
|
2 | 4 |
|
3 | 5 | from dvc_render.vega import BadTemplateError, VegaRenderer
|
@@ -103,11 +105,29 @@ def test_confusion():
|
103 | 105 | assert plot_content["spec"]["encoding"]["y"]["field"] == "actual"
|
104 | 106 |
|
105 | 107 |
|
106 |
| -def test_bad_template(): |
| 108 | +def test_bad_template_on_init(): |
107 | 109 | with pytest.raises(BadTemplateError):
|
108 | 110 | Template("name", "content")
|
109 | 111 |
|
110 | 112 |
|
| 113 | +def test_bad_template_on_missing_data(tmp_dir): |
| 114 | + template_content = {"data": {"values": "BAD_ANCHOR"}} |
| 115 | + tmp_dir.gen("bar.json", json.dumps(template_content)) |
| 116 | + datapoints = [{"val": 2}, {"val": 3}] |
| 117 | + renderer = VegaRenderer(datapoints, "foo", template="bar.json") |
| 118 | + |
| 119 | + with pytest.raises(BadTemplateError): |
| 120 | + renderer.get_filled_template() |
| 121 | + |
| 122 | + template_content = { |
| 123 | + "mark": {"type": "bar"}, |
| 124 | + "data": {"values": Template.anchor("data")}, |
| 125 | + } |
| 126 | + tmp_dir.gen("bar.json", json.dumps(template_content)) |
| 127 | + renderer = VegaRenderer(datapoints, "foo", template="bar.json") |
| 128 | + assert renderer.get_filled_template() |
| 129 | + |
| 130 | + |
111 | 131 | def test_raise_on_wrong_field():
|
112 | 132 | datapoints = [{"val": 2}, {"val": 3}]
|
113 | 133 | props = {"x": "no_val"}
|
|
0 commit comments