Skip to content

Commit 9aafe94

Browse files
committed
Add dtype assertion to check_array_result for improved result validation
1 parent 5000725 commit 9aafe94

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

cdl/tests/features/images/profile_unit_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# pylint: disable=invalid-name # Allows short reference names like x, y, ...
88
# guitest: show
99

10+
import numpy as np
1011
import pytest
1112
from guidata.qthelpers import exec_dialog, qt_app_context
1213

@@ -70,7 +71,7 @@ def test_line_profile() -> None:
7071
sig = cpi.compute_line_profile(ima, param)
7172
assert sig is not None
7273
assert len(sig.y) == width
73-
exp = ima.data[row, :]
74+
exp = np.array(ima.data[row, :], dtype=float)
7475
check_array_result("Horizontal line profile", sig.y, exp)
7576

7677
# Test vertical line profile
@@ -79,7 +80,7 @@ def test_line_profile() -> None:
7980
sig = cpi.compute_line_profile(ima, param)
8081
assert sig is not None
8182
assert len(sig.y) == height
82-
exp = ima.data[:, col]
83+
exp = np.array(ima.data[:, col], dtype=float)
8384
check_array_result("Vertical line profile", sig.y, exp)
8485

8586

@@ -97,7 +98,7 @@ def test_segment_profile() -> None:
9798
sig = cpi.compute_segment_profile(ima, param)
9899
assert sig is not None
99100
assert len(sig.y) == min(row2, height - 1) - max(row1, 0) + 1
100-
exp = ima.data[10:200, 20]
101+
exp = np.array(ima.data[10:200, 20], dtype=float)
101102
check_array_result("Segment profile", sig.y, exp)
102103

103104

@@ -116,20 +117,20 @@ def test_average_profile() -> None:
116117
sig = cpi.compute_average_profile(ima, param)
117118
assert sig is not None
118119
assert len(sig.y) == col2 - col1 + 1
119-
exp = ima.data[row1 : row2 + 1, col1 : col2 + 1].mean(axis=0)
120+
exp = np.array(ima.data[row1 : row2 + 1, col1 : col2 + 1].mean(axis=0), dtype=float)
120121
check_array_result("Horizontal average profile", sig.y, exp)
121122

122123
# Test vertical average profile
123124
param.direction = "vertical"
124125
sig = cpi.compute_average_profile(ima, param)
125126
assert sig is not None
126127
assert len(sig.y) == min(row2, height - 1) - max(row1, 0) + 1
127-
exp = ima.data[row1 : row2 + 1, col1 : col2 + 1].mean(axis=1)
128+
exp = np.array(ima.data[row1 : row2 + 1, col1 : col2 + 1].mean(axis=1), dtype=float)
128129
check_array_result("Vertical average profile", sig.y, exp)
129130

130131

131132
if __name__ == "__main__":
132-
test_profile_unit()
133+
# test_profile_unit()
133134
test_line_profile()
134135
test_segment_profile()
135136
test_average_profile()

cdl/utils/tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def check_array_result(
283283
restxt = f"{title}: {__array_to_str(res)} (expected: {__array_to_str(exp)})"
284284
execenv.print(restxt)
285285
assert np.allclose(res, exp, rtol=rtol, atol=atol), restxt
286+
assert res.dtype == exp.dtype, restxt
286287

287288

288289
def check_scalar_result(

0 commit comments

Comments
 (0)