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

8185 - Refactor test #8231

Open
wants to merge 34 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
075ec11
Eliminates code repetition
garciadias Nov 20, 2024
e8d3e19
Replace relative import with absolute
garciadias Nov 20, 2024
d4b01e6
Directly tests export_ckpt function instead of using command_line_tests
garciadias Nov 21, 2024
bfc68a4
Style fix
garciadias Nov 21, 2024
10eb2af
Merge branch 'dev' into 8185-tests-refactor
garciadias Nov 21, 2024
55fcd22
Revert "Style fix"
garciadias Nov 23, 2024
ba16743
Revert "Replace relative import with absolute"
garciadias Nov 23, 2024
1667eb7
Revert "Directly tests export_ckpt function instead of using command_…
garciadias Nov 23, 2024
702e740
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 24, 2024
9a2c2f4
moves tests to their corresponding folder
garciadias Nov 28, 2024
f2cf158
replace relative imports with absolute import
garciadias Nov 28, 2024
b3fd8e9
Change locating integrations
garciadias Nov 28, 2024
114fc72
Corrects the download path for integration tests
garciadias Nov 28, 2024
626e050
Move array/* and dictionary/* files to parent directory
garciadias Dec 2, 2024
4c6b59c
Move single files on their parent folders
garciadias Dec 2, 2024
050e71b
Merge remote-tracking branch 'upstream/dev' into dev
garciadias Dec 2, 2024
7d68938
Merge branch 'dev' into 8185-tests-refactor
garciadias Dec 2, 2024
3508211
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 2, 2024
2d55074
Recovers deleted file
garciadias Dec 3, 2024
6e9c66e
Merge remote-tracking branch 'upstream/dev' into 8185-tests-refactor
garciadias Dec 3, 2024
fa5c75c
Merge remote-tracking branch 'upstream/dev' into dev
garciadias Dec 4, 2024
dda65c4
Merge branch 'dev' into 8185-tests-refactor
garciadias Dec 4, 2024
bf82225
Start fixing path issues after moving files
garciadias Dec 6, 2024
56c2a48
Keep fixing data paths
garciadias Dec 9, 2024
98d3ab2
rerouting paths
garciadias Dec 11, 2024
6d1af88
Merge remote-tracking branch 'origin/8185-tests-refactor' into 8185-t…
garciadias Dec 11, 2024
a0d2395
Solve many more issues
garciadias Dec 11, 2024
9977e98
Merge remote-tracking branch 'origin/8185-tests-refactor' into 8185-t…
garciadias Dec 11, 2024
8831dc0
reorder imports
garciadias Dec 11, 2024
58c461c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 11, 2024
bb85f53
Fix path issues
garciadias Dec 11, 2024
865dc22
Move utils inside utils to avoid coflict
garciadias Dec 12, 2024
cf1025a
Keep cleaning tests but reverting utils.utils change
Dec 16, 2024
d2e7a2e
Merge remote-tracking branch 'origin/8185-tests-refactor' into 8185-t…
garciadias Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ temp/
.DS_Store

# temporary testing data MedNIST
tests/integration/testing_data/MedNIST*
tests/testing_data/MedNIST*
tests/testing_data/*Hippocampus*
tests/testing_data/*.tiff
Expand Down
2 changes: 1 addition & 1 deletion runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ if [ $doNetTests = true ]
then
set +e # disable exit on failure so that diagnostics can be given on failure
echo "${separator}${blue}integration${noColor}"
for i in tests/*integration_*.py
for i in tests/integration/*.py
do
echo "$i"
${cmdPrefix}${cmd} "$i"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from monai.networks import eval_mode
from monai.networks.nets import resnet10, resnet18, resnet34, resnet50, resnet101, resnet152, resnet200
from monai.utils import ensure_tuple, optional_import
from tests.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_onnx_save, test_script_save
from tests.utils.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_onnx_save, test_script_save

_, has_torchvision = optional_import("torchvision")

Expand Down Expand Up @@ -101,7 +101,6 @@
@unittest.skipUnless(has_torchvision, "Requires torchvision")
@skip_if_quick
class TestRetinaNet(unittest.TestCase):

@parameterized.expand(TEST_CASES)
def test_retina_shape(self, model, input_param, input_shape):
backbone = model(**input_param)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from monai.apps.detection.utils.anchor_utils import AnchorGeneratorWithAnchorShape
from monai.networks import eval_mode, train_mode
from monai.utils import optional_import
from tests.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save
from tests.utils.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save

_, has_torchvision = optional_import("torchvision")

Expand Down Expand Up @@ -93,7 +93,6 @@


class NaiveNetwork(torch.nn.Module):

def __init__(self, spatial_dims, num_classes, **kwargs):
super().__init__()
self.spatial_dims = spatial_dims
Expand All @@ -115,7 +114,6 @@ def forward(self, images):
@unittest.skipUnless(has_torchvision, "Requires torchvision")
@skip_if_quick
class TestRetinaNetDetector(unittest.TestCase):

@parameterized.expand(TEST_CASES)
def test_retina_detector_resnet_backbone_shape(self, input_param, input_shape):
returned_layers = [1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)
from monai.data.meta_tensor import MetaTensor
from monai.transforms import CastToTyped, Invertd
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.utils.utils import TEST_NDARRAYS, assert_allclose

TESTS_3D = []
boxes = [[0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 3, 3], [0, 1, 1, 2, 3, 4]]
Expand Down Expand Up @@ -79,7 +79,6 @@


class TestBoxTransform(unittest.TestCase):

@parameterized.expand(TESTS_2D_mask)
def test_value_2d_mask(self, mask, expected_box_label):
box_label = convert_mask_to_box(mask)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from monai.apps.detection.utils.anchor_utils import AnchorGenerator, AnchorGeneratorWithAnchorShape
from monai.utils import optional_import
from tests.utils import SkipIfBeforePyTorchVersion, assert_allclose, test_script_save
from tests.utils.utils import SkipIfBeforePyTorchVersion, assert_allclose, test_script_save

_, has_torchvision = optional_import("torchvision")

Expand All @@ -42,7 +42,6 @@
@SkipIfBeforePyTorchVersion((1, 11))
@unittest.skipUnless(has_torchvision, "Requires torchvision")
class TestAnchorGenerator(unittest.TestCase):

@parameterized.expand(TEST_CASES_2D)
def test_anchor_2d(self, input_param, image_shape, feature_maps_shapes):
torch_anchor_utils, _ = optional_import("torchvision.models.detection.anchor_utils")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from monai.apps.detection.utils.ATSS_matcher import ATSSMatcher
from monai.data.box_utils import box_iou
from tests.utils import assert_allclose
from tests.utils.utils import assert_allclose

TEST_CASES = [
[
Expand All @@ -33,7 +33,6 @@


class TestATSS(unittest.TestCase):

@parameterized.expand(TEST_CASES)
def test_atss(self, input_param, boxes, anchors, num_anchors_per_level, num_anchors_per_loc, expected_matches):
matcher = ATSSMatcher(**input_param, debug=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

from monai.apps.detection.utils.box_coder import BoxCoder
from monai.transforms import CastToType
from tests.utils import assert_allclose
from tests.utils.utils import assert_allclose


class TestBoxTransform(unittest.TestCase):

def test_value(self):
box_coder = BoxCoder(weights=[1, 1, 1, 1, 1, 1])
test_dtype = [torch.float32, torch.float16]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.apps.detection.utils.box_selector import BoxSelector
from tests.utils import assert_allclose
from tests.utils.utils import assert_allclose

device = "cuda" if torch.cuda.is_available() else "cpu"
num_anchors = 7
Expand Down Expand Up @@ -56,7 +56,6 @@


class TestBoxSelector(unittest.TestCase):

@parameterized.expand(TEST_CASE)
def test_box_selector(self, input_param, boxes, logits, image_shape, expected_results):
box_selector = BoxSelector(**input_param)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from monai.apps.detection.utils.detector_utils import preprocess_images
from monai.utils import ensure_tuple
from tests.utils import assert_allclose
from tests.utils.utils import assert_allclose

TEST_CASE_1 = [ # 3D, batch 3, 2 input channel
{
Expand Down Expand Up @@ -79,7 +79,6 @@


class TestDetectorUtils(unittest.TestCase):

@parameterized.expand(TEST_CASES)
def test_detector_utils(self, input_param, input_shape, expected_shape):
size_divisible = 32 * ensure_tuple(input_param["conv1_t_stride"])[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.apps.detection.utils.hard_negative_sampler import HardNegativeSampler
from tests.utils import assert_allclose
from tests.utils.utils import assert_allclose

TEST_CASE = [
[[], [], [], [torch.tensor([]), torch.tensor([])], [torch.tensor([]), torch.tensor([])]],
Expand All @@ -37,7 +37,6 @@


class TestSampleSlices(unittest.TestCase):

@parameterized.expand(TEST_CASE)
def test_shape(self, target_label0, target_label1, concat_fg_probs, expected_result_pos, expected_result_neg):
compute_dtypes = [torch.float16, torch.float32]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from monai.apps.generation.maisi.networks.autoencoderkl_maisi import AutoencoderKlMaisi
from monai.networks import eval_mode
from monai.utils import optional_import
from tests.utils import SkipIfBeforePyTorchVersion
from tests.utils.utils import SkipIfBeforePyTorchVersion

tqdm, has_tqdm = optional_import("tqdm", name="tqdm")
_, has_einops = optional_import("einops")
Expand Down Expand Up @@ -77,7 +77,6 @@


class TestAutoencoderKlMaisi(unittest.TestCase):

@parameterized.expand(CASES)
def test_shape(self, input_param, input_shape, expected_shape, expected_latent_shape):
net = AutoencoderKlMaisi(**input_param).to(device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from monai.apps.generation.maisi.networks.controlnet_maisi import ControlNetMaisi
from monai.networks import eval_mode
from monai.utils import optional_import
from tests.utils import SkipIfBeforePyTorchVersion
from tests.utils.utils import SkipIfBeforePyTorchVersion

_, has_einops = optional_import("einops")

Expand Down Expand Up @@ -129,7 +129,6 @@

@SkipIfBeforePyTorchVersion((2, 0))
class TestControlNet(unittest.TestCase):

@parameterized.expand(TEST_CASES)
@skipUnless(has_einops, "Requires einops")
def test_shape_unconditioned_models(self, input_param, expected_num_down_blocks_residuals, expected_shape):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from parameterized import parameterized

from monai.apps.pathology.handlers.utils import from_engine_hovernet
from tests.utils import assert_allclose
from tests.utils.utils import assert_allclose

TEST_CASE_0 = [
[{"A": {"C": 1, "D": 2}, "B": {"C": 2, "D": 2}}, {"A": {"C": 3, "D": 2}, "B": {"C": 4, "D": 2}}],
Expand All @@ -28,7 +28,6 @@


class TestFromEngineHovernet(unittest.TestCase):

@parameterized.expand(CASES)
def test_results(self, input, expected):
output = from_engine_hovernet(keys=["A", "B"], nested_key="C")(input)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from monai.apps.pathology.engines import PrepareBatchHoVerNet
from monai.engines import SupervisedEvaluator
from monai.utils.enums import HoVerNetBranch
from tests.utils import assert_allclose
from tests.utils.utils import assert_allclose

TEST_CASE_0 = [
{"extra_keys": ["extra_label1", "extra_label2"]},
Expand All @@ -35,7 +35,6 @@ def forward(self, x: torch.Tensor):


class TestPrepareBatchHoVerNet(unittest.TestCase):

@parameterized.expand([TEST_CASE_0])
def test_content(self, input_args, expected_value):
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from monai.data import MetaTensor
from monai.inferers import sliding_window_inference
from monai.utils import optional_import
from tests.test_sliding_window_inference import TEST_CASES
from tests.inferers.test_sliding_window_inference import TEST_CASES

_, has_tqdm = optional_import("tqdm")

Expand All @@ -36,7 +36,6 @@


class TestSlidingWindowHoVerNetInference(unittest.TestCase):

@parameterized.expand(TEST_CASES_PADDING)
def test_sliding_window_with_padding(
self, key, image_shape, roi_shape, sw_batch_size, overlap, mode, device, extra_input_padding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from monai.apps.pathology.transforms.post.array import GenerateDistanceMap
from monai.transforms.intensity.array import GaussianSmooth
from tests.utils import TEST_NDARRAYS
from tests.utils.utils import TEST_NDARRAYS

EXCEPTION_TESTS = []
TESTS = []
Expand All @@ -36,7 +36,6 @@


class TestGenerateDistanceMap(unittest.TestCase):

@parameterized.expand(EXCEPTION_TESTS)
def test_value(self, arguments, mask, probmap, exception_type):
with self.assertRaises(exception_type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from monai.apps.pathology.transforms.post.dictionary import GenerateDistanceMapd
from monai.transforms.intensity.array import GaussianSmooth
from tests.utils import TEST_NDARRAYS
from tests.utils.utils import TEST_NDARRAYS

EXCEPTION_TESTS = []
TESTS = []
Expand Down Expand Up @@ -55,7 +55,6 @@


class TestGenerateDistanceMapd(unittest.TestCase):

@parameterized.expand(EXCEPTION_TESTS)
def test_value(self, arguments, mask, border_map, exception_type):
with self.assertRaises(exception_type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.apps.pathology.transforms.post.array import GenerateInstanceBorder
from tests.utils import TEST_NDARRAYS
from tests.utils.utils import TEST_NDARRAYS

EXCEPTION_TESTS = []
TESTS = []
Expand All @@ -34,7 +34,6 @@


class TestGenerateInstanceBorder(unittest.TestCase):

@parameterized.expand(EXCEPTION_TESTS)
def test_value(self, arguments, mask, hover_map, exception_type):
with self.assertRaises(exception_type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.apps.pathology.transforms.post.dictionary import GenerateInstanceBorderd
from tests.utils import TEST_NDARRAYS
from tests.utils.utils import TEST_NDARRAYS

EXCEPTION_TESTS = []
TESTS = []
Expand All @@ -44,7 +44,6 @@


class TestGenerateInstanceBorderd(unittest.TestCase):

@parameterized.expand(EXCEPTION_TESTS)
def test_value(self, arguments, mask, hover_map, exception_type):
with self.assertRaises(exception_type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from monai.apps.pathology.transforms.post.array import GenerateInstanceCentroid
from monai.transforms import BoundingRect
from monai.utils import min_version, optional_import
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.utils.utils import TEST_NDARRAYS, assert_allclose

_, has_skimage = optional_import("skimage", "0.19.3", min_version)

Expand All @@ -41,7 +41,6 @@

@unittest.skipUnless(has_skimage, "Requires scikit-image library.")
class TestGenerateInstanceCentroid(unittest.TestCase):

@parameterized.expand(TEST_CASE)
def test_shape(self, in_type, test_data, offset, expected):
inst_bbox = get_bbox(test_data[None])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from monai.apps.pathology.transforms.post.dictionary import GenerateInstanceCentroidd
from monai.transforms import BoundingRect
from monai.utils import min_version, optional_import
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.utils.utils import TEST_NDARRAYS, assert_allclose

_, has_skimage = optional_import("skimage", "0.19.3", min_version)

Expand All @@ -41,7 +41,6 @@

@unittest.skipUnless(has_skimage, "Requires scikit-image library.")
class TestGenerateInstanceCentroidd(unittest.TestCase):

@parameterized.expand(TEST_CASE)
def test_shape(self, in_type, test_data, offset, expected):
inst_bbox = get_bbox(test_data[None])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from monai.apps.pathology.transforms.post.array import GenerateInstanceContour
from monai.transforms import BoundingRect
from monai.utils import min_version, optional_import
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.utils.utils import TEST_NDARRAYS, assert_allclose

_, has_skimage = optional_import("skimage", "0.19.3", min_version)

Expand All @@ -46,7 +46,6 @@

@unittest.skipUnless(has_skimage, "Requires scikit-image library.")
class TestGenerateInstanceContour(unittest.TestCase):

@parameterized.expand(TEST_CASE)
def test_shape(self, in_type, test_data, min_num_points, offset, expected):
inst_bbox = get_bbox(test_data[None])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from monai.apps.pathology.transforms.post.dictionary import GenerateInstanceContourd
from monai.transforms import BoundingRect
from monai.utils import min_version, optional_import
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.utils.utils import TEST_NDARRAYS, assert_allclose

_, has_skimage = optional_import("skimage", "0.19.3", min_version)

Expand All @@ -46,7 +46,6 @@

@unittest.skipUnless(has_skimage, "Requires scikit-image library.")
class TestGenerateInstanceContourd(unittest.TestCase):

@parameterized.expand(TEST_CASE)
def test_shape(self, in_type, test_data, min_num_points, offset, expected):
inst_bbox = get_bbox(test_data[None])
Expand Down
Loading