-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathtest_slide_info.py
148 lines (126 loc) · 3.85 KB
/
test_slide_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""Test for code related to obtaining slide information."""
from pathlib import Path
from click.testing import CliRunner
from tiatoolbox import cli
# -------------------------------------------------------------------------------------
# Command Line Interface
# -------------------------------------------------------------------------------------
def test_command_line_slide_info(sample_all_wsis: Path, tmp_path: Path) -> None:
"""Test the Slide information CLI."""
runner = CliRunner()
slide_info_result = runner.invoke(
cli.main,
[
"slide-info",
"--img-input",
str(Path(sample_all_wsis)),
"--mode",
"save",
"--file-types",
"*.ndpi, *.svs",
"--output-path",
str(tmp_path),
"--verbose",
"True",
],
)
assert slide_info_result.exit_code == 0
assert Path(tmp_path, "CMU-1-Small-Region.yaml").exists()
assert Path(tmp_path, "CMU-1.yaml").exists()
assert not Path(tmp_path, "test1.yaml").exists()
def test_command_line_slide_info_jp2(sample_all_wsis: Path) -> None:
"""Test the Slide information CLI JP2, svs."""
runner = CliRunner()
slide_info_result = runner.invoke(
cli.main,
[
"slide-info",
"--img-input",
str(Path(sample_all_wsis)),
"--mode",
"save",
],
)
output_dir = Path(sample_all_wsis).parent
assert slide_info_result.exit_code == 0
assert Path(output_dir, "meta-data", "CMU-1-Small-Region.yaml").exists()
assert Path(output_dir, "meta-data", "CMU-1.yaml").exists()
assert Path(
output_dir,
"meta-data",
"CMU-1-Small-Region.omnyx.yaml",
).exists()
def test_command_line_slide_info_svs(sample_svs: Path) -> None:
"""Test CLI slide info for single file."""
runner = CliRunner()
slide_info_result = runner.invoke(
cli.main,
[
"slide-info",
"--img-input",
sample_svs,
"--file-types",
"*.ndpi, *.svs",
"--mode",
"show",
"--verbose",
"True",
],
)
assert slide_info_result.exit_code == 0
def test_command_line_slide_info_file_not_found(sample_svs: Path) -> None:
"""Test CLI slide info file not found error."""
runner = CliRunner()
slide_info_result = runner.invoke(
cli.main,
[
"slide-info",
"--img-input",
str(sample_svs)[:-1],
"--file-types",
"*.ndpi, *.svs",
"--mode",
"show",
],
)
assert slide_info_result.output == ""
assert slide_info_result.exit_code == 1
assert isinstance(slide_info_result.exception, FileNotFoundError)
def test_command_line_slide_info_output_none_mode_save(sample_svs: Path) -> None:
"""Test CLI slide info for single file."""
runner = CliRunner()
slide_info_result = runner.invoke(
cli.main,
[
"slide-info",
"--img-input",
str(sample_svs),
"--file-types",
"*.ndpi, *.svs",
"--mode",
"save",
"--verbose",
"False",
],
)
assert slide_info_result.exit_code == 0
assert Path(
sample_svs.parent,
"meta-data",
"CMU-1-Small-Region.yaml",
).exists()
def test_command_line_slide_info_no_input() -> None:
"""Test CLI slide info for single file."""
runner = CliRunner()
slide_info_result = runner.invoke(
cli.main,
[
"slide-info",
"--file-types",
"*.ndpi, *.svs",
"--mode",
"save",
],
)
assert "No image input provided." in slide_info_result.output
assert slide_info_result.exit_code != 0