Skip to content

Commit 63f2fc3

Browse files
committed
use constants in tests
1 parent db06778 commit 63f2fc3

File tree

5 files changed

+131
-127
lines changed

5 files changed

+131
-127
lines changed

tests/integration/plots/test_plots.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from funcy import first
1212

1313
from dvc.cli import main
14-
from dvc.render import REVISION
14+
from dvc.render import ANCHOR_DEFINITIONS, FILENAME, REVISION
1515

1616
JSON_OUT = "vis_data"
1717

@@ -116,7 +116,7 @@ def verify_vega(
116116

117117
assert (
118118
json_result[0]["content"]["data"]["values"]
119-
== split_json_result[0]["anchor_definitions"]["<DVC_METRIC_DATA>"]
119+
== split_json_result[0][ANCHOR_DEFINITIONS]["<DVC_METRIC_DATA>"]
120120
)
121121

122122
assert set(versions) == set(json_result[0]["revisions"])
@@ -138,10 +138,8 @@ def _assert_templates_equal(
138138
tmp2 = deepcopy(filled_template)
139139
tmp3 = json.loads(
140140
json.dumps(split_template)
141-
.replace('"<DVC_METRIC_COLUMN_WIDTH>"', "300")
142141
.replace('"<DVC_METRIC_PLOT_HEIGHT>"', "300")
143142
.replace('"<DVC_METRIC_PLOT_WIDTH>"', "300")
144-
.replace('"<DVC_METRIC_ROW_HEIGHT>"', "300")
145143
.replace("<DVC_METRIC_TITLE>", title)
146144
.replace("<DVC_METRIC_X_LABEL>", x_label)
147145
.replace("<DVC_METRIC_Y_LABEL>", y_label)
@@ -231,7 +229,7 @@ def test_repo_with_plots(tmp_dir, scm, dvc, capsys, run_copy_metrics, repo_with_
231229
] == _update_datapoints(
232230
linear_v1,
233231
{
234-
"rev": "workspace",
232+
REVISION: "workspace",
235233
},
236234
)
237235
assert html_result["linear.json"]["data"]["values"] == _update_datapoints(
@@ -245,13 +243,13 @@ def test_repo_with_plots(tmp_dir, scm, dvc, capsys, run_copy_metrics, repo_with_
245243
] == _update_datapoints(
246244
confusion_v1,
247245
{
248-
"rev": "workspace",
246+
REVISION: "workspace",
249247
},
250248
)
251249
assert html_result["confusion.json"]["data"]["values"] == _update_datapoints(
252250
confusion_v1,
253251
{
254-
"rev": "workspace",
252+
REVISION: "workspace",
255253
},
256254
)
257255
verify_image(tmp_dir, "workspace", "image.png", image_v1, html_path, json_data)
@@ -319,12 +317,12 @@ def test_repo_with_plots(tmp_dir, scm, dvc, capsys, run_copy_metrics, repo_with_
319317
] == _update_datapoints(
320318
linear_v2,
321319
{
322-
"rev": "workspace",
320+
REVISION: "workspace",
323321
},
324322
) + _update_datapoints(
325323
linear_v1,
326324
{
327-
"rev": "HEAD",
325+
REVISION: "HEAD",
328326
},
329327
)
330328
assert html_result["../linear.json"]["data"]["values"] == _update_datapoints(
@@ -343,12 +341,12 @@ def test_repo_with_plots(tmp_dir, scm, dvc, capsys, run_copy_metrics, repo_with_
343341
] == _update_datapoints(
344342
confusion_v2,
345343
{
346-
"rev": "workspace",
344+
REVISION: "workspace",
347345
},
348346
) + _update_datapoints(
349347
confusion_v1,
350348
{
351-
"rev": "HEAD",
349+
REVISION: "HEAD",
352350
},
353351
)
354352
assert html_result["../confusion.json"]["data"]["values"] == _update_datapoints(
@@ -477,20 +475,20 @@ def test_repo_with_config_plots(tmp_dir, capsys, repo_with_config_plots):
477475
ble = _update_datapoints(
478476
plots["data"]["linear_train.json"],
479477
{
480-
"rev": "workspace",
481-
"filename": "linear_train.json",
478+
REVISION: "workspace",
479+
FILENAME: "linear_train.json",
482480
},
483481
) + _update_datapoints(
484482
plots["data"]["linear_test.json"],
485483
{
486-
"rev": "workspace",
487-
"filename": "linear_test.json",
484+
REVISION: "workspace",
485+
FILENAME: "linear_test.json",
488486
},
489487
)
490488

491489
assert html_result["linear_train_vs_test"]["data"]["values"] == ble
492490
assert (
493-
split_json_result["data"]["linear_train_vs_test"][0]["anchor_definitions"][
491+
split_json_result["data"]["linear_train_vs_test"][0][ANCHOR_DEFINITIONS][
494492
"<DVC_METRIC_DATA>"
495493
]
496494
== ble

tests/unit/render/test_convert.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from dvc.render import ANCHOR_DEFINITIONS, REVISION, REVISIONS, SRC, TYPE_KEY
5+
from dvc.render import ANCHOR_DEFINITIONS, FILENAME, REVISION, REVISIONS, SRC, TYPE_KEY
66
from dvc.render.convert import to_json
77

88

@@ -42,14 +42,14 @@ def test_to_json_vega_split(mocker):
4242
{
4343
"x": 1,
4444
"y": 2,
45-
"rev": "foo",
46-
"filename": "foo.json",
45+
REVISION: "foo",
46+
FILENAME: "foo.json",
4747
},
4848
{
4949
"x": 2,
5050
"y": 1,
51-
"rev": "bar",
52-
"filename": "foo.json",
51+
REVISION: "bar",
52+
FILENAME: "foo.json",
5353
},
5454
],
5555
}

tests/unit/render/test_image_converter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from dvc.render import REVISION, SRC
1+
from dvc.render import FILENAME, REVISION, SRC
22
from dvc.render.converter.image import ImageConverter
33

44

@@ -9,7 +9,7 @@ def test_image_converter_no_out():
99

1010
assert datapoints[0] == {
1111
REVISION: "r",
12-
"filename": "image.png",
12+
FILENAME: "image.png",
1313
SRC: converter._encode_image(b"content"),
1414
}
1515

@@ -22,7 +22,7 @@ def test_image_converter_with_out(tmp_dir):
2222

2323
assert datapoints[0] == {
2424
REVISION: "r",
25-
"filename": "image.png",
25+
FILENAME: "image.png",
2626
SRC: str(tmp_dir / "foo" / "r_image.png"),
2727
}
2828

@@ -38,7 +38,7 @@ def test_image_converter_with_slash_in_revision(tmp_dir):
3838

3939
assert datapoints[0] == {
4040
REVISION: "feature/r",
41-
"filename": "image.png",
41+
FILENAME: "image.png",
4242
SRC: str(tmp_dir / "foo" / "feature_r_image.png"),
4343
}
4444

tests/unit/render/test_match.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import pytest
22
from funcy import set_in
33

4+
from dvc.render import FIELD, FILENAME, REVISION
45
from dvc.render.converter.vega import VegaConverter
5-
from dvc.render.match import PlotsData, _squash_plots_properties, match_defs_renderers
6+
from dvc.render.match import (
7+
PlotsData,
8+
_squash_plots_properties,
9+
match_defs_renderers,
10+
)
611

712

813
@pytest.mark.parametrize(
@@ -157,22 +162,22 @@ def test_match_renderers(M):
157162
renderer = renderer_with_errors[0]
158163
assert renderer.datapoints == [
159164
{
160-
"rev": "v1",
161-
"filename": "file.json",
162-
"field": "y",
165+
REVISION: "v1",
166+
FILENAME: "file.json",
167+
FIELD: "y",
163168
"x": 1,
164169
"y": 1,
165170
},
166171
{
167-
"rev": "v1",
168-
"filename": "file.json",
169-
"field": "y",
172+
REVISION: "v1",
173+
FILENAME: "file.json",
174+
FIELD: "y",
170175
"x": 2,
171176
"y": 2,
172177
},
173178
]
174179
assert renderer.properties == {
175-
"anchors_y_definitions": [{"filename": "file.json", "field": "y"}],
180+
"anchors_y_definitions": [{FILENAME: "file.json", FIELD: "y"}],
176181
"revs_with_datapoints": ["v1"],
177182
"title": "plot_id_1",
178183
"x": "x",

0 commit comments

Comments
 (0)