Skip to content

Commit ac7ece7

Browse files
committed
test: add test for flip_image mechanism.
1 parent 556e141 commit ac7ece7

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

tests/test_load_image.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,36 @@
1212
load_image_param = [
1313
# case 1: just filename of file in current directory.
1414
# expect function loads tiff file from cwd
15-
"KFe2As2-00838.tif",
15+
("KFe2As2-00838.tif", Mock(fliphorizontal=False, flipvertical=False), 0),
1616
# case 2: absolute file path to file in another directory.
1717
# expect file is found and correctly read.
18-
"home_dir/KFe2As2-00838.tif",
18+
(
19+
"home_dir/KFe2As2-00838.tif",
20+
Mock(fliphorizontal=True, flipvertical=False),
21+
102,
22+
),
1923
# case 3: relative file path to file in another directory.
2024
# expect file is found and correctly read
21-
"./KFe2As2-00838.tif",
25+
("./KFe2As2-00838.tif", Mock(fliphorizontal=False, flipvertical=True), 39),
2226
# case 4: non-existent file that incurred by mistype.
23-
"nonexistent_file.tif",
27+
(
28+
"nonexistent_file.tif",
29+
Mock(fliphorizontal=False, flipvertical=False),
30+
FileNotFoundError,
31+
),
2432
]
2533

2634

27-
@pytest.mark.parametrize("file_name", load_image_param)
28-
def test_load_image(file_name, user_filesystem):
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):
2939
home_dir = user_filesystem["home"]
3040
cwd_dir = user_filesystem["cwd"]
3141
os.chdir(cwd_dir)
3242

33-
# These values were obtained from docs/examples/data/KFe2As2-00838.tif
3443
expected_mean = 2595.7087
3544
expected_shape = (2048, 2048)
36-
expected_first_point = 0
37-
expected_last_point = 0
3845

3946
# locate source example file inside project docs
4047
source_file = (
@@ -44,12 +51,11 @@ def test_load_image(file_name, user_filesystem):
4451
shutil.copy(source_file, home_dir / "KFe2As2-00838.tif")
4552

4653
try:
47-
loader = LoadImage(Mock(fliphorizontal=False, flipvertical=False))
54+
loader = LoadImage(config)
4855
actual = loader.load_image(file_name)
4956
assert actual.shape == expected_shape
5057
assert actual.mean() == expected_mean
51-
assert actual[0][0] == expected_first_point
52-
assert actual[-1][-1] == expected_last_point
58+
assert actual[1][0] == expected_entry_value
5359
except FileNotFoundError:
5460
pytest.raises(
5561
FileNotFoundError,

0 commit comments

Comments
 (0)