Skip to content

Commit 329c0d6

Browse files
committed
Added unit tests for 'secure_path'
1 parent 38ad910 commit 329c0d6

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/util/test_init.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Test module for the functions located in murfey.util.__init__
3+
"""
4+
5+
from pathlib import Path
6+
7+
import pytest
8+
9+
from murfey.util import secure_path
10+
11+
secure_path_test_matrix = (
12+
# Keep spaces? | Input path | Expected output
13+
# Tomo workflow examples
14+
(
15+
False,
16+
"D:/User_22220202_090000_cm40000-1/Position_1_1_001_0.00_22220202_090000_EER.eer",
17+
"D:/User_22220202_090000_cm40000-1/Position_1_1_001_0.00_22220202_090000_EER.eer",
18+
),
19+
(
20+
False,
21+
"D:/User_22220202_090000_cm40000-1_/Position_1_1_001_0.00_22220202_090000_EER.eer",
22+
"D:/User_22220202_090000_cm40000-1_/Position_1_1_001_0.00_22220202_090000_EER.eer",
23+
),
24+
# CLEM workflow examples
25+
(
26+
True,
27+
"D:/Session/cm40000-1/images/My Sample/TileScan 1/Position 1--Stage00--Z00--C00.tif",
28+
"D:/Session/cm40000-1/images/My Sample/TileScan 1/Position 1--Stage00--Z00--C00.tif",
29+
),
30+
(
31+
True,
32+
"D:/Session/cm40000-1/images/My Sample_/TileScan 1/Position 1--Stage00--Z00--C00.tif",
33+
"D:/Session/cm40000-1/images/My Sample_/TileScan 1/Position 1--Stage00--Z00--C00.tif",
34+
),
35+
(
36+
True,
37+
"D:/Session/cm40000-1/images/My_Sample_/TileScan 1/Position 1--Stage00--Z00--C00.tif",
38+
"D:/Session/cm40000-1/images/My_Sample_/TileScan 1/Position 1--Stage00--Z00--C00.tif",
39+
),
40+
# Go wild
41+
(
42+
True,
43+
"D:/some path/to_/this/repo!/my_file.txt",
44+
"D:/some path/to_/this/repo/my_file.txt",
45+
),
46+
(
47+
True,
48+
"D:/some path__/to_/this/repo/my file.txt",
49+
"D:/some path__/to_/this/repo/my file.txt",
50+
),
51+
(
52+
False,
53+
"D:/some path__/to_/this/repo/my file.txt",
54+
"D:/some_path__/to_/this/repo/my_file.txt",
55+
),
56+
)
57+
58+
59+
@pytest.mark.parametrize("test_params", secure_path_test_matrix)
60+
def test_secure_path(test_params: tuple[bool, str, str]):
61+
# Unpack test params
62+
keep_spaces, input_path, expected_output = test_params
63+
assert secure_path(Path(input_path), keep_spaces) == Path(expected_output)

0 commit comments

Comments
 (0)