Skip to content

Commit b71e9fe

Browse files
committed
Unit tests: added PlotBuilder shape methods
1 parent 38d33a6 commit b71e9fe

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

plotpy/tests/unit/test_builder_annotations.py renamed to plotpy/tests/unit/test_builder_annotation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the terms of the BSD 3-Clause
44
# (see plotpy/LICENSE for details)
55

6-
"""Test PlotBuilder annotations factory methods"""
6+
"""Test PlotBuilder annotation factory methods"""
77

88
import numpy as np
99
import pytest

plotpy/tests/unit/test_builder_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ def _make_image(
3232
title="Title",
3333
alpha_function=alpha_function,
3434
alpha=0.5,
35+
background_color=background_color,
36+
colormap="jet",
3537
xdata=xdata,
3638
ydata=ydata,
3739
pixel_size=pixel_size,
3840
center_on=center_on,
3941
interpolation=interpolation,
40-
background_color=background_color,
41-
colormap="jet",
4242
eliminate_outliers=eliminate_outliers,
4343
xformat="%.1f",
4444
yformat="%.1f",
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the BSD 3-Clause
4+
# (see plotpy/LICENSE for details)
5+
6+
"""Test PlotBuilder shape factory methods"""
7+
8+
import numpy as np
9+
import pytest
10+
11+
from plotpy.builder import make
12+
from plotpy.tests import get_path
13+
from plotpy.tests.unit.test_builder_curve import show_items_qtbot
14+
15+
DEFAULT_ARGS = {
16+
make.segment: [0.0, 0.0, 1.0, 1.0],
17+
make.rectangle: [0.0, 0.0, 1.0, 1.0],
18+
make.circle: [0.0, 0.0, 1.0, 1.0],
19+
make.ellipse: [0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0],
20+
}
21+
22+
23+
def _make_standard_shape(
24+
method,
25+
title: str = None,
26+
):
27+
"""Make annotation"""
28+
args = DEFAULT_ARGS[method]
29+
return method(
30+
*args,
31+
title=title,
32+
)
33+
34+
35+
@pytest.mark.parametrize(
36+
"method",
37+
[make.segment, make.rectangle, make.circle, make.ellipse],
38+
)
39+
def test_builder_standard_shape(qtbot, method):
40+
items = []
41+
items.append(_make_standard_shape(method, title="title"))
42+
show_items_qtbot(qtbot, items)
43+
44+
45+
def test_builder_polygon(qtbot):
46+
items = []
47+
x = np.linspace(0, 1, 10)
48+
y = x**2
49+
for closed in [True, False]:
50+
items.append(make.polygon(x, y, closed=closed, title="title"))
51+
show_items_qtbot(qtbot, items)
52+
53+
54+
def test_builder_svgshape(qtbot):
55+
items = []
56+
svg_path = get_path("svg_target.svg")
57+
with open(svg_path, "rb") as f:
58+
svg_data = f.read()
59+
x = np.linspace(0, 1, 10)
60+
y = x**2
61+
for shape_str in ("circle", "rectangle", "square"):
62+
for data_or_path in (svg_data, svg_path):
63+
items.append(
64+
make.svg(shape_str, data_or_path, 0.0, 0.0, 1.0, 1.0, title="title")
65+
)
66+
show_items_qtbot(qtbot, items)

0 commit comments

Comments
 (0)