-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathtest_save_tiles.py
110 lines (95 loc) · 3.07 KB
/
test_save_tiles.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
"""Test for code related to saving image tiles."""
from pathlib import Path
from click.testing import CliRunner
from tiatoolbox import cli
# -------------------------------------------------------------------------------------
# Command Line Interface
# -------------------------------------------------------------------------------------
def test_command_line_save_tiles(sample_svs_ndpi_wsis: Path, tmp_path: Path) -> None:
"""Test for save_tiles CLI."""
runner = CliRunner()
save_tiles_result = runner.invoke(
cli.main,
[
"save-tiles",
"--img-input",
str(Path(sample_svs_ndpi_wsis)),
"--file-types",
"*.ndpi, *.svs",
"--tile-objective-value",
"5",
"--output-path",
str(tmp_path / "all_tiles"),
],
)
tmp_path = Path(tmp_path)
cmu_small_region = tmp_path / "all_tiles" / "CMU-1-Small-Region.svs"
bioformatspull2759 = tmp_path / "all_tiles" / "bioformatspull2759.ndpi"
assert save_tiles_result.exit_code == 0
assert (cmu_small_region / "Output.csv").exists()
assert (cmu_small_region / "slide_thumbnail.jpg").exists()
assert (cmu_small_region / "Tile_5_0_0.jpg").exists()
assert (bioformatspull2759 / "Output.csv").exists()
assert (bioformatspull2759 / "slide_thumbnail.jpg").exists()
assert (bioformatspull2759 / "Tile_5_0_0.jpg").exists()
def test_command_line_save_tiles_single_file(sample_svs: Path, tmp_path: Path) -> None:
"""Test for save_tiles CLI single file."""
runner = CliRunner()
save_svs_tiles_result = runner.invoke(
cli.main,
[
"save-tiles",
"--img-input",
str(sample_svs),
"--file-types",
"*.ndpi, *.svs",
"--tile-objective-value",
"5",
"--output-path",
tmp_path,
"--verbose",
"True",
],
)
assert save_svs_tiles_result.exit_code == 0
assert (
Path(tmp_path)
.joinpath("CMU-1-Small-Region.svs")
.joinpath("Output.csv")
.exists()
)
assert (
Path(tmp_path)
.joinpath("CMU-1-Small-Region.svs")
.joinpath("slide_thumbnail.jpg")
.exists()
)
assert (
Path(tmp_path)
.joinpath("CMU-1-Small-Region.svs")
.joinpath("Tile_5_0_0.jpg")
.exists()
)
def test_command_line_save_tiles_file_not_found(
sample_svs: Path,
tmp_path: Path,
) -> None:
"""Test for save_tiles CLI file not found error."""
runner = CliRunner()
save_svs_tiles_result = runner.invoke(
cli.main,
[
"save-tiles",
"--img-input",
str(sample_svs)[:-1],
"--file-types",
"*.ndpi, *.svs",
"--tile-objective-value",
"5",
"--output-path",
tmp_path,
],
)
assert save_svs_tiles_result.output == ""
assert save_svs_tiles_result.exit_code == 1
assert isinstance(save_svs_tiles_result.exception, FileNotFoundError)