Skip to content

Commit 02747bb

Browse files
author
shaneahmed
committed
BUG: Update test_tiatoolbox.py to fix pytest errors
Update test_tiatoolbox.py to fix pytest errors Add test for slide_info feature
1 parent 1ba8c42 commit 02747bb

File tree

2 files changed

+58
-13
lines changed

2 files changed

+58
-13
lines changed

tests/test_tiatoolbox.py

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,82 @@
11
#!/usr/bin/env python
22

33
"""Tests for `tiatoolbox` package."""
4-
54
import pytest
65

7-
from click.testing import CliRunner
8-
9-
from tiatoolbox import tiatoolbox
6+
from tiatoolbox.dataloader.slide_info import slide_info
7+
from tiatoolbox.utils import misc_utils as misc
108
from tiatoolbox import cli
119

10+
from click.testing import CliRunner
11+
import requests
12+
import os
13+
import pathlib
14+
1215

1316
@pytest.fixture
14-
def response():
15-
"""Sample pytest fixture.
17+
def response_ndpi():
18+
"""Sample pytest fixture for ndpi images.
1619
1720
See more at: http://doc.pytest.org/en/latest/fixture.html
1821
"""
19-
# import requests
20-
# return requests.get('https://github.com/audreyr/cookiecutter-pypackage')
22+
if not os.path.isfile("./CMU-1.ndpi"):
23+
r = requests.get(
24+
"http://openslide.cs.cmu.edu/download/openslide-testdata/Hamamatsu/CMU-1.ndpi"
25+
)
26+
with open("./CMU-1.ndpi", "wb") as f:
27+
f.write(r.content)
28+
29+
30+
@pytest.fixture
31+
def response_svs():
32+
"""Sample pytest fixture for svs images.
33+
34+
See more at: http://doc.pytest.org/en/latest/fixture.html
35+
"""
36+
if not os.path.isfile("./CMU-1.svs"):
37+
r = requests.get(
38+
"http://openslide.cs.cmu.edu/download/openslide-testdata/Aperio/CMU-1.svs"
39+
)
40+
with open("./CMU-1.svs", "wb") as f:
41+
f.write(r.content)
2142

2243

23-
def test_content(response):
44+
def test_content(response_ndpi, response_svs):
2445
"""Sample pytest test function with the pytest fixture as an argument."""
2546
# from bs4 import BeautifulSoup
2647
# assert 'GitHub' in BeautifulSoup(response.content).title.string
48+
file_types = ("*.ndpi", "*.svs", "*.mrxs")
49+
files_all = misc.grab_files_from_dir(
50+
input_path=str(pathlib.Path(r".")), file_types=file_types,
51+
)
52+
_ = slide_info(input_path=files_all, workers=2, mode="save")
2753

2854

29-
def test_command_line_interface():
55+
def test_command_line_help_interface():
3056
"""Test the CLI."""
3157
runner = CliRunner()
3258
result = runner.invoke(cli.main)
3359
assert result.exit_code == 0
34-
assert "tiatoolbox.cli.main" in result.output
3560
help_result = runner.invoke(cli.main, ["--help"])
3661
assert help_result.exit_code == 0
37-
assert "--help Show this message and exit." in help_result.output
62+
assert help_result.output == result.output
63+
64+
65+
def test_command_line_slide_info():
66+
"""Test the Slide infor CLI."""
67+
runner = CliRunner()
68+
slide_info_result = runner.invoke(
69+
cli.main,
70+
[
71+
"slide-info",
72+
"--wsi_input",
73+
".",
74+
"--file_types",
75+
'"*.ndpi, *.svs"',
76+
"--mode",
77+
"show",
78+
"--workers",
79+
"2",
80+
],
81+
)
82+
assert slide_info_result.exit_code == 0

tiatoolbox/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@click.group(context_settings=dict(help_option_names=["-h", "--help"]))
1010
def main():
1111
"""
12-
Computational pathology toolbox designed by TIALAB.
12+
Computational pathology toolbox developed by TIALAB
1313
"""
1414
return 0
1515

0 commit comments

Comments
 (0)