Skip to content

Commit 52ab482

Browse files
committed
Enhance pixel coordinate test: add support for 'xy' image type and use Literal for type hinting
1 parent 400757c commit 52ab482

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

plotpy/tests/features/test_image_coords.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
# guitest: show
1515

16+
from __future__ import annotations
17+
18+
from typing import Literal
19+
1620
import numpy as np
1721
from guidata.qthelpers import qt_app_context
1822

@@ -22,12 +26,17 @@
2226
from plotpy.tools import DisplayCoordsTool
2327

2428

25-
def test_pixel_coords():
29+
def test_pixel_coords(image_type: Literal["standard", "xy"] = "standard") -> None:
2630
"""Testing image pixel coordinates"""
27-
title = test_pixel_coords.__doc__
31+
title = test_pixel_coords.__doc__ + f" ({image_type} image)"
2832
data = ptd.gen_2d_gaussian(20, np.uint8, x0=-10, y0=-10, mu=7, sigma=10.0)
2933
with qt_app_context(exec_loop=True):
30-
image = make.image(data, interpolation="nearest")
34+
if image_type == "xy":
35+
x = np.linspace(0.0, 10.0, data.shape[1], dtype=float)
36+
y = np.linspace(0.0, 10.0, data.shape[0], dtype=float) ** 2 / 10.0
37+
image = make.xyimage(x, y, data, interpolation="nearest")
38+
else:
39+
image = make.image(data, interpolation="nearest")
3140
text = "First pixel should be centered on (0, 0) coordinates"
3241
label = make.label(text, (1.0, 1.0), (0, 0), "L")
3342
rect = make.rectangle(5.0, 5.0, 10.0, 10.0, "Rectangle")
@@ -42,4 +51,5 @@ def test_pixel_coords():
4251

4352

4453
if __name__ == "__main__":
45-
test_pixel_coords()
54+
test_pixel_coords("standard")
55+
test_pixel_coords("xy")

0 commit comments

Comments
 (0)