11import os
22import shutil
33from pathlib import Path
4- from unittest . mock import Mock
4+ from types import SimpleNamespace
55
66import pytest
77
1212load_image_param = [
1313 # case 1: just filename of file in current directory.
1414 # expect function loads tiff file from cwd
15- ("KFe2As2-00838.tif" , Mock ( fliphorizontal = False , flipvertical = False ), 0 ),
15+ ([ "KFe2As2-00838.tif" , False , False ], [ 0 , 26 , 173 ] ),
1616 # case 2: absolute file path to file in another directory.
1717 # expect file is found and correctly read.
1818 (
19- "home_dir/KFe2As2-00838.tif" ,
20- Mock (fliphorizontal = True , flipvertical = False ),
21- 102 ,
19+ ["home_dir/KFe2As2-00838.tif" , True , False ],
20+ [102 , 57 , 136 ],
2221 ),
2322 # case 3: relative file path to file in another directory.
2423 # expect file is found and correctly read
25- ("./KFe2As2-00838.tif" , Mock ( fliphorizontal = False , flipvertical = True ), 39 ),
24+ ([ "./KFe2As2-00838.tif" , False , True ], [ 39 , 7 , 0 ] ),
2625 # case 4: non-existent file that incurred by mistype.
2726 (
28- "nonexistent_file.tif" ,
29- Mock (fliphorizontal = False , flipvertical = False ),
27+ ["nonexistent_file.tif" , False , False ],
3028 FileNotFoundError ,
3129 ),
30+ # case 5: relative file path to file in another directory.
31+ # expect file to be flip both horizontally and vertically
32+ # and correctly read
33+ (["./KFe2As2-00838.tif" , True , True ], [0 , 53 , 21 ]),
3234]
3335
3436
35- @pytest .mark .parametrize (
36- "file_name, config, expected_entry_value" , load_image_param
37- )
38- def test_load_image (file_name , config , expected_entry_value , user_filesystem ):
37+ @pytest .mark .parametrize ("inputs, expected" , load_image_param )
38+ def test_load_image (inputs , expected , user_filesystem ):
3939 home_dir = user_filesystem ["home" ]
4040 cwd_dir = user_filesystem ["cwd" ]
4141 os .chdir (cwd_dir )
@@ -49,13 +49,15 @@ def test_load_image(file_name, config, expected_entry_value, user_filesystem):
4949 )
5050 shutil .copy (source_file , cwd_dir / "KFe2As2-00838.tif" )
5151 shutil .copy (source_file , home_dir / "KFe2As2-00838.tif" )
52-
52+ config = SimpleNamespace ( fliphorizontal = inputs [ 1 ], flipvertical = inputs [ 2 ])
5353 try :
5454 loader = LoadImage (config )
55- actual = loader .load_image (file_name )
55+ actual = loader .load_image (inputs [ 0 ] )
5656 assert actual .shape == expected_shape
5757 assert actual .mean () == expected_mean
58- assert actual [1 ][0 ] == expected_entry_value
58+ assert actual [1 ][0 ] == expected [0 ]
59+ assert actual [1 ][1 ] == expected [1 ]
60+ assert actual [2 ][5 ] == expected [2 ]
5961 except FileNotFoundError :
6062 pytest .raises (
6163 FileNotFoundError ,
0 commit comments