Skip to content

Commit 693f62f

Browse files
committed
Migrate unit tests from cdl to sigima_ (to be continued)
1 parent 6cd707a commit 693f62f

5 files changed

Lines changed: 36 additions & 43 deletions

File tree

cdl/tests/features/common/stat_app_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# guitest: show
1515

1616
from cdl.tests import cdltest_app_context, take_plotwidget_screenshot
17-
from cdl.tests.features.common.stat_unit_test import (
17+
from cdl.tests.sigima_tests.common.stat_unit_test import (
1818
create_reference_image,
1919
create_reference_signal,
2020
)

cdl/tests/features/common/io1_unit_test.py renamed to cdl/tests/sigima_tests/common/io1_unit_test.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,19 @@
33
"""
44
I/O test
55
6-
Testing DataLab specific formats.
6+
Testing `sigima_` specific formats.
77
"""
88

9-
# guitest: show
10-
119
from __future__ import annotations
1210

1311
import numpy as np
1412
from guidata.qthelpers import qt_app_context
1513

16-
from cdl.adapters_plotpy.factories import create_adapter_from_object
17-
from cdl.env import execenv
14+
from sigima_.env import execenv
1815
from sigima_.io import read_images, read_signals
1916
from sigima_.io.image import funcs as image_funcs
2017
from sigima_.obj import ImageObj, SignalObj
21-
from sigima_.tests.helpers import try_open_test_data
22-
from sigima_.tests.vistools import view_curve_items, view_images
18+
from sigima_.tests import helpers, vistools
2319

2420

2521
def __read_objs(fname: str) -> list[ImageObj] | list[SignalObj]:
@@ -34,50 +30,50 @@ def __read_objs(fname: str) -> list[ImageObj] | list[SignalObj]:
3430
return objs
3531

3632

37-
@try_open_test_data("Testing TXT file reader", "*.txt")
33+
@helpers.try_open_test_data("Testing TXT file reader", "*.txt")
3834
def open_txt(fname: str | None = None) -> None:
3935
"""Testing TXT files"""
4036
objs = __read_objs(fname)
4137
for obj in objs:
4238
execenv.print(obj)
43-
view_curve_items([create_adapter_from_object(obj).make_item() for obj in objs])
39+
vistools.view_curves_and_images(objs)
4440

4541

46-
@try_open_test_data("Testing CSV file reader", "*.csv")
42+
@helpers.try_open_test_data("Testing CSV file reader", "*.csv")
4743
def open_csv(fname: str | None = None) -> None:
4844
"""Testing CSV files"""
4945
objs = __read_objs(fname)
5046
for obj in objs:
5147
execenv.print(obj)
52-
view_curve_items([create_adapter_from_object(obj).make_item() for obj in objs])
48+
vistools.view_curves_and_images(objs)
5349

5450

55-
@try_open_test_data("Testing MAT-File reader", "*.mat")
51+
@helpers.try_open_test_data("Testing MAT-File reader", "*.mat")
5652
def open_mat(fname: str | None = None) -> None:
5753
"""Testing MAT files"""
5854
objs = __read_objs(fname)
5955
for obj in objs:
6056
execenv.print(obj)
6157
if isinstance(objs[0], SignalObj):
62-
view_curve_items([create_adapter_from_object(obj).make_item() for obj in objs])
58+
vistools.view_curves(objs)
6359
else:
64-
view_images([obj.data for obj in objs])
60+
vistools.view_images(objs)
6561

6662

67-
@try_open_test_data("Testing SIF file handler", "*.sif")
63+
@helpers.try_open_test_data("Testing SIF file handler", "*.sif")
6864
def open_sif(fname: str | None = None) -> None:
6965
"""Testing SIF files"""
7066
execenv.print(image_funcs.SIFFile(fname))
7167
datalist = image_funcs.imread_sif(fname)
72-
view_images(datalist)
68+
vistools.view_images(datalist)
7369

7470

75-
@try_open_test_data("Testing SCOR-DATA file handler", "*.scor-data")
71+
@helpers.try_open_test_data("Testing SCOR-DATA file handler", "*.scor-data")
7672
def open_scordata(fname: str | None = None) -> None:
7773
"""Testing SCOR-DATA files"""
7874
execenv.print(image_funcs.SCORFile(fname))
7975
data = image_funcs.imread_scor(fname)
80-
view_images(data)
76+
vistools.view_images(data)
8177

8278

8379
def test_io1() -> None:
File renamed without changes.

cdl/tests/features/images/binning_unit_test.py renamed to cdl/tests/sigima_tests/images/binning_unit_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import sigima_.computation.image as sigima_image
2020
import sigima_.param
21-
from cdl.env import execenv
2221
from sigima_.algorithms.image import BINNING_OPERATIONS, binning
22+
from sigima_.env import execenv
2323
from sigima_.tests.data import get_test_image
2424
from sigima_.tests.vistools import view_image_items
2525

cdl/tests/features/images/centroid_unit_test.py renamed to cdl/tests/sigima_tests/images/centroid_unit_test.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,14 @@
2020
import numpy as np
2121
import pytest
2222
import scipy.ndimage as spi
23-
from guidata.qthelpers import qt_app_context
2423
from numpy import ma
25-
from plotpy.builder import make
2624

2725
import sigima_.algorithms.image as alg
2826
import sigima_.computation.image as sigima_image
2927
import sigima_.obj
30-
from cdl.config import _
31-
from cdl.env import execenv
32-
from sigima_.tests.data import (
33-
create_noisygauss_image,
34-
get_laser_spot_data,
35-
)
28+
from sigima_.config import _
29+
from sigima_.env import execenv
30+
from sigima_.tests.data import create_noisygauss_image, get_laser_spot_data
3631
from sigima_.tests.helpers import check_scalar_result
3732
from sigima_.tests.vistools import view_image_items
3833

@@ -57,17 +52,11 @@ def get_centroid_with_cv2(data):
5752
return row, col
5853

5954

60-
def add_xcursor(items, x, y, title):
61-
"""Added X cursor to plot"""
62-
label = " " + f"{_('Centroid')}[{title}] (x=%s, y=%s)"
63-
execenv.print(label % (x, y))
64-
cursor = make.xcursor(x, y, label=label)
65-
cursor.setTitle(title)
66-
items.append(cursor)
67-
68-
69-
def compare_centroid_funcs(data):
55+
def __compare_centroid_funcs(data):
7056
"""Compare centroid methods"""
57+
# pylint: disable=import-outside-toplevel
58+
from plotpy.builder import make
59+
7160
items = []
7261
items += [make.image(data, interpolation="nearest", eliminate_outliers=2.0)]
7362
# Computing centroid coordinates
@@ -79,22 +68,30 @@ def compare_centroid_funcs(data):
7968
):
8069
try:
8170
t0 = time.time()
82-
row, col = func(data)
71+
y, x = func(data)
8372
dt = time.time() - t0
84-
add_xcursor(items, col, row, name)
73+
label = " " + f"{_('Centroid')}[{name}] (x=%s, y=%s)"
74+
execenv.print(label % (x, y))
75+
cursor = make.xcursor(x, y, label=label)
76+
cursor.setTitle(name)
77+
items.append(cursor)
8578
execenv.print(f" Calculation time: {int(dt * 1e3):d} ms")
8679
except ImportError:
8780
execenv.print(f" Unable to compute {name}: missing module")
8881
view_image_items(items)
8982

9083

91-
def test_centroid_graphically():
84+
@pytest.mark.gui
85+
def test_image_centroid_interactive():
9286
"""Centroid test comparing different methods and showing results"""
87+
# pylint: disable=import-outside-toplevel
88+
from guidata.qthelpers import qt_app_context
89+
9390
with qt_app_context():
9491
for data in get_laser_spot_data():
9592
execenv.print(f"Data[dtype={data.dtype},shape={data.shape}]")
9693
# Testing with masked arrays
97-
compare_centroid_funcs(data.view(ma.MaskedArray))
94+
__compare_centroid_funcs(data.view(ma.MaskedArray))
9895

9996

10097
def __check_centroid(image, expected_x, expected_y):
@@ -121,5 +118,5 @@ def test_image_centroid():
121118

122119

123120
if __name__ == "__main__":
124-
test_centroid_graphically()
121+
test_image_centroid_interactive()
125122
test_image_centroid()

0 commit comments

Comments
 (0)