Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💚 Parallel tests #671

Merged
merged 35 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2ab38f6
💚 Add parallel tests
blaginin Jul 19, 2023
05797ef
💚 add pr trigger
blaginin Jul 19, 2023
b414e5d
💚 fix pytest arg
blaginin Jul 19, 2023
b4ed5bc
Merge branch 'dev' into parallel-tests
blaginin Jul 31, 2023
b2b0e73
:white_check_mark: fix fixtures to work in parallel
blaginin Jul 31, 2023
cd1e5e7
:rewind: CI changes
blaginin Jul 31, 2023
905c4da
:hammer: set parallel tests as a default option
blaginin Jul 31, 2023
8d7ae0e
Merge branch 'dev' into parallel-tests
blaginin Jul 31, 2023
fe72af4
💚 Add own folder for .predict( methods
blaginin Jul 31, 2023
0b0da94
:heavy_plus_sign: add pytest-xdist dependency
blaginin Aug 1, 2023
ea39e10
Merge branch 'develop' into parallel-tests
shaneahmed Aug 1, 2023
cec8459
:twisted_rightwards_arrows: merge dev
blaginin Aug 9, 2023
87d43d0
Merge remote-tracking branch 'upstream/parallel-tests' into parallel-…
blaginin Aug 9, 2023
62fc857
:recycle: switched to `Path`
blaginin Aug 9, 2023
dc0ddd4
Merge branch 'develop' into parallel-tests
blaginin Aug 10, 2023
32a1d3f
Merge branch 'develop' into parallel-tests
blaginin Aug 12, 2023
e4fefe2
:recycle: use tmp_path instead of the default directory
blaginin Aug 12, 2023
54f9f6f
Merge remote-tracking branch 'upstream/parallel-tests' into parallel-…
blaginin Aug 12, 2023
d7b50f2
:recycle: add `-n auto` to Makefile
blaginin Aug 12, 2023
370ee2c
:recycle: remove `-n auto` to Makefile
blaginin Aug 12, 2023
34a575c
Merge branch 'develop' into parallel-tests
shaneahmed Aug 14, 2023
3c9fc87
Update tests/models/test_patch_predictor.py
blaginin Aug 17, 2023
021228d
Update tests/models/test_semantic_segmentation.py
blaginin Aug 17, 2023
c46c82e
Update tests/test_utils.py
blaginin Aug 17, 2023
757a36d
Update tests/test_utils.py
blaginin Aug 17, 2023
a48147a
Update tests/test_utils.py
blaginin Aug 17, 2023
48e0d77
Update tests/test_utils.py
blaginin Aug 17, 2023
64f803e
Update tests/test_init.py
blaginin Aug 17, 2023
4ef4ace
Merge branch 'dev' into parallel-tests
blaginin Aug 17, 2023
ac1ab71
Merge branch 'develop' into parallel-tests
shaneahmed Aug 21, 2023
206dde5
Merge branch 'develop' into parallel-tests
blaginin Aug 21, 2023
3ab9886
:recycle: move `chdir` to fixtures
blaginin Aug 23, 2023
168bf77
Merge remote-tracking branch 'upstream/parallel-tests' into parallel-…
blaginin Aug 23, 2023
b5b8a75
Merge branch 'develop' into parallel-tests
blaginin Aug 23, 2023
82e13d7
Merge branch 'develop' into parallel-tests
shaneahmed Aug 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ lint: ## check style with flake8
flake8 tiatoolbox tests

test: ## run tests quickly with the default Python
pytest
pytest -n auto

coverage: ## check code coverage quickly with the default Python
pytest --cov=tiatoolbox --cov-report=term --cov-report=html --cov-report=xml
Expand Down
4 changes: 1 addition & 3 deletions tests/models/test_arch_micronet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
ON_GPU = toolbox_env.has_gpu()


def test_functionality(
remote_sample,
):
def test_functionality(remote_sample):
"""Functionality test."""
sample_wsi = remote_sample("wsi1_2k_2k_svs")
reader = WSIReader.open(sample_wsi)
Expand Down
3 changes: 1 addition & 2 deletions tests/models/test_hovernetplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from tiatoolbox.utils.transforms import imresize


def test_functionality(remote_sample, tmp_path):
def test_functionality(remote_sample):
"""Functionality test."""
tmp_path = str(tmp_path)
sample_patch = str(remote_sample("stainnorm-source"))
patch_pre = imread(sample_patch)
patch_pre = imresize(patch_pre, scale_factor=0.5)
Expand Down
29 changes: 20 additions & 9 deletions tests/models/test_semantic_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# ! The garbage collector
import gc
import multiprocessing
import pathlib
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import pathlib
from pathlib import Path

We are using from pathlib import Path now. It would be good if we use Path from now on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import shutil
from pathlib import Path

Expand Down Expand Up @@ -258,23 +259,25 @@ def test_functional_wsi_stream_dataset(remote_sample):
# -------------------------------------------------------------------------------------


def test_crash_segmentor(remote_sample):
def test_crash_segmentor(remote_sample, tmp_path):
"""Functional crash tests for segmentor."""
# # convert to pathlib Path to prevent wsireader complaint
mini_wsi_svs = Path(remote_sample("wsi2_4k_4k_svs"))
mini_wsi_jpg = Path(remote_sample("wsi2_4k_4k_jpg"))
mini_wsi_msk = Path(remote_sample("wsi2_4k_4k_msk"))

model = _CNNTo1()

save_dir = pathlib.Path(f"{tmp_path}/test_crash_segmentor")
semantic_segmentor = SemanticSegmentor(batch_size=BATCH_SIZE, model=model)

# fake injection to trigger Segmentor to create parallel
# post processing workers because baseline Semantic Segmentor does not support
# post processing out of the box. It only contains condition to create it
# for any subclass
semantic_segmentor.num_postproc_workers = 1

# * test basic crash
_rm_dir("output") # default output dir test
with pytest.raises(TypeError, match=r".*`mask_reader`.*"):
semantic_segmentor.filter_coordinates(mini_wsi_msk, np.array(["a", "b", "c"]))
with pytest.raises(ValueError, match=r".*ndarray.*integer.*"):
Expand All @@ -286,7 +289,7 @@ def test_crash_segmentor(remote_sample):
with pytest.raises(ValueError, match=r".*must be a valid file path.*"):
semantic_segmentor.get_reader(mini_wsi_msk, "not_exist", "wsi", True)

_rm_dir("output") # default output dir test
_rm_dir(save_dir)
with pytest.raises(ValueError, match=r".*provide.*"):
SemanticSegmentor()
with pytest.raises(ValueError, match=r".*valid mode.*"):
Expand All @@ -299,10 +302,16 @@ def test_crash_segmentor(remote_sample):
mode="tile",
on_gpu=ON_GPU,
crash_on_exception=True,
save_dir=save_dir,
)
with pytest.raises(ValueError, match=r".*already exists.*"):
semantic_segmentor.predict([], mode="tile", patch_input_shape=[2048, 2048])
_rm_dir("output") # default output dir test
semantic_segmentor.predict(
[],
mode="tile",
patch_input_shape=[2048, 2048],
save_dir=save_dir,
)
_rm_dir(save_dir)

# * test not providing any io_config info when not using pretrained model
with pytest.raises(ValueError, match=r".*provide either `ioconfig`.*"):
Expand All @@ -311,11 +320,11 @@ def test_crash_segmentor(remote_sample):
mode="tile",
on_gpu=ON_GPU,
crash_on_exception=True,
save_dir=save_dir,
)
_rm_dir("output") # default output dir test
_rm_dir(save_dir)

# * Test crash propagation when parallelize post processing
_rm_dir("output")
semantic_segmentor.num_postproc_workers = 2
semantic_segmentor.model.forward = _crash_func
with pytest.raises(ValueError, match=r"Propagation Crash."):
Expand All @@ -325,17 +334,19 @@ def test_crash_segmentor(remote_sample):
mode="wsi",
on_gpu=ON_GPU,
crash_on_exception=True,
save_dir=save_dir,
)
_rm_dir("output")
_rm_dir(save_dir)

# test ignore crash
semantic_segmentor.predict(
[mini_wsi_svs],
patch_input_shape=[2048, 2048],
mode="wsi",
on_gpu=ON_GPU,
crash_on_exception=False,
save_dir=save_dir,
)
_rm_dir("output")


def test_functional_segmentor_merging(tmp_path):
Expand Down