-
Notifications
You must be signed in to change notification settings - Fork 19
Fix user-facing API bugs #175
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
Open
MarcelRosier
wants to merge
3
commits into
main
Choose a base branch
from
163-fix-user-facing-api-bugs-preprocessing-missingmri-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,4 +13,4 @@ | |
| PediatricSegmenter, | ||
| ) | ||
|
|
||
| logger.remove() | ||
| logger.disable("brats") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import importlib | ||
| import sys | ||
| from contextlib import ExitStack | ||
| from types import ModuleType | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
| from brats.constants import ( | ||
| AdultGliomaPreAndPostTreatmentAlgorithms, | ||
| AdultGliomaPreTreatmentAlgorithms, | ||
| AfricaAlgorithms, | ||
| GoATAlgorithms, | ||
| InpaintingAlgorithms, | ||
| MeningiomaAlgorithms, | ||
| MeningiomaRTAlgorithms, | ||
| MetastasesAlgorithms, | ||
| MissingMRIAlgorithms, | ||
| PediatricAlgorithms, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def preprocessing_module(monkeypatch): | ||
| """Import preprocessing with a lightweight fake optional dependency.""" | ||
| brainles_preprocessing = ModuleType("brainles_preprocessing") | ||
| constants = ModuleType("brainles_preprocessing.constants") | ||
| modality = ModuleType("brainles_preprocessing.modality") | ||
| normalization = ModuleType("brainles_preprocessing.normalization") | ||
| preprocessor = ModuleType("brainles_preprocessing.preprocessor") | ||
|
|
||
| class Atlas: | ||
| BRATS_MNI152 = "MNI152" | ||
| BRATS_SRI24 = "SRI24" | ||
|
|
||
| class CenterModality: | ||
| pass | ||
|
|
||
| class Modality: | ||
| pass | ||
|
|
||
| class Normalizer: | ||
| pass | ||
|
|
||
| class AtlasCentricPreprocessor: | ||
| pass | ||
|
|
||
| class NativeSpacePreprocessor: | ||
| pass | ||
|
|
||
| constants.Atlas = Atlas | ||
| modality.CenterModality = CenterModality | ||
| modality.Modality = Modality | ||
| normalization.Normalizer = Normalizer | ||
| preprocessor.AtlasCentricPreprocessor = AtlasCentricPreprocessor | ||
| preprocessor.NativeSpacePreprocessor = NativeSpacePreprocessor | ||
|
|
||
| for module in [ | ||
| brainles_preprocessing, | ||
| constants, | ||
| modality, | ||
| normalization, | ||
| preprocessor, | ||
| ]: | ||
| monkeypatch.setitem(sys.modules, module.__name__, module) | ||
|
|
||
| sys.modules.pop("brats.preprocessing", None) | ||
| module = importlib.import_module("brats.preprocessing") | ||
| yield module | ||
| sys.modules.pop("brats.preprocessing", None) | ||
|
|
||
|
|
||
| def _all_modalities() -> dict[str, str]: | ||
| return { | ||
| "t1_input": "t1.nii.gz", | ||
| "t1c_input": "t1c.nii.gz", | ||
| "t2_input": "t2.nii.gz", | ||
| "flair_input": "flair.nii.gz", | ||
| "t1_output": "t1-out.nii.gz", | ||
| "t1c_output": "t1c-out.nii.gz", | ||
| "t2_output": "t2-out.nii.gz", | ||
| "flair_output": "flair-out.nii.gz", | ||
| } | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("challenge", "expected_pipeline"), | ||
| [ | ||
| ( | ||
| AdultGliomaPreAndPostTreatmentAlgorithms.BraTS25_1, | ||
| "preprocess_coreg_mni152reg_bet", | ||
| ), | ||
| (PediatricAlgorithms.BraTS25_1, "preprocess_coreg_sri24reg_defacing"), | ||
| ( | ||
| MissingMRIAlgorithms.BraTS25_1, | ||
| "preprocess_coreg_sri24reg_bet_allow_missing", | ||
| ), | ||
| (MeningiomaRTAlgorithms.BraTS25_1, "preprocess_deface_only"), | ||
| ( | ||
| AdultGliomaPreTreatmentAlgorithms.BraTS23_1, | ||
| "preprocess_coreg_sri24reg_bet", | ||
| ), | ||
| (AfricaAlgorithms.BraTS25_1, "preprocess_coreg_sri24reg_bet"), | ||
| (GoATAlgorithms.BraTS25_1A, "preprocess_coreg_sri24reg_bet"), | ||
| (InpaintingAlgorithms.BraTS25_1A, "preprocess_coreg_sri24reg_bet"), | ||
| (MeningiomaAlgorithms.BraTS25_1, "preprocess_coreg_sri24reg_bet"), | ||
| (MetastasesAlgorithms.BraTS23_1, "preprocess_coreg_sri24reg_bet"), | ||
| ], | ||
| ) | ||
| def test_preprocess_for_challenge_dispatches_by_enum( | ||
| preprocessing_module, challenge, expected_pipeline | ||
| ): | ||
| pipeline_names = [ | ||
| "preprocess_coreg_mni152reg_bet", | ||
| "preprocess_coreg_sri24reg_defacing", | ||
| "preprocess_coreg_sri24reg_bet_allow_missing", | ||
| "preprocess_deface_only", | ||
| "preprocess_coreg_sri24reg_bet", | ||
| ] | ||
| paths = _all_modalities() | ||
|
|
||
| with ExitStack() as stack: | ||
| pipelines = { | ||
| name: stack.enter_context(patch.object(preprocessing_module, name)) | ||
| for name in pipeline_names | ||
| } | ||
| preprocessing_module.preprocess_for_challenge(challenge, **paths) | ||
|
|
||
| pipelines[expected_pipeline].assert_called_once() | ||
| for name, pipeline in pipelines.items(): | ||
| if name != expected_pipeline: | ||
| pipeline.assert_not_called() | ||
|
|
||
|
|
||
| def test_preprocess_for_challenge_rejects_raw_value(preprocessing_module): | ||
| with pytest.raises(TypeError, match="supported Algorithms enum member"): | ||
| preprocessing_module.preprocess_for_challenge( | ||
| AdultGliomaPreAndPostTreatmentAlgorithms.BraTS25_1.value, | ||
| **_all_modalities(), | ||
| ) | ||
|
|
||
|
|
||
| def test_preprocess_for_challenge_validates_required_modalities(preprocessing_module): | ||
| paths = _all_modalities() | ||
| paths["t1_input"] = None | ||
|
|
||
| with pytest.raises(ValueError, match="All modalities required"): | ||
| preprocessing_module.preprocess_for_challenge( | ||
| AdultGliomaPreAndPostTreatmentAlgorithms.BraTS25_1, | ||
| **paths, | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.