diff --git a/tests/resources/sample_0.jpk-qi-image b/tests/resources/sample_0.jpk-qi-image new file mode 100644 index 0000000..331e9da Binary files /dev/null and b/tests/resources/sample_0.jpk-qi-image differ diff --git a/tests/test_gwy.py b/tests/test_gwy.py index 3a0d21a..21bd562 100644 --- a/tests/test_gwy.py +++ b/tests/test_gwy.py @@ -19,9 +19,9 @@ def test_load_gwy() -> None: result_image, result_pixel_to_nm_scaling = gwy.load_gwy(file_path, channel=channel) assert isinstance(result_image, np.ndarray) assert result_image.shape == (512, 512) - assert result_image.sum() == 33836850.232917726 + assert result_image.sum() == pytest.approx(33836850.232917726) assert isinstance(result_pixel_to_nm_scaling, float) - assert result_pixel_to_nm_scaling == 0.8468632812499975 + assert result_pixel_to_nm_scaling == pytest.approx(0.8468632812499975) def test_gwy_read_object() -> None: diff --git a/tests/test_ibw.py b/tests/test_ibw.py index e03ecf3..ae1330d 100644 --- a/tests/test_ibw.py +++ b/tests/test_ibw.py @@ -30,11 +30,11 @@ def test_load_ibw( file_path = RESOURCES / file_name result_image, result_pixel_to_nm_scaling = ibw.load_ibw(file_path, channel) # type: ignore - assert result_pixel_to_nm_scaling == pixel_to_nm_scaling + assert result_pixel_to_nm_scaling == pytest.approx(pixel_to_nm_scaling) assert isinstance(result_image, np.ndarray) assert result_image.shape == image_shape assert result_image.dtype == image_dtype - assert result_image.sum() == image_sum + assert result_image.sum() == pytest.approx(image_sum) def test_load_ibw_file_not_found() -> None: diff --git a/tests/test_jpk.py b/tests/test_jpk.py index 4e0011d..5346a22 100644 --- a/tests/test_jpk.py +++ b/tests/test_jpk.py @@ -16,7 +16,52 @@ [ pytest.param( "sample_0.jpk", "height_trace", 1.2770176335964876, (256, 256), float, 219242202.8256843, id="test image 0" - ) + ), + pytest.param( + "sample_0.jpk-qi-image", + "height_trace", + 4.999999999999986, + (100, 100), + float, + 31593146.16051172, + id="qi-image 0; height_trace", + ), + pytest.param( + "sample_0.jpk-qi-image", + "slope_trace", + 4.999999999999986, + (100, 100), + float, + 626.3810326940231, + id="qi-image 0; slope_trace", + ), + pytest.param( + "sample_0.jpk-qi-image", + "adhesion_trace", + 4.999999999999986, + (100, 100), + float, + 1.579363986493833e-06, + id="qi-image 0; adhesion_trace", + ), + pytest.param( + "sample_0.jpk-qi-image", + "measuredHeight_trace", + 4.999999999999986, + (100, 100), + float, + 32181137.138706185, + id="qi-image 0; measuredHeight_trace", + ), + pytest.param( + "sample_0.jpk-qi-image", + "vDeflection_trace", + 4.999999999999986, + (100, 100), + float, + -1.3615033224242345e-05, + id="qi-image 0; vDeflection_trace", + ), ], ) def test_load_jpk( @@ -30,15 +75,14 @@ def test_load_jpk( """Test the normal operation of loading a .jpk file.""" result_image = np.ndarray result_pixel_to_nm_scaling = float - file_path = RESOURCES / file_name result_image, result_pixel_to_nm_scaling = jpk.load_jpk(file_path, channel) # type: ignore - assert result_pixel_to_nm_scaling == pixel_to_nm_scaling + assert result_pixel_to_nm_scaling == pytest.approx(pixel_to_nm_scaling) assert isinstance(result_image, np.ndarray) assert result_image.shape == image_shape assert result_image.dtype == image_dtype - assert result_image.sum() == image_sum + assert result_image.sum() == pytest.approx(image_sum) def test_load_jpk_file_not_found() -> None: diff --git a/tests/test_spm.py b/tests/test_spm.py index 0d9cde7..b6097f4 100644 --- a/tests/test_spm.py +++ b/tests/test_spm.py @@ -39,11 +39,11 @@ def test_load_spm( file_path = RESOURCES / file_name result_image, result_pixel_to_nm_scaling = spm.load_spm(file_path, channel=channel) - assert result_pixel_to_nm_scaling == pixel_to_nm_scaling + assert result_pixel_to_nm_scaling == pytest.approx(pixel_to_nm_scaling) assert isinstance(result_image, np.ndarray) assert result_image.shape == image_shape assert result_image.dtype == image_dtype - assert result_image.sum() == image_sum + assert result_image.sum() == pytest.approx(image_sum) @patch("pySPM.SPM.SPM_image.pxs") diff --git a/tests/test_stp.py b/tests/test_stp.py index 897c365..ae7b187 100644 --- a/tests/test_stp.py +++ b/tests/test_stp.py @@ -32,8 +32,8 @@ def test_load_stp( file_path = RESOURCES / file_name result_image, result_pixel_to_nm_scaling = load_stp(file_path=file_path) - assert result_pixel_to_nm_scaling == expected_pixel_to_nm_scaling + assert result_pixel_to_nm_scaling == pytest.approx(expected_pixel_to_nm_scaling) assert isinstance(result_image, np.ndarray) assert result_image.shape == expected_image_shape assert result_image.dtype == expected_image_dtype - assert result_image.sum() == expected_image_sum + assert result_image.sum() == pytest.approx(expected_image_sum) diff --git a/tests/test_top.py b/tests/test_top.py index 6eef2bf..86fed76 100644 --- a/tests/test_top.py +++ b/tests/test_top.py @@ -32,8 +32,8 @@ def test_load_top( file_path = RESOURCES / file_name result_image, result_pixel_to_nm_scaling = load_top(file_path=file_path) - assert result_pixel_to_nm_scaling == expected_pixel_to_nm_scaling + assert result_pixel_to_nm_scaling == pytest.approx(expected_pixel_to_nm_scaling) assert isinstance(result_image, np.ndarray) assert result_image.shape == expected_image_shape assert result_image.dtype == expected_image_dtype - assert result_image.sum() == expected_image_sum + assert result_image.sum() == pytest.approx(expected_image_sum) diff --git a/tests/test_topostats.py b/tests/test_topostats.py index f6913c0..78be6c1 100644 --- a/tests/test_topostats.py +++ b/tests/test_topostats.py @@ -96,9 +96,9 @@ def test_load_topostats( assert topostats_data[version_key] == float(version) else: assert topostats_data[version_key] == version - assert topostats_data["pixel_to_nm_scaling"] == pixel_to_nm_scaling + assert topostats_data["pixel_to_nm_scaling"] == pytest.approx(pixel_to_nm_scaling) assert topostats_data["image"].shape == image_shape - assert topostats_data["image"].sum() == image_sum + assert topostats_data["image"].sum() == pytest.approx(image_sum) if version >= "0.2": assert isinstance(topostats_data["img_path"], Path)