Skip to content

Commit 80a5abb

Browse files
committed
tests: Use pytest.approx() in float comparisons
Tests were failing, hopefully this fixes that by using `pytest.approx()`.
1 parent 92756bd commit 80a5abb

7 files changed

Lines changed: 14 additions & 14 deletions

File tree

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ def test_load_jpk(
7878
file_path = RESOURCES / file_name
7979
result_image, result_pixel_to_nm_scaling = jpk.load_jpk(file_path, channel) # type: ignore
8080

81-
assert result_pixel_to_nm_scaling == pixel_to_nm_scaling
81+
assert result_pixel_to_nm_scaling == pytest.approx(pixel_to_nm_scaling)
8282
assert isinstance(result_image, np.ndarray)
8383
assert result_image.shape == image_shape
8484
assert result_image.dtype == image_dtype
85-
assert result_image.sum() == image_sum
85+
assert result_image.sum() == pytest.approx(image_sum)
8686

8787

8888
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)