Skip to content

Commit a12bd2d

Browse files
authored
Merge pull request #155 from AFM-SPM/ns-rse/jpk-qu-image-tests
Merging this small sample without review.
2 parents 794e2d1 + 80a5abb commit a12bd2d

8 files changed

Lines changed: 60 additions & 16 deletions

File tree

284 KB
Binary file not shown.

tests/test_gwy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def test_load_gwy() -> None:
1919
result_image, result_pixel_to_nm_scaling = gwy.load_gwy(file_path, channel=channel)
2020
assert isinstance(result_image, np.ndarray)
2121
assert result_image.shape == (512, 512)
22-
assert result_image.sum() == 33836850.232917726
22+
assert result_image.sum() == pytest.approx(33836850.232917726)
2323
assert isinstance(result_pixel_to_nm_scaling, float)
24-
assert result_pixel_to_nm_scaling == 0.8468632812499975
24+
assert result_pixel_to_nm_scaling == pytest.approx(0.8468632812499975)
2525

2626

2727
def test_gwy_read_object() -> None:

tests/test_ibw.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def test_load_ibw(
3030
file_path = RESOURCES / file_name
3131
result_image, result_pixel_to_nm_scaling = ibw.load_ibw(file_path, channel) # type: ignore
3232

33-
assert result_pixel_to_nm_scaling == pixel_to_nm_scaling
33+
assert result_pixel_to_nm_scaling == pytest.approx(pixel_to_nm_scaling)
3434
assert isinstance(result_image, np.ndarray)
3535
assert result_image.shape == image_shape
3636
assert result_image.dtype == image_dtype
37-
assert result_image.sum() == image_sum
37+
assert result_image.sum() == pytest.approx(image_sum)
3838

3939

4040
def test_load_ibw_file_not_found() -> None:

tests/test_jpk.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,52 @@
1616
[
1717
pytest.param(
1818
"sample_0.jpk", "height_trace", 1.2770176335964876, (256, 256), float, 219242202.8256843, id="test image 0"
19-
)
19+
),
20+
pytest.param(
21+
"sample_0.jpk-qi-image",
22+
"height_trace",
23+
4.999999999999986,
24+
(100, 100),
25+
float,
26+
31593146.16051172,
27+
id="qi-image 0; height_trace",
28+
),
29+
pytest.param(
30+
"sample_0.jpk-qi-image",
31+
"slope_trace",
32+
4.999999999999986,
33+
(100, 100),
34+
float,
35+
626.3810326940231,
36+
id="qi-image 0; slope_trace",
37+
),
38+
pytest.param(
39+
"sample_0.jpk-qi-image",
40+
"adhesion_trace",
41+
4.999999999999986,
42+
(100, 100),
43+
float,
44+
1.579363986493833e-06,
45+
id="qi-image 0; adhesion_trace",
46+
),
47+
pytest.param(
48+
"sample_0.jpk-qi-image",
49+
"measuredHeight_trace",
50+
4.999999999999986,
51+
(100, 100),
52+
float,
53+
32181137.138706185,
54+
id="qi-image 0; measuredHeight_trace",
55+
),
56+
pytest.param(
57+
"sample_0.jpk-qi-image",
58+
"vDeflection_trace",
59+
4.999999999999986,
60+
(100, 100),
61+
float,
62+
-1.3615033224242345e-05,
63+
id="qi-image 0; vDeflection_trace",
64+
),
2065
],
2166
)
2267
def test_load_jpk(
@@ -30,15 +75,14 @@ def test_load_jpk(
3075
"""Test the normal operation of loading a .jpk file."""
3176
result_image = np.ndarray
3277
result_pixel_to_nm_scaling = float
33-
3478
file_path = RESOURCES / file_name
3579
result_image, result_pixel_to_nm_scaling = jpk.load_jpk(file_path, channel) # type: ignore
3680

37-
assert result_pixel_to_nm_scaling == pixel_to_nm_scaling
81+
assert result_pixel_to_nm_scaling == pytest.approx(pixel_to_nm_scaling)
3882
assert isinstance(result_image, np.ndarray)
3983
assert result_image.shape == image_shape
4084
assert result_image.dtype == image_dtype
41-
assert result_image.sum() == image_sum
85+
assert result_image.sum() == pytest.approx(image_sum)
4286

4387

4488
def test_load_jpk_file_not_found() -> None:

tests/test_spm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def test_load_spm(
3939
file_path = RESOURCES / file_name
4040
result_image, result_pixel_to_nm_scaling = spm.load_spm(file_path, channel=channel)
4141

42-
assert result_pixel_to_nm_scaling == pixel_to_nm_scaling
42+
assert result_pixel_to_nm_scaling == pytest.approx(pixel_to_nm_scaling)
4343
assert isinstance(result_image, np.ndarray)
4444
assert result_image.shape == image_shape
4545
assert result_image.dtype == image_dtype
46-
assert result_image.sum() == image_sum
46+
assert result_image.sum() == pytest.approx(image_sum)
4747

4848

4949
@patch("pySPM.SPM.SPM_image.pxs")

tests/test_stp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def test_load_stp(
3232
file_path = RESOURCES / file_name
3333
result_image, result_pixel_to_nm_scaling = load_stp(file_path=file_path)
3434

35-
assert result_pixel_to_nm_scaling == expected_pixel_to_nm_scaling
35+
assert result_pixel_to_nm_scaling == pytest.approx(expected_pixel_to_nm_scaling)
3636
assert isinstance(result_image, np.ndarray)
3737
assert result_image.shape == expected_image_shape
3838
assert result_image.dtype == expected_image_dtype
39-
assert result_image.sum() == expected_image_sum
39+
assert result_image.sum() == pytest.approx(expected_image_sum)

tests/test_top.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def test_load_top(
3232
file_path = RESOURCES / file_name
3333
result_image, result_pixel_to_nm_scaling = load_top(file_path=file_path)
3434

35-
assert result_pixel_to_nm_scaling == expected_pixel_to_nm_scaling
35+
assert result_pixel_to_nm_scaling == pytest.approx(expected_pixel_to_nm_scaling)
3636
assert isinstance(result_image, np.ndarray)
3737
assert result_image.shape == expected_image_shape
3838
assert result_image.dtype == expected_image_dtype
39-
assert result_image.sum() == expected_image_sum
39+
assert result_image.sum() == pytest.approx(expected_image_sum)

tests/test_topostats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def test_load_topostats(
9696
assert topostats_data[version_key] == float(version)
9797
else:
9898
assert topostats_data[version_key] == version
99-
assert topostats_data["pixel_to_nm_scaling"] == pixel_to_nm_scaling
99+
assert topostats_data["pixel_to_nm_scaling"] == pytest.approx(pixel_to_nm_scaling)
100100
assert topostats_data["image"].shape == image_shape
101-
assert topostats_data["image"].sum() == image_sum
101+
assert topostats_data["image"].sum() == pytest.approx(image_sum)
102102
if version >= "0.2":
103103
assert isinstance(topostats_data["img_path"], Path)
104104

0 commit comments

Comments
 (0)