Skip to content

Commit 523006c

Browse files
committed
Added test_builder_annotations
1 parent f2b1060 commit 523006c

File tree

3 files changed

+107
-18
lines changed

3 files changed

+107
-18
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 annotations factory methods"""
7+
8+
import numpy as np
9+
import pytest
10+
11+
from plotpy.builder import make
12+
from plotpy.tests.unit.test_builder_curve import show_items_qtbot
13+
14+
DEFAULT_ARGS = {
15+
make.annotated_point: [0.0, 0.0],
16+
make.annotated_segment: [0.0, 0.0, 1.0, 1.0],
17+
make.annotated_rectangle: [0.0, 0.0, 1.0, 1.0],
18+
make.annotated_circle: [0.0, 0.0, 1.0, 1.0],
19+
make.annotated_ellipse: [0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0],
20+
}
21+
22+
23+
def _make_annotation(
24+
method,
25+
title: str = None,
26+
subtitle: str = None,
27+
show_label: bool = None,
28+
show_computations: bool = None,
29+
show_subtitle: bool = None,
30+
format: str = None,
31+
uncertainty: float = None,
32+
transform_matrix: np.ndarray = None,
33+
readonly: bool = None,
34+
private: bool = None,
35+
):
36+
"""Make annotation"""
37+
args = DEFAULT_ARGS[method]
38+
return method(
39+
*args,
40+
title=title,
41+
subtitle=subtitle,
42+
show_label=show_label,
43+
show_computations=show_computations,
44+
show_subtitle=show_subtitle,
45+
format=format,
46+
uncertainty=uncertainty,
47+
transform_matrix=transform_matrix,
48+
readonly=readonly,
49+
private=private,
50+
)
51+
52+
53+
@pytest.mark.parametrize(
54+
"method",
55+
[
56+
make.annotated_point,
57+
make.annotated_segment,
58+
make.annotated_rectangle,
59+
make.annotated_circle,
60+
make.annotated_ellipse,
61+
],
62+
)
63+
def test_builder_annotation_params(qtbot, method):
64+
items = []
65+
for show_label in [True, False]:
66+
items.append(
67+
_make_annotation(
68+
method,
69+
title="title",
70+
subtitle="subtitle",
71+
show_label=show_label,
72+
)
73+
)
74+
for show_computations in [True, False]:
75+
items.append(_make_annotation(method, show_computations=show_computations))
76+
for show_subtitle in [True, False]:
77+
items.append(_make_annotation(method, show_subtitle=show_subtitle))
78+
for format in ["%f", "%e"]:
79+
items.append(_make_annotation(method, format=format))
80+
for uncertainty in [0.0, 1.0]:
81+
items.append(_make_annotation(method, uncertainty=uncertainty))
82+
for transform_matrix in [None, np.identity(3)]:
83+
items.append(_make_annotation(method, transform_matrix=transform_matrix))
84+
for readonly in [True, False]:
85+
items.append(_make_annotation(method, readonly=readonly))
86+
for private in [True, False]:
87+
items.append(_make_annotation(method, private=private))
88+
show_items_qtbot(qtbot, items)

plotpy/tests/unit/test_builder_curve.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
from plotpy.builder import make
1414

1515

16-
def show_item(qtbot, item, type="curve"):
16+
def show_items_qtbot(qtbot, items, type="curve"):
1717
"""Plot curve in a dialog"""
1818
win = make.dialog(type=type)
1919
plot = win.manager.get_plot()
20-
plot.add_item(item)
20+
for item in items:
21+
plot.add_item(item)
2122
win.show()
2223
qtbot.keyClick(win, Qt.Key_Enter)
2324

@@ -43,7 +44,7 @@ def _make_curve_style(shade, curvestyle, baseline):
4344
def test_builder_curve_curve_style(qtbot, shade, curvestyle, baseline):
4445
"""Test curve parameters of curve() method"""
4546
curve = _make_curve_style(shade, curvestyle, baseline)
46-
show_item(qtbot, curve, "curve")
47+
show_items_qtbot(qtbot, [curve], "curve")
4748

4849

4950
@pytest.mark.parametrize("shade", [0, 0.4, 1.0])
@@ -52,7 +53,7 @@ def test_builder_curve_curve_style(qtbot, shade, curvestyle, baseline):
5253
def test_builder_curve_curve_shade_baseline(qtbot, shade, curvestyle, baseline):
5354
"""Test curve parameters of curve() method"""
5455
curve = _make_curve_style(shade, curvestyle, baseline)
55-
show_item(qtbot, curve, "curve")
56+
show_items_qtbot(qtbot, [curve], "curve")
5657

5758

5859
def _make_curve_linestyle(color, linestyle, linewidth):
@@ -76,7 +77,7 @@ def _make_curve_linestyle(color, linestyle, linewidth):
7677
def test_builder_curve_line_style(qtbot, color, linestyle, linewidth):
7778
"""Test line parameters of curve() method"""
7879
curve = _make_curve_linestyle(color, linestyle, linewidth)
79-
show_item(qtbot, curve, "curve")
80+
show_items_qtbot(qtbot, [curve], "curve")
8081

8182

8283
@pytest.mark.parametrize("color", ["red", "blue"])
@@ -85,7 +86,7 @@ def test_builder_curve_line_style(qtbot, color, linestyle, linewidth):
8586
def test_builder_curve_line_color(qtbot, color, linestyle, linewidth):
8687
"""Test line parameters of curve() method"""
8788
curve = _make_curve_linestyle(color, linestyle, linewidth)
88-
show_item(qtbot, curve, "curve")
89+
show_items_qtbot(qtbot, [curve], "curve")
8990

9091

9192
def _make_curve_marker(marker, markersize, markerfacecolor, markeredgecolor):
@@ -134,7 +135,7 @@ def test_builder_curve_marker_params_symbol(
134135
):
135136
"""Test marker parameters of curve() methodg"""
136137
curve = _make_curve_marker(marker, markersize, markerfacecolor, markeredgecolor)
137-
show_item(qtbot, curve, "curve")
138+
show_items_qtbot(qtbot, [curve], "curve")
138139

139140

140141
@pytest.mark.parametrize("marker", ["Cross"])
@@ -146,4 +147,4 @@ def test_builder_curve_marker_size_color(
146147
):
147148
"""Test marker parameters of curve() methodg"""
148149
curve = _make_curve_marker(marker, markersize, markerfacecolor, markeredgecolor)
149-
show_item(qtbot, curve, "curve")
150+
show_items_qtbot(qtbot, [curve], "curve")

plotpy/tests/unit/test_builder_image.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from plotpy.builder import make
1212
from plotpy.styles import LUTAlpha
13-
from plotpy.tests.unit.test_builder_curve import show_item
13+
from plotpy.tests.unit.test_builder_curve import show_items_qtbot
1414

1515

1616
def _make_image(
@@ -61,54 +61,54 @@ def _make_image(
6161
)
6262
def test_builder_image_alpha_function(qtbot, alpha_function):
6363
item = _make_image(alpha_function=alpha_function)
64-
show_item(qtbot, item)
64+
show_items_qtbot(qtbot, [item])
6565

6666

6767
@pytest.mark.parametrize(
6868
"xdata,ydata", [[[None, None], [None, None]], [[-10, 10], [-10, 10]]]
6969
)
7070
def test_builder_image_xdata_ydata(qtbot, xdata, ydata):
7171
item = _make_image(xdata=xdata, ydata=ydata)
72-
show_item(qtbot, item)
72+
show_items_qtbot(qtbot, [item])
7373

7474

7575
@pytest.mark.parametrize("pixel_size", [None, 1.0, (1.0, 2.0)])
7676
def test_builder_image_center_on(qtbot, pixel_size):
7777
item = _make_image(pixel_size=pixel_size)
78-
show_item(qtbot, item)
78+
show_items_qtbot(qtbot, [item])
7979

8080

8181
@pytest.mark.parametrize("center_on", [None, [1.0, 3.0]])
8282
def test_builder_image_center_on(qtbot, center_on):
8383
item = _make_image(center_on=center_on)
84-
show_item(qtbot, item)
84+
show_items_qtbot(qtbot, [item])
8585

8686

8787
@pytest.mark.parametrize("interpolation", ["nearest", "linear", "antialiasing"])
8888
def test_builder_image_interpolation(qtbot, interpolation):
8989
item = _make_image(interpolation=interpolation)
90-
show_item(qtbot, item)
90+
show_items_qtbot(qtbot, [item])
9191

9292

9393
@pytest.mark.parametrize("background_color", [None, "red"])
9494
def test_builder_image_center_on(qtbot, background_color):
9595
item = _make_image(background_color=background_color)
96-
show_item(qtbot, item)
96+
show_items_qtbot(qtbot, [item])
9797

9898

9999
@pytest.mark.parametrize("eliminate_outliers", [None, 3.0])
100100
def test_builder_image_center_on(qtbot, eliminate_outliers):
101101
item = _make_image(eliminate_outliers=eliminate_outliers)
102-
show_item(qtbot, item)
102+
show_items_qtbot(qtbot, [item])
103103

104104

105105
@pytest.mark.parametrize("lut_range", [None, [0.0, 100.0]])
106106
def test_builder_image_center_on(qtbot, lut_range):
107107
item = _make_image(lut_range=lut_range)
108-
show_item(qtbot, item)
108+
show_items_qtbot(qtbot, [item])
109109

110110

111111
@pytest.mark.parametrize("lock_position", [None, True, False])
112112
def test_builder_image_center_on(qtbot, lock_position):
113113
item = _make_image(lock_position=lock_position)
114-
show_item(qtbot, item)
114+
show_items_qtbot(qtbot, [item])

0 commit comments

Comments
 (0)