|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | 3 | """Tests for `tiatoolbox` package.""" |
4 | | - |
5 | 4 | import pytest |
6 | 5 |
|
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 |
10 | 8 | from tiatoolbox import cli |
11 | 9 |
|
| 10 | +from click.testing import CliRunner |
| 11 | +import requests |
| 12 | +import os |
| 13 | +import pathlib |
| 14 | + |
12 | 15 |
|
13 | 16 | @pytest.fixture |
14 | | -def response(): |
15 | | - """Sample pytest fixture. |
| 17 | +def response_ndpi(): |
| 18 | + """Sample pytest fixture for ndpi images. |
16 | 19 |
|
17 | 20 | See more at: http://doc.pytest.org/en/latest/fixture.html |
18 | 21 | """ |
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) |
21 | 42 |
|
22 | 43 |
|
23 | | -def test_content(response): |
| 44 | +def test_content(response_ndpi, response_svs): |
24 | 45 | """Sample pytest test function with the pytest fixture as an argument.""" |
25 | 46 | # from bs4 import BeautifulSoup |
26 | 47 | # 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") |
27 | 53 |
|
28 | 54 |
|
29 | | -def test_command_line_interface(): |
| 55 | +def test_command_line_help_interface(): |
30 | 56 | """Test the CLI.""" |
31 | 57 | runner = CliRunner() |
32 | 58 | result = runner.invoke(cli.main) |
33 | 59 | assert result.exit_code == 0 |
34 | | - assert "tiatoolbox.cli.main" in result.output |
35 | 60 | help_result = runner.invoke(cli.main, ["--help"]) |
36 | 61 | 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 |
0 commit comments