11"""Test the loading of spm files."""
22
33from pathlib import Path
4- import pytest
4+ from unittest . mock import patch
55
66import numpy as np
7+ import pySPM
8+ import pytest
79
8- from AFMReader . spm import load_spm
10+ from AFMReader import spm
911
1012BASE_DIR = Path .cwd ()
1113RESOURCES = BASE_DIR / "tests" / "resources"
1214
15+ # pylint: disable=too-many-positional-arguments
16+
1317
1418@pytest .mark .parametrize (
1519 ("file_name" , "channel" , "pixel_to_nm_scaling" , "image_shape" , "image_dtype" , "image_sum" ),
@@ -32,10 +36,37 @@ def test_load_spm(
3236 result_pixel_to_nm_scaling = float
3337
3438 file_path = RESOURCES / file_name
35- result_image , result_pixel_to_nm_scaling = load_spm (file_path , channel = channel )
39+ result_image , result_pixel_to_nm_scaling = spm . load_spm (file_path , channel = channel )
3640
3741 assert result_pixel_to_nm_scaling == pixel_to_nm_scaling
3842 assert isinstance (result_image , np .ndarray )
3943 assert result_image .shape == image_shape
4044 assert result_image .dtype == image_dtype
4145 assert result_image .sum () == image_sum
46+
47+
48+ @patch ("pySPM.SPM.SPM_image.pxs" )
49+ @pytest .mark .parametrize (
50+ ("filename" , "unit" , "x" , "y" , "expected_px2nm" ),
51+ [
52+ pytest .param ("square_mm" , "mm" , 0.01 , 0.01 , 10000 , id = "mm units; square" ),
53+ pytest .param ("square_um" , "um" , 1.5 , 1.5 , 1500 , id = "um units; square" ),
54+ pytest .param ("square_nm" , "nm" , 50 , 50 , 50 , id = "nm units; square" ),
55+ pytest .param ("square_pm" , "pm" , 233 , 233 , 0.233 , id = "pm units; square" ),
56+ pytest .param ("rectangle_thin_pm" , "pm" , 1 , 512 , 0.001 , id = "pm units; rectangular (thin)" ),
57+ pytest .param ("rectangle_tall_pm" , "pm" , 512 , 1 , 0.512 , id = "pm units; rectangular (tall)" ),
58+ ],
59+ )
60+ def test__spm_pixel_to_nm_scaling (
61+ mock_pxs ,
62+ spm_channel_data : pySPM .SPM .SPM_image ,
63+ filename : str ,
64+ unit : str ,
65+ x : int ,
66+ y : int ,
67+ expected_px2nm : float ,
68+ ) -> None :
69+ """Test extraction of pixels to nanometer scaling."""
70+ mock_pxs .return_value = [(x , unit ), (y , unit )] # issue is that pxs is a func that returns the data
71+ result = spm .spm_pixel_to_nm_scaling (filename , spm_channel_data )
72+ assert result == expected_px2nm
0 commit comments