Skip to content

Commit a9a37ba

Browse files
committed
Added test_builder_image
1 parent 71e4912 commit a9a37ba

File tree

2 files changed

+115
-1
lines changed

2 files changed

+115
-1
lines changed

plotpy/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,7 @@ def xyimage(
17281728
y: numpy.ndarray,
17291729
data: numpy.ndarray,
17301730
title: str | None = None,
1731-
alpha_function: bool | None = None,
1731+
alpha_function: LUTAlpha | None = None,
17321732
alpha: float | None = None,
17331733
background_color: str | None = None,
17341734
colormap: str | None = None,
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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 image factory methods"""
7+
8+
import numpy as np
9+
import pytest
10+
11+
from plotpy.builder import make
12+
from plotpy.styles import LUTAlpha
13+
from plotpy.tests.unit.test_builder_curve import show_item
14+
15+
16+
def _make_image(
17+
alpha_function=None,
18+
xdata=[None, None],
19+
ydata=[None, None],
20+
pixel_size=None,
21+
center_on=None,
22+
interpolation="linear",
23+
background_color=None,
24+
eliminate_outliers=None,
25+
lut_range=None,
26+
lock_position=None,
27+
):
28+
"""Make image"""
29+
data = np.ones((50, 50), dtype=np.uint16)
30+
return make.image(
31+
data,
32+
title="Title",
33+
alpha_function=alpha_function,
34+
alpha=0.5,
35+
xdata=xdata,
36+
ydata=ydata,
37+
pixel_size=pixel_size,
38+
center_on=center_on,
39+
interpolation=interpolation,
40+
background_color=background_color,
41+
colormap="jet",
42+
eliminate_outliers=eliminate_outliers,
43+
xformat="%.1f",
44+
yformat="%.1f",
45+
zformat="%.1f",
46+
lut_range=lut_range,
47+
lock_position=lock_position,
48+
)
49+
50+
51+
@pytest.mark.parametrize(
52+
"alpha_function",
53+
[
54+
None,
55+
LUTAlpha.NONE,
56+
LUTAlpha.CONSTANT,
57+
LUTAlpha.LINEAR,
58+
LUTAlpha.SIGMOID,
59+
LUTAlpha.TANH,
60+
],
61+
)
62+
def test_builder_image_alpha_function(qtbot, alpha_function):
63+
item = _make_image(alpha_function=alpha_function)
64+
show_item(qtbot, item)
65+
66+
67+
@pytest.mark.parametrize(
68+
"xdata,ydata", [[[None, None], [None, None]], [[-10, 10], [-10, 10]]]
69+
)
70+
def test_builder_image_xdata_ydata(qtbot, xdata, ydata):
71+
item = _make_image(xdata=xdata, ydata=ydata)
72+
show_item(qtbot, item)
73+
74+
75+
@pytest.mark.parametrize("pixel_size", [None, 1.0, (1.0, 2.0)])
76+
def test_builder_image_center_on(qtbot, pixel_size):
77+
item = _make_image(pixel_size=pixel_size)
78+
show_item(qtbot, item)
79+
80+
81+
@pytest.mark.parametrize("center_on", [None, [1.0, 3.0]])
82+
def test_builder_image_center_on(qtbot, center_on):
83+
item = _make_image(center_on=center_on)
84+
show_item(qtbot, item)
85+
86+
87+
@pytest.mark.parametrize("interpolation", ["nearest", "linear", "antialiasing"])
88+
def test_builder_image_interpolation(qtbot, interpolation):
89+
item = _make_image(interpolation=interpolation)
90+
show_item(qtbot, item)
91+
92+
93+
@pytest.mark.parametrize("background_color", [None, "red"])
94+
def test_builder_image_center_on(qtbot, background_color):
95+
item = _make_image(background_color=background_color)
96+
show_item(qtbot, item)
97+
98+
99+
@pytest.mark.parametrize("eliminate_outliers", [None, 3.0])
100+
def test_builder_image_center_on(qtbot, eliminate_outliers):
101+
item = _make_image(eliminate_outliers=eliminate_outliers)
102+
show_item(qtbot, item)
103+
104+
105+
@pytest.mark.parametrize("lut_range", [None, [0.0, 100.0]])
106+
def test_builder_image_center_on(qtbot, lut_range):
107+
item = _make_image(lut_range=lut_range)
108+
show_item(qtbot, item)
109+
110+
111+
@pytest.mark.parametrize("lock_position", [None, True, False])
112+
def test_builder_image_center_on(qtbot, lock_position):
113+
item = _make_image(lock_position=lock_position)
114+
show_item(qtbot, item)

0 commit comments

Comments
 (0)