diff --git a/tests/apps/detection/networks/test_retinanet.py b/tests/apps/detection/networks/test_retinanet.py index f36708d5b3..9ac345c34f 100644 --- a/tests/apps/detection/networks/test_retinanet.py +++ b/tests/apps/detection/networks/test_retinanet.py @@ -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") diff --git a/tests/apps/detection/networks/test_retinanet_detector.py b/tests/apps/detection/networks/test_retinanet_detector.py index 691254fd87..1bd4c17272 100644 --- a/tests/apps/detection/networks/test_retinanet_detector.py +++ b/tests/apps/detection/networks/test_retinanet_detector.py @@ -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") diff --git a/tests/apps/detection/test_box_transform.py b/tests/apps/detection/test_box_transform.py index e99f95fa32..15b3dd1817 100644 --- a/tests/apps/detection/test_box_transform.py +++ b/tests/apps/detection/test_box_transform.py @@ -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]] diff --git a/tests/apps/detection/utils/test_anchor_box.py b/tests/apps/detection/utils/test_anchor_box.py index 301ce78361..4d7a38d07e 100644 --- a/tests/apps/detection/utils/test_anchor_box.py +++ b/tests/apps/detection/utils/test_anchor_box.py @@ -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") diff --git a/tests/apps/detection/utils/test_atss_box_matcher.py b/tests/apps/detection/utils/test_atss_box_matcher.py index 6133d4839d..35d0958510 100644 --- a/tests/apps/detection/utils/test_atss_box_matcher.py +++ b/tests/apps/detection/utils/test_atss_box_matcher.py @@ -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 = [ [ diff --git a/tests/apps/detection/utils/test_box_coder.py b/tests/apps/detection/utils/test_box_coder.py index 75ff650d6c..5b695d144e 100644 --- a/tests/apps/detection/utils/test_box_coder.py +++ b/tests/apps/detection/utils/test_box_coder.py @@ -17,7 +17,7 @@ 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): diff --git a/tests/apps/detection/utils/test_detector_boxselector.py b/tests/apps/detection/utils/test_detector_boxselector.py index 326ecd5773..583087e264 100644 --- a/tests/apps/detection/utils/test_detector_boxselector.py +++ b/tests/apps/detection/utils/test_detector_boxselector.py @@ -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 diff --git a/tests/apps/detection/utils/test_detector_utils.py b/tests/apps/detection/utils/test_detector_utils.py index 352e1c2faf..5b37140873 100644 --- a/tests/apps/detection/utils/test_detector_utils.py +++ b/tests/apps/detection/utils/test_detector_utils.py @@ -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 { diff --git a/tests/apps/detection/utils/test_hardnegsampler.py b/tests/apps/detection/utils/test_hardnegsampler.py index 5385abd1db..11c5446e60 100644 --- a/tests/apps/detection/utils/test_hardnegsampler.py +++ b/tests/apps/detection/utils/test_hardnegsampler.py @@ -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([])]], diff --git a/tests/apps/generation/maisi/networks/test_autoencoderkl_maisi.py b/tests/apps/generation/maisi/networks/test_autoencoderkl_maisi.py index 0e9f427fb6..3ebad68456 100644 --- a/tests/apps/generation/maisi/networks/test_autoencoderkl_maisi.py +++ b/tests/apps/generation/maisi/networks/test_autoencoderkl_maisi.py @@ -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") diff --git a/tests/apps/generation/maisi/networks/test_controlnet_maisi.py b/tests/apps/generation/maisi/networks/test_controlnet_maisi.py index bfdf25ec6e..39aed569cc 100644 --- a/tests/apps/generation/maisi/networks/test_controlnet_maisi.py +++ b/tests/apps/generation/maisi/networks/test_controlnet_maisi.py @@ -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") diff --git a/tests/apps/pathology/handlers/test_from_engine_hovernet.py b/tests/apps/pathology/handlers/test_from_engine_hovernet.py index 7d1a784466..a296885682 100644 --- a/tests/apps/pathology/handlers/test_from_engine_hovernet.py +++ b/tests/apps/pathology/handlers/test_from_engine_hovernet.py @@ -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}}], diff --git a/tests/apps/pathology/test_prepare_batch_hovernet.py b/tests/apps/pathology/test_prepare_batch_hovernet.py index ae9554a3e8..559fdf58b2 100644 --- a/tests/apps/pathology/test_prepare_batch_hovernet.py +++ b/tests/apps/pathology/test_prepare_batch_hovernet.py @@ -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"]}, diff --git a/tests/apps/pathology/transforms/post/test_generate_distance_map.py b/tests/apps/pathology/transforms/post/test_generate_distance_map.py index 42f5664647..613d4233a4 100644 --- a/tests/apps/pathology/transforms/post/test_generate_distance_map.py +++ b/tests/apps/pathology/transforms/post/test_generate_distance_map.py @@ -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 = [] diff --git a/tests/apps/pathology/transforms/post/test_generate_distance_mapd.py b/tests/apps/pathology/transforms/post/test_generate_distance_mapd.py index 2bddadf5b8..7b1b36438d 100644 --- a/tests/apps/pathology/transforms/post/test_generate_distance_mapd.py +++ b/tests/apps/pathology/transforms/post/test_generate_distance_mapd.py @@ -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 = [] diff --git a/tests/apps/pathology/transforms/post/test_generate_instance_border.py b/tests/apps/pathology/transforms/post/test_generate_instance_border.py index fc1035dfe5..c962cdd189 100644 --- a/tests/apps/pathology/transforms/post/test_generate_instance_border.py +++ b/tests/apps/pathology/transforms/post/test_generate_instance_border.py @@ -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 = [] diff --git a/tests/apps/pathology/transforms/post/test_generate_instance_borderd.py b/tests/apps/pathology/transforms/post/test_generate_instance_borderd.py index cdfbee4193..0594dc6525 100644 --- a/tests/apps/pathology/transforms/post/test_generate_instance_borderd.py +++ b/tests/apps/pathology/transforms/post/test_generate_instance_borderd.py @@ -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 = [] diff --git a/tests/apps/pathology/transforms/post/test_generate_instance_centroid.py b/tests/apps/pathology/transforms/post/test_generate_instance_centroid.py index 6b4d533401..8b8031433a 100644 --- a/tests/apps/pathology/transforms/post/test_generate_instance_centroid.py +++ b/tests/apps/pathology/transforms/post/test_generate_instance_centroid.py @@ -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) diff --git a/tests/apps/pathology/transforms/post/test_generate_instance_centroidd.py b/tests/apps/pathology/transforms/post/test_generate_instance_centroidd.py index d381ad8c0e..20183b58e1 100644 --- a/tests/apps/pathology/transforms/post/test_generate_instance_centroidd.py +++ b/tests/apps/pathology/transforms/post/test_generate_instance_centroidd.py @@ -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) diff --git a/tests/apps/pathology/transforms/post/test_generate_instance_contour.py b/tests/apps/pathology/transforms/post/test_generate_instance_contour.py index 7f4290747d..a669962647 100644 --- a/tests/apps/pathology/transforms/post/test_generate_instance_contour.py +++ b/tests/apps/pathology/transforms/post/test_generate_instance_contour.py @@ -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) diff --git a/tests/apps/pathology/transforms/post/test_generate_instance_contourd.py b/tests/apps/pathology/transforms/post/test_generate_instance_contourd.py index 5c831ee680..e8f680e81a 100644 --- a/tests/apps/pathology/transforms/post/test_generate_instance_contourd.py +++ b/tests/apps/pathology/transforms/post/test_generate_instance_contourd.py @@ -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) diff --git a/tests/apps/pathology/transforms/post/test_generate_instance_type.py b/tests/apps/pathology/transforms/post/test_generate_instance_type.py index 24e1d1b6d0..8361d57d71 100644 --- a/tests/apps/pathology/transforms/post/test_generate_instance_type.py +++ b/tests/apps/pathology/transforms/post/test_generate_instance_type.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.apps.pathology.transforms.post.array import GenerateInstanceType -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose y, x = np.ogrid[0:30, 0:30] diff --git a/tests/apps/pathology/transforms/post/test_generate_instance_typed.py b/tests/apps/pathology/transforms/post/test_generate_instance_typed.py index 958f68d6bb..3cf1018e1b 100644 --- a/tests/apps/pathology/transforms/post/test_generate_instance_typed.py +++ b/tests/apps/pathology/transforms/post/test_generate_instance_typed.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.apps.pathology.transforms.post.dictionary import GenerateInstanceTyped -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose y, x = np.ogrid[0:30, 0:30] diff --git a/tests/apps/pathology/transforms/post/test_generate_watershed_markers.py b/tests/apps/pathology/transforms/post/test_generate_watershed_markers.py index 238fb00ee0..88e4284496 100644 --- a/tests/apps/pathology/transforms/post/test_generate_watershed_markers.py +++ b/tests/apps/pathology/transforms/post/test_generate_watershed_markers.py @@ -18,7 +18,7 @@ from monai.apps.pathology.transforms.post.array import GenerateWatershedMarkers from monai.utils import min_version, optional_import -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS _, has_skimage = optional_import("skimage", "0.19.3", min_version) _, has_scipy = optional_import("scipy", "1.8.1", min_version) diff --git a/tests/apps/pathology/transforms/post/test_generate_watershed_markersd.py b/tests/apps/pathology/transforms/post/test_generate_watershed_markersd.py index a3c2b9c231..36f12b35b6 100644 --- a/tests/apps/pathology/transforms/post/test_generate_watershed_markersd.py +++ b/tests/apps/pathology/transforms/post/test_generate_watershed_markersd.py @@ -18,7 +18,7 @@ from monai.apps.pathology.transforms.post.dictionary import GenerateWatershedMarkersd from monai.utils import min_version, optional_import -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS _, has_skimage = optional_import("skimage", "0.19.3", min_version) _, has_scipy = optional_import("scipy", "1.8.1", min_version) diff --git a/tests/apps/pathology/transforms/post/test_generate_watershed_mask.py b/tests/apps/pathology/transforms/post/test_generate_watershed_mask.py index 5224a912b0..a1c70e4179 100644 --- a/tests/apps/pathology/transforms/post/test_generate_watershed_mask.py +++ b/tests/apps/pathology/transforms/post/test_generate_watershed_mask.py @@ -19,7 +19,7 @@ from monai.apps.pathology.transforms.post.array import GenerateWatershedMask from monai.utils import min_version, optional_import -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS _, has_scipy = optional_import("scipy", "1.8.1", min_version) diff --git a/tests/apps/pathology/transforms/post/test_generate_watershed_maskd.py b/tests/apps/pathology/transforms/post/test_generate_watershed_maskd.py index 9d0f2c274a..e93ecceb86 100644 --- a/tests/apps/pathology/transforms/post/test_generate_watershed_maskd.py +++ b/tests/apps/pathology/transforms/post/test_generate_watershed_maskd.py @@ -19,7 +19,7 @@ from monai.apps.pathology.transforms.post.dictionary import GenerateWatershedMaskd from monai.utils import min_version, optional_import -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS _, has_scipy = optional_import("scipy", "1.8.1", min_version) diff --git a/tests/apps/pathology/transforms/post/test_hovernet_instance_map_post_processing.py b/tests/apps/pathology/transforms/post/test_hovernet_instance_map_post_processing.py index ce272fba1a..c3f4dd97e8 100644 --- a/tests/apps/pathology/transforms/post/test_hovernet_instance_map_post_processing.py +++ b/tests/apps/pathology/transforms/post/test_hovernet_instance_map_post_processing.py @@ -19,7 +19,7 @@ from monai.apps.pathology.transforms.post.array import HoVerNetInstanceMapPostProcessing from monai.transforms import ComputeHoVerMaps, FillHoles, GaussianSmooth 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_scipy = optional_import("scipy", "1.8.1", min_version) _, has_skimage = optional_import("skimage", "0.19.3", min_version) diff --git a/tests/apps/pathology/transforms/post/test_hovernet_instance_map_post_processingd.py b/tests/apps/pathology/transforms/post/test_hovernet_instance_map_post_processingd.py index c982156caa..7bdb35f6b1 100644 --- a/tests/apps/pathology/transforms/post/test_hovernet_instance_map_post_processingd.py +++ b/tests/apps/pathology/transforms/post/test_hovernet_instance_map_post_processingd.py @@ -20,7 +20,7 @@ from monai.transforms import ComputeHoVerMaps, FillHoles, GaussianSmooth from monai.utils import min_version, optional_import from monai.utils.enums import HoVerNetBranch -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose _, has_scipy = optional_import("scipy", "1.8.1", min_version) _, has_skimage = optional_import("skimage", "0.19.3", min_version) diff --git a/tests/apps/pathology/transforms/post/test_hovernet_nuclear_type_post_processing.py b/tests/apps/pathology/transforms/post/test_hovernet_nuclear_type_post_processing.py index e97b7abd2c..b8c882207b 100644 --- a/tests/apps/pathology/transforms/post/test_hovernet_nuclear_type_post_processing.py +++ b/tests/apps/pathology/transforms/post/test_hovernet_nuclear_type_post_processing.py @@ -22,7 +22,7 @@ ) from monai.transforms import ComputeHoVerMaps 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_scipy = optional_import("scipy", "1.8.1", min_version) _, has_skimage = optional_import("skimage", "0.19.3", min_version) diff --git a/tests/apps/pathology/transforms/post/test_watershed.py b/tests/apps/pathology/transforms/post/test_watershed.py index 3f7a29bfe7..4215b0df3a 100644 --- a/tests/apps/pathology/transforms/post/test_watershed.py +++ b/tests/apps/pathology/transforms/post/test_watershed.py @@ -24,7 +24,7 @@ Watershed, ) from monai.utils import min_version, optional_import -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS _, has_skimage = optional_import("skimage", "0.19.3", min_version) _, has_scipy = optional_import("scipy", "1.8.1", min_version) diff --git a/tests/apps/pathology/transforms/post/test_watershedd.py b/tests/apps/pathology/transforms/post/test_watershedd.py index fc44996be4..5ba576b747 100644 --- a/tests/apps/pathology/transforms/post/test_watershedd.py +++ b/tests/apps/pathology/transforms/post/test_watershedd.py @@ -25,7 +25,7 @@ ) from monai.transforms import Compose from monai.utils import min_version, optional_import -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS _, has_skimage = optional_import("skimage", "0.19.3", min_version) _, has_scipy = optional_import("scipy", "1.8.1", min_version) diff --git a/tests/apps/reconstruction/networks/nets/test_recon_net_utils.py b/tests/apps/reconstruction/networks/nets/test_recon_net_utils.py index 48d3b59a17..ced27097d1 100644 --- a/tests/apps/reconstruction/networks/nets/test_recon_net_utils.py +++ b/tests/apps/reconstruction/networks/nets/test_recon_net_utils.py @@ -27,7 +27,7 @@ sensitivity_map_expand, sensitivity_map_reduce, ) -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose # no need for checking devices, these functions don't change device format # reshape test case diff --git a/tests/apps/reconstruction/test_complex_utils.py b/tests/apps/reconstruction/test_complex_utils.py index fdcee4babe..bc7c4f4c52 100644 --- a/tests/apps/reconstruction/test_complex_utils.py +++ b/tests/apps/reconstruction/test_complex_utils.py @@ -18,7 +18,7 @@ from monai.apps.reconstruction.complex_utils import complex_abs, complex_conj, complex_mul, convert_to_tensor_complex from monai.utils.type_conversion import convert_data_type -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose # test case for convert_to_tensor_complex im_complex = [[1.0 + 1.0j, 1.0 + 1.0j], [1.0 + 1.0j, 1.0 + 1.0j]] diff --git a/tests/apps/reconstruction/test_fastmri_reader.py b/tests/apps/reconstruction/test_fastmri_reader.py index 06c3954eae..309ec86f4a 100644 --- a/tests/apps/reconstruction/test_fastmri_reader.py +++ b/tests/apps/reconstruction/test_fastmri_reader.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.apps.reconstruction.fastmri_reader import FastMRIReader -from tests.utils import SkipIfNoModule, assert_allclose +from tests.utils.utils import SkipIfNoModule, assert_allclose TEST_CASE1 = [ { diff --git a/tests/apps/reconstruction/test_mri_utils.py b/tests/apps/reconstruction/test_mri_utils.py index aabf06d02e..5a996eb497 100644 --- a/tests/apps/reconstruction/test_mri_utils.py +++ b/tests/apps/reconstruction/test_mri_utils.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.apps.reconstruction.mri_utils import root_sum_of_squares -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose # root_sum_of_squares im = [[3.0, 4.0], [3.0, 4.0]] diff --git a/tests/apps/reconstruction/transforms/test_reference_based_normalize_intensity.py b/tests/apps/reconstruction/transforms/test_reference_based_normalize_intensity.py index 2d946af118..4b5cb45dc5 100644 --- a/tests/apps/reconstruction/transforms/test_reference_based_normalize_intensity.py +++ b/tests/apps/reconstruction/transforms/test_reference_based_normalize_intensity.py @@ -18,7 +18,7 @@ from monai.apps.reconstruction.transforms.dictionary import ReferenceBasedNormalizeIntensityd from monai.utils.type_conversion import convert_to_numpy -from tests.utils import TEST_NDARRAYS_NO_META_TENSOR, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_NO_META_TENSOR, assert_allclose # see test_normalize_intensityd for typical tests (like non-zero # normalization, device test, etc.) diff --git a/tests/apps/reconstruction/transforms/test_reference_based_spatial_cropd.py b/tests/apps/reconstruction/transforms/test_reference_based_spatial_cropd.py index 83cd9c4a5d..889c511500 100644 --- a/tests/apps/reconstruction/transforms/test_reference_based_spatial_cropd.py +++ b/tests/apps/reconstruction/transforms/test_reference_based_spatial_cropd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.apps.reconstruction.transforms.dictionary import ReferenceBasedSpatialCropd -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS # see test_spatial_cropd for typical tests (like roi_start, # roi_slices, etc.) diff --git a/tests/apps/test_auto3dseg_bundlegen.py b/tests/apps/test_auto3dseg_bundlegen.py index e7bf6820bc..a7e7d4090b 100644 --- a/tests/apps/test_auto3dseg_bundlegen.py +++ b/tests/apps/test_auto3dseg_bundlegen.py @@ -26,7 +26,7 @@ from monai.bundle.config_parser import ConfigParser from monai.data import create_test_image_3d from monai.utils import set_determinism -from tests.utils import ( +from tests.utils.utils import ( SkipIfBeforePyTorchVersion, get_testing_algo_template_path, skip_if_downloading_fails, diff --git a/tests/apps/test_cross_validation.py b/tests/apps/test_cross_validation.py index 6d0f2319fb..29a779d2c5 100644 --- a/tests/apps/test_cross_validation.py +++ b/tests/apps/test_cross_validation.py @@ -17,7 +17,7 @@ from monai.apps import CrossValidation, DecathlonDataset from monai.data import MetaTensor from monai.transforms import Compose, EnsureChannelFirstd, LoadImaged, ScaleIntensityd -from tests.utils import skip_if_downloading_fails, skip_if_quick +from tests.utils.utils import skip_if_downloading_fails, skip_if_quick class TestCrossValidation(unittest.TestCase): diff --git a/tests/apps/test_decathlondataset.py b/tests/apps/test_decathlondataset.py index 70a2a6c06c..3af71689c7 100644 --- a/tests/apps/test_decathlondataset.py +++ b/tests/apps/test_decathlondataset.py @@ -19,7 +19,7 @@ from monai.apps import DecathlonDataset from monai.data import MetaTensor from monai.transforms import Compose, EnsureChannelFirstd, LoadImaged, ScaleIntensityd -from tests.utils import skip_if_downloading_fails, skip_if_quick +from tests.utils.utils import skip_if_downloading_fails, skip_if_quick class TestDecathlonDataset(unittest.TestCase): diff --git a/tests/apps/test_download_and_extract.py b/tests/apps/test_download_and_extract.py index 555f7dc250..cd22ec52c2 100644 --- a/tests/apps/test_download_and_extract.py +++ b/tests/apps/test_download_and_extract.py @@ -20,7 +20,7 @@ from parameterized import parameterized from monai.apps import download_and_extract, download_url, extractall -from tests.utils import skip_if_downloading_fails, skip_if_quick, testing_data_config +from tests.utils.utils import skip_if_downloading_fails, skip_if_quick, testing_data_config class TestDownloadAndExtract(unittest.TestCase): diff --git a/tests/apps/test_mednistdataset.py b/tests/apps/test_mednistdataset.py index c1b21e9373..6a95cd29bf 100644 --- a/tests/apps/test_mednistdataset.py +++ b/tests/apps/test_mednistdataset.py @@ -19,7 +19,7 @@ from monai.apps import MedNISTDataset from monai.data import MetaTensor from monai.transforms import Compose, EnsureChannelFirstd, LoadImaged, ScaleIntensityd -from tests.utils import skip_if_downloading_fails, skip_if_quick +from tests.utils.utils import skip_if_downloading_fails, skip_if_quick MEDNIST_FULL_DATASET_LENGTH = 58954 diff --git a/tests/apps/test_mmar_download.py b/tests/apps/test_mmar_download.py index 2ac73a8149..74eb03fdf7 100644 --- a/tests/apps/test_mmar_download.py +++ b/tests/apps/test_mmar_download.py @@ -25,7 +25,7 @@ from monai.apps.mmars import MODEL_DESC from monai.apps.mmars.mmars import _get_val from monai.utils import version_leq -from tests.utils import skip_if_downloading_fails, skip_if_quick +from tests.utils.utils import skip_if_downloading_fails, skip_if_quick TEST_CASES = [["clara_pt_prostate_mri_segmentation"], ["clara_pt_covid19_ct_lesion_segmentation"]] TEST_EXTRACT_CASES = [ diff --git a/tests/apps/test_tciadataset.py b/tests/apps/test_tciadataset.py index 5a16bb4816..70546b449b 100644 --- a/tests/apps/test_tciadataset.py +++ b/tests/apps/test_tciadataset.py @@ -19,7 +19,7 @@ from monai.apps.tcia import DCM_FILENAME_REGEX, TCIA_LABEL_DICT from monai.data import MetaTensor from monai.transforms import Compose, EnsureChannelFirstd, LoadImaged, ScaleIntensityd -from tests.utils import skip_if_downloading_fails, skip_if_quick +from tests.utils.utils import skip_if_downloading_fails, skip_if_quick class TestTciaDataset(unittest.TestCase): diff --git a/tests/apps/vista3d/test_point_based_window_inferer.py b/tests/apps/vista3d/test_point_based_window_inferer.py index 1b293288c4..f82708185a 100644 --- a/tests/apps/vista3d/test_point_based_window_inferer.py +++ b/tests/apps/vista3d/test_point_based_window_inferer.py @@ -20,7 +20,7 @@ from monai.networks import eval_mode from monai.networks.nets.vista3d import vista3d132 from monai.utils import optional_import -from tests.utils import SkipIfBeforePyTorchVersion, skip_if_quick +from tests.utils.utils import SkipIfBeforePyTorchVersion, skip_if_quick device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/bundle/test_bundle_ckpt_export.py b/tests/bundle/test_bundle_ckpt_export.py index 354728400c..9a784abb97 100644 --- a/tests/bundle/test_bundle_ckpt_export.py +++ b/tests/bundle/test_bundle_ckpt_export.py @@ -22,7 +22,7 @@ from monai.bundle import ConfigParser from monai.data import load_net_with_metadata from monai.networks import save_state -from tests.utils import command_line_tests, skip_if_windows +from tests.utils.utils import command_line_tests, skip_if_windows TEST_CASE_1 = ["", ""] TEST_CASE_2 = ["model", ""] diff --git a/tests/bundle/test_bundle_download.py b/tests/bundle/test_bundle_download.py index 399c61b117..60a8be3db7 100644 --- a/tests/bundle/test_bundle_download.py +++ b/tests/bundle/test_bundle_download.py @@ -27,7 +27,7 @@ from monai.bundle import ConfigParser, create_workflow, load from monai.bundle.scripts import _examine_monai_version, _list_latest_versions, download from monai.utils import optional_import -from tests.utils import ( +from tests.utils.utils import ( SkipIfBeforePyTorchVersion, assert_allclose, command_line_tests, diff --git a/tests/bundle/test_bundle_get_data.py b/tests/bundle/test_bundle_get_data.py index f84713fbe3..2ae8583bca 100644 --- a/tests/bundle/test_bundle_get_data.py +++ b/tests/bundle/test_bundle_get_data.py @@ -17,7 +17,7 @@ from monai.bundle import get_all_bundles_list, get_bundle_info, get_bundle_versions from monai.utils import optional_import -from tests.utils import SkipIfNoModule, skip_if_downloading_fails, skip_if_quick, skip_if_windows +from tests.utils.utils import SkipIfNoModule, skip_if_downloading_fails, skip_if_quick, skip_if_windows requests, _ = optional_import("requests") diff --git a/tests/bundle/test_bundle_push_to_hf_hub.py b/tests/bundle/test_bundle_push_to_hf_hub.py index 39368c6f40..0f5a709ead 100644 --- a/tests/bundle/test_bundle_push_to_hf_hub.py +++ b/tests/bundle/test_bundle_push_to_hf_hub.py @@ -20,7 +20,7 @@ from monai.bundle import push_to_hf_hub from monai.utils import optional_import -from tests.utils import skip_if_quick +from tests.utils.utils import skip_if_quick huggingface_hub, has_huggingface_hub = optional_import("huggingface_hub") diff --git a/tests/bundle/test_bundle_trt_export.py b/tests/bundle/test_bundle_trt_export.py index 91b1bc889a..10e49ccf01 100644 --- a/tests/bundle/test_bundle_trt_export.py +++ b/tests/bundle/test_bundle_trt_export.py @@ -23,7 +23,7 @@ from monai.data import load_net_with_metadata from monai.networks import save_state from monai.utils import optional_import -from tests.utils import ( +from tests.utils.utils import ( SkipIfBeforeComputeCapabilityVersion, command_line_tests, skip_if_no_cuda, diff --git a/tests/bundle/test_bundle_utils.py b/tests/bundle/test_bundle_utils.py index 47c534f3b6..42bdaff59a 100644 --- a/tests/bundle/test_bundle_utils.py +++ b/tests/bundle/test_bundle_utils.py @@ -22,7 +22,7 @@ from monai.bundle.utils import load_bundle_config from monai.networks.nets import UNet from monai.utils import pprint_edges -from tests.utils import command_line_tests, skip_if_windows +from tests.utils.utils import command_line_tests, skip_if_windows metadata = """ { diff --git a/tests/bundle/test_bundle_verify_metadata.py b/tests/bundle/test_bundle_verify_metadata.py index b45ff8b2cf..074d0d60e9 100644 --- a/tests/bundle/test_bundle_verify_metadata.py +++ b/tests/bundle/test_bundle_verify_metadata.py @@ -20,7 +20,7 @@ from parameterized import parameterized from monai.bundle import ConfigParser, verify_metadata -from tests.utils import command_line_tests, download_url_or_skip_test, skip_if_windows, testing_data_config +from tests.utils.utils import command_line_tests, download_url_or_skip_test, skip_if_windows, testing_data_config TESTS_DIR = Path(__file__).parent.as_posix() SCHEMA_FILE = os.path.join(TESTS_DIR, "testing_data", "schema.json") diff --git a/tests/bundle/test_bundle_verify_net.py b/tests/bundle/test_bundle_verify_net.py index 5db25b1253..595cb6892a 100644 --- a/tests/bundle/test_bundle_verify_net.py +++ b/tests/bundle/test_bundle_verify_net.py @@ -19,7 +19,7 @@ from parameterized import parameterized from monai.bundle import ConfigParser, verify_net_in_out -from tests.utils import command_line_tests, skip_if_no_cuda, skip_if_windows +from tests.utils.utils import command_line_tests, skip_if_no_cuda, skip_if_windows TESTS_PATH = Path(__file__).parents[1].as_posix() diff --git a/tests/bundle/test_config_parser.py b/tests/bundle/test_config_parser.py index 577d5d2d07..5f62e59adb 100644 --- a/tests/bundle/test_config_parser.py +++ b/tests/bundle/test_config_parser.py @@ -26,7 +26,7 @@ from monai.data import DataLoader, Dataset from monai.transforms import Compose, LoadImaged, RandTorchVisiond from monai.utils import min_version, optional_import -from tests.utils import TimedCall +from tests.utils.utils import TimedCall _, has_tv = optional_import("torchvision", "0.8.0", min_version) _, has_yaml = optional_import("yaml") diff --git a/tests/config/test_cv2_dist.py b/tests/config/test_cv2_dist.py index 562c205763..006e2f55eb 100644 --- a/tests/config/test_cv2_dist.py +++ b/tests/config/test_cv2_dist.py @@ -20,7 +20,7 @@ # FIXME: test for the workaround of https://github.com/Project-MONAI/MONAI/issues/5291 from monai.config.deviceconfig import print_config -from tests.utils import skip_if_no_cuda +from tests.utils.utils import skip_if_no_cuda def main_worker(rank, ngpus_per_node, port): diff --git a/tests/croppers.py b/tests/croppers.py index cfececfa9f..b5a6f64d63 100644 --- a/tests/croppers.py +++ b/tests/croppers.py @@ -20,7 +20,7 @@ from monai.transforms import Randomizable from monai.transforms.lazy.functional import apply_pending from monai.transforms.transform import MapTransform -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose class CropTest(unittest.TestCase): diff --git a/tests/data/meta_tensor/test_meta_tensor.py b/tests/data/meta_tensor/test_meta_tensor.py index 60b6019703..9c2ae03471 100644 --- a/tests/data/meta_tensor/test_meta_tensor.py +++ b/tests/data/meta_tensor/test_meta_tensor.py @@ -34,7 +34,7 @@ from monai.transforms import BorderPadd, Compose, DivisiblePadd, FromMetaTensord, ToMetaTensord from monai.utils.enums import PostFix from monai.utils.module import pytorch_after -from tests.utils import TEST_DEVICES, SkipIfBeforePyTorchVersion, assert_allclose, skip_if_no_cuda +from tests.utils.utils import TEST_DEVICES, SkipIfBeforePyTorchVersion, assert_allclose, skip_if_no_cuda DTYPES = [[torch.float32], [torch.float64], [torch.float16], [torch.int64], [torch.int32], [None]] TESTS = [] diff --git a/tests/data/meta_tensor/test_to_from_meta_tensord.py b/tests/data/meta_tensor/test_to_from_meta_tensord.py index fe777cec77..434c794fb4 100644 --- a/tests/data/meta_tensor/test_to_from_meta_tensord.py +++ b/tests/data/meta_tensor/test_to_from_meta_tensord.py @@ -24,7 +24,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import FromMetaTensord, ToMetaTensord from monai.utils.enums import PostFix -from tests.utils import TEST_DEVICES, assert_allclose +from tests.utils.utils import TEST_DEVICES, assert_allclose DTYPES = [[torch.float32], [torch.float64], [torch.float16], [torch.int64], [torch.int32]] TESTS = [] diff --git a/tests/data/test_box_utils.py b/tests/data/test_box_utils.py index 3c05efe0d0..3ea5fe25cf 100644 --- a/tests/data/test_box_utils.py +++ b/tests/data/test_box_utils.py @@ -35,7 +35,7 @@ non_max_suppression, ) from monai.utils.type_conversion import convert_data_type -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/data/test_csv_iterable_dataset.py b/tests/data/test_csv_iterable_dataset.py index e06da0c41b..6fde2f5313 100644 --- a/tests/data/test_csv_iterable_dataset.py +++ b/tests/data/test_csv_iterable_dataset.py @@ -21,7 +21,7 @@ from monai.data import CSVIterableDataset, DataLoader from monai.transforms import ToNumpyd -from tests.utils import skip_if_windows +from tests.utils.utils import skip_if_windows @skip_if_windows diff --git a/tests/data/test_dataloader.py b/tests/data/test_dataloader.py index 73e27799f7..3d6ceb75e1 100644 --- a/tests/data/test_dataloader.py +++ b/tests/data/test_dataloader.py @@ -21,7 +21,7 @@ from monai.data import CacheDataset, DataLoader, Dataset, ZipDataset from monai.transforms import Compose, DataStatsd, Randomizable, SimulateDelayd from monai.utils import convert_to_numpy, set_determinism -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_1 = [[{"image": np.asarray([1, 2, 3])}, {"image": np.asarray([4, 5])}]] diff --git a/tests/data/test_fft_utils.py b/tests/data/test_fft_utils.py index 7c7035770a..b1bd743beb 100644 --- a/tests/data/test_fft_utils.py +++ b/tests/data/test_fft_utils.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.data.fft_utils import fftn_centered, ifftn_centered -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose # im = [[[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]] diff --git a/tests/data/test_gdsdataset.py b/tests/data/test_gdsdataset.py index 5d2e2aa013..58866c58fd 100644 --- a/tests/data/test_gdsdataset.py +++ b/tests/data/test_gdsdataset.py @@ -23,7 +23,7 @@ from monai.data import GDSDataset, json_hashing from monai.transforms import Compose, Flip, Identity, LoadImaged, SimulateDelayd, Transform from monai.utils import optional_import -from tests.utils import TEST_NDARRAYS, assert_allclose, skip_if_no_cuda +from tests.utils.utils import TEST_NDARRAYS, assert_allclose, skip_if_no_cuda _, has_cp = optional_import("cupy") nib, has_nib = optional_import("nibabel") diff --git a/tests/data/test_grid_dataset.py b/tests/data/test_grid_dataset.py index 4a3b4b6340..ac98635b95 100644 --- a/tests/data/test_grid_dataset.py +++ b/tests/data/test_grid_dataset.py @@ -20,7 +20,7 @@ from monai.data import DataLoader, GridPatchDataset, PatchIter, PatchIterd, iter_patch from monai.transforms import RandShiftIntensity, RandShiftIntensityd from monai.utils import set_determinism -from tests.utils import TEST_NDARRAYS, assert_allclose, get_arange_img +from tests.utils.utils import TEST_NDARRAYS, assert_allclose, get_arange_img def identity_generator(x): diff --git a/tests/data/test_init_reader.py b/tests/data/test_init_reader.py index cb45cb5146..05f80c83d8 100644 --- a/tests/data/test_init_reader.py +++ b/tests/data/test_init_reader.py @@ -15,7 +15,7 @@ from monai.data import ITKReader, NibabelReader, NrrdReader, NumpyReader, PILReader, PydicomReader from monai.transforms import LoadImage, LoadImaged -from tests.utils import SkipIfNoModule +from tests.utils.utils import SkipIfNoModule class TestInitLoadImage(unittest.TestCase): diff --git a/tests/data/test_itk_torch_bridge.py b/tests/data/test_itk_torch_bridge.py index 22ae019271..6134b28ffc 100644 --- a/tests/data/test_itk_torch_bridge.py +++ b/tests/data/test_itk_torch_bridge.py @@ -35,7 +35,7 @@ from monai.networks.blocks import Warp from monai.transforms import Affine from monai.utils import optional_import, set_determinism -from tests.utils import assert_allclose, skip_if_downloading_fails, skip_if_quick, test_is_quick, testing_data_config +from tests.utils.utils import assert_allclose, skip_if_downloading_fails, skip_if_quick, test_is_quick, testing_data_config itk, has_itk = optional_import("itk") _, has_nib = optional_import("nibabel") diff --git a/tests/data/test_lmdbdataset.py b/tests/data/test_lmdbdataset.py index 9d128dd728..00c75528d6 100644 --- a/tests/data/test_lmdbdataset.py +++ b/tests/data/test_lmdbdataset.py @@ -21,7 +21,7 @@ from monai.data import LMDBDataset, json_hashing from monai.transforms import Compose, LoadImaged, SimulateDelayd, Transform -from tests.utils import skip_if_windows +from tests.utils.utils import skip_if_windows TEST_CASE_1 = [ Compose( diff --git a/tests/data/test_lmdbdataset_dist.py b/tests/data/test_lmdbdataset_dist.py index 1acb89beb3..88f36cab4c 100644 --- a/tests/data/test_lmdbdataset_dist.py +++ b/tests/data/test_lmdbdataset_dist.py @@ -19,7 +19,7 @@ from monai.data import LMDBDataset, json_hashing from monai.transforms import Transform -from tests.utils import DistCall, DistTestCase, skip_if_windows +from tests.utils.utils import DistCall, DistTestCase, skip_if_windows class _InplaceXform(Transform): diff --git a/tests/data/test_make_nifti.py b/tests/data/test_make_nifti.py index 08d3a731ab..48628dfd97 100644 --- a/tests/data/test_make_nifti.py +++ b/tests/data/test_make_nifti.py @@ -21,7 +21,7 @@ from monai.data.synthetic import create_test_image_2d from monai.utils import optional_import -from tests.utils import make_nifti_image +from tests.utils.utils import make_nifti_image _, has_nib = optional_import("nibabel") diff --git a/tests/data/test_masked_patch_wsi_dataset.py b/tests/data/test_masked_patch_wsi_dataset.py index 1509599659..53981aa7d3 100644 --- a/tests/data/test_masked_patch_wsi_dataset.py +++ b/tests/data/test_masked_patch_wsi_dataset.py @@ -21,7 +21,7 @@ from monai.data import Dataset, MaskedPatchWSIDataset from monai.transforms import Lambdad from monai.utils import ProbMapKeys, WSIPatchKeys, optional_import, set_determinism -from tests.utils import download_url_or_skip_test, testing_data_config +from tests.utils.utils import download_url_or_skip_test, testing_data_config set_determinism(0) diff --git a/tests/data/test_nifti_rw.py b/tests/data/test_nifti_rw.py index 8543fcea30..61c9130a63 100644 --- a/tests/data/test_nifti_rw.py +++ b/tests/data/test_nifti_rw.py @@ -21,7 +21,7 @@ from monai.data import NibabelWriter from monai.transforms import LoadImage, Orientation, Spacing -from tests.utils import TEST_NDARRAYS, assert_allclose, make_nifti_image +from tests.utils.utils import TEST_NDARRAYS, assert_allclose, make_nifti_image TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/data/test_numpy_reader.py b/tests/data/test_numpy_reader.py index 6303598bb7..b018539774 100644 --- a/tests/data/test_numpy_reader.py +++ b/tests/data/test_numpy_reader.py @@ -20,7 +20,7 @@ from monai.data import DataLoader, Dataset, NumpyReader from monai.transforms import LoadImage, LoadImaged -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class TestNumpyReader(unittest.TestCase): diff --git a/tests/data/test_patch_wsi_dataset.py b/tests/data/test_patch_wsi_dataset.py index dd465731d6..3ed8007c8b 100644 --- a/tests/data/test_patch_wsi_dataset.py +++ b/tests/data/test_patch_wsi_dataset.py @@ -24,7 +24,7 @@ from monai.data.wsi_reader import CuCIMWSIReader, OpenSlideWSIReader from monai.utils import optional_import from monai.utils.enums import WSIPatchKeys -from tests.utils import download_url_or_skip_test, testing_data_config +from tests.utils.utils import download_url_or_skip_test, testing_data_config cucim, has_cim = optional_import("cucim") has_cim = has_cim and hasattr(cucim, "CuImage") diff --git a/tests/data/test_persistentdataset_dist.py b/tests/data/test_persistentdataset_dist.py index c369af9e92..46ee324890 100644 --- a/tests/data/test_persistentdataset_dist.py +++ b/tests/data/test_persistentdataset_dist.py @@ -21,7 +21,7 @@ from monai.data import PersistentDataset, json_hashing from monai.transforms import Transform -from tests.utils import DistCall, DistTestCase +from tests.utils.utils import DistCall, DistTestCase class _InplaceXform(Transform): diff --git a/tests/data/test_sampler_dist.py b/tests/data/test_sampler_dist.py index b8bd1c7a9f..50f44d39cf 100644 --- a/tests/data/test_sampler_dist.py +++ b/tests/data/test_sampler_dist.py @@ -20,7 +20,7 @@ from monai.data import CacheDataset, DataLoader, DistributedSampler from monai.transforms import ToTensor -from tests.utils import DistCall, DistTestCase, assert_allclose +from tests.utils.utils import DistCall, DistTestCase, assert_allclose class DistributedSamplerTest(DistTestCase): diff --git a/tests/data/test_shuffle_buffer.py b/tests/data/test_shuffle_buffer.py index e75321616b..66e75b34b4 100644 --- a/tests/data/test_shuffle_buffer.py +++ b/tests/data/test_shuffle_buffer.py @@ -18,7 +18,7 @@ from monai.data import DataLoader, ShuffleBuffer from monai.utils import convert_data_type -from tests.utils import SkipIfBeforePyTorchVersion +from tests.utils.utils import SkipIfBeforePyTorchVersion @SkipIfBeforePyTorchVersion((1, 12)) diff --git a/tests/data/test_sliding_patch_wsi_dataset.py b/tests/data/test_sliding_patch_wsi_dataset.py index d6b4138ac6..fa1ec720c7 100644 --- a/tests/data/test_sliding_patch_wsi_dataset.py +++ b/tests/data/test_sliding_patch_wsi_dataset.py @@ -22,7 +22,7 @@ from monai.data import SlidingPatchWSIDataset from monai.utils import WSIPatchKeys, optional_import, set_determinism -from tests.utils import download_url_or_skip_test, testing_data_config +from tests.utils.utils import download_url_or_skip_test, testing_data_config set_determinism(0) diff --git a/tests/data/test_smartcachedataset.py b/tests/data/test_smartcachedataset.py index bb43060469..1b163717cb 100644 --- a/tests/data/test_smartcachedataset.py +++ b/tests/data/test_smartcachedataset.py @@ -24,7 +24,7 @@ from monai.data import DataLoader, SmartCacheDataset from monai.transforms import Compose, Lambda, LoadImaged -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_1 = [0.1, 0, Compose([LoadImaged(keys=["image", "label", "extra"])])] diff --git a/tests/data/test_thread_buffer.py b/tests/data/test_thread_buffer.py index 2b7da2c0b0..6042a0dbf8 100644 --- a/tests/data/test_thread_buffer.py +++ b/tests/data/test_thread_buffer.py @@ -20,7 +20,7 @@ from monai.data import DataLoader, Dataset, ThreadBuffer, ThreadDataLoader from monai.transforms import Compose, SimulateDelayd from monai.utils import PerfContext, set_determinism -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class TestDataLoader(unittest.TestCase): diff --git a/tests/data/test_threadcontainer.py b/tests/data/test_threadcontainer.py index ffed62cb9c..748dcb4eda 100644 --- a/tests/data/test_threadcontainer.py +++ b/tests/data/test_threadcontainer.py @@ -22,7 +22,7 @@ from monai.data import DataLoader from monai.utils import optional_import, set_determinism from monai.utils.enums import CommonKeys -from tests.utils import SkipIfNoModule +from tests.utils.utils import SkipIfNoModule try: _, has_ignite = optional_import("ignite") diff --git a/tests/data/test_video_datasets.py b/tests/data/test_video_datasets.py index 86a126861e..f4493dd2c2 100644 --- a/tests/data/test_video_datasets.py +++ b/tests/data/test_video_datasets.py @@ -21,7 +21,7 @@ from monai.data.dataloader import DataLoader from monai.data.video_dataset import CameraDataset, VideoDataset, VideoFileDataset from monai.utils.module import optional_import -from tests.utils import assert_allclose, download_url_or_skip_test, testing_data_config +from tests.utils.utils import assert_allclose, download_url_or_skip_test, testing_data_config cv2, has_cv2 = optional_import("cv2") diff --git a/tests/data/test_weighted_random_sampler_dist.py b/tests/data/test_weighted_random_sampler_dist.py index 8e37482da6..fde5045db9 100644 --- a/tests/data/test_weighted_random_sampler_dist.py +++ b/tests/data/test_weighted_random_sampler_dist.py @@ -18,7 +18,7 @@ import torch.distributed as dist from monai.data import DistributedWeightedRandomSampler -from tests.utils import DistCall, DistTestCase, skip_if_darwin, skip_if_windows +from tests.utils.utils import DistCall, DistTestCase, skip_if_darwin, skip_if_windows @skip_if_windows diff --git a/tests/data/utils/test_decollate.py b/tests/data/utils/test_decollate.py index 92f7c89e28..7d7c185d9d 100644 --- a/tests/data/utils/test_decollate.py +++ b/tests/data/utils/test_decollate.py @@ -40,7 +40,7 @@ from monai.transforms.spatial.dictionary import RandAffined, RandRotate90d from monai.utils import optional_import, set_determinism from monai.utils.enums import PostFix, TraceKeys -from tests.utils import make_nifti_image +from tests.utils.utils import make_nifti_image _, has_nib = optional_import("nibabel") diff --git a/tests/data/utils/test_ori_ras_lps.py b/tests/data/utils/test_ori_ras_lps.py index 39c0a57877..c3977968ff 100644 --- a/tests/data/utils/test_ori_ras_lps.py +++ b/tests/data/utils/test_ori_ras_lps.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.data.utils import orientation_ras_lps -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TEST_CASES_AFFINE = [] for p in TEST_NDARRAYS: diff --git a/tests/engines/test_ensemble_evaluator.py b/tests/engines/test_ensemble_evaluator.py index ad81d35d52..17ca43bcef 100644 --- a/tests/engines/test_ensemble_evaluator.py +++ b/tests/engines/test_ensemble_evaluator.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.engines import EnsembleEvaluator -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_1 = [["pred_0", "pred_1", "pred_2", "pred_3", "pred_4"]] diff --git a/tests/engines/test_prepare_batch_default.py b/tests/engines/test_prepare_batch_default.py index 093468ce27..c3fdacf8c4 100644 --- a/tests/engines/test_prepare_batch_default.py +++ b/tests/engines/test_prepare_batch_default.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.engines import PrepareBatchDefault, SupervisedEvaluator -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class TestNet(torch.nn.Module): diff --git a/tests/engines/test_prepare_batch_default_dist.py b/tests/engines/test_prepare_batch_default_dist.py index 53a79575e6..c84b2c4175 100644 --- a/tests/engines/test_prepare_batch_default_dist.py +++ b/tests/engines/test_prepare_batch_default_dist.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.engines import PrepareBatchDefault, SupervisedEvaluator -from tests.utils import DistCall, DistTestCase, assert_allclose +from tests.utils.utils import DistCall, DistTestCase, assert_allclose TEST_CASE_1 = [ [ diff --git a/tests/engines/test_prepare_batch_extra_input.py b/tests/engines/test_prepare_batch_extra_input.py index 3c53cc6481..44b83ed775 100644 --- a/tests/engines/test_prepare_batch_extra_input.py +++ b/tests/engines/test_prepare_batch_extra_input.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.engines import PrepareBatchExtraInput, SupervisedEvaluator -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_0 = [ {"extra_keys": "extra1"}, diff --git a/tests/fl/client/monai_algo/test_fl_monai_algo.py b/tests/fl/client/monai_algo/test_fl_monai_algo.py index 27fee546be..af9e05a93d 100644 --- a/tests/fl/client/monai_algo/test_fl_monai_algo.py +++ b/tests/fl/client/monai_algo/test_fl_monai_algo.py @@ -27,7 +27,7 @@ from monai.fl.utils.constants import ExtraItems from monai.fl.utils.exchange_object import ExchangeObject from monai.utils import path_to_uri -from tests.utils import SkipIfNoModule +from tests.utils.utils import SkipIfNoModule _root_dir = Path(__file__).resolve().parents[3] _data_dir = os.path.join(_root_dir, "testing_data") diff --git a/tests/fl/client/monai_algo/test_fl_monai_algo_dist.py b/tests/fl/client/monai_algo/test_fl_monai_algo_dist.py index b98c5089a4..a57b6e9f18 100644 --- a/tests/fl/client/monai_algo/test_fl_monai_algo_dist.py +++ b/tests/fl/client/monai_algo/test_fl_monai_algo_dist.py @@ -23,7 +23,7 @@ from monai.fl.utils.constants import ExtraItems from monai.fl.utils.exchange_object import ExchangeObject from monai.networks import get_state_dict -from tests.utils import DistCall, DistTestCase, SkipIfBeforePyTorchVersion, SkipIfNoModule, skip_if_no_cuda +from tests.utils.utils import DistCall, DistTestCase, SkipIfBeforePyTorchVersion, SkipIfNoModule, skip_if_no_cuda TESTS_PATH = TESTS_PATH = Path(__file__).parents[3].as_posix() _root_dir = os.path.abspath(pathjoin(TESTS_PATH)) diff --git a/tests/fl/test_fl_monai_algo_stats.py b/tests/fl/test_fl_monai_algo_stats.py index a21d932232..2f3b8efb41 100644 --- a/tests/fl/test_fl_monai_algo_stats.py +++ b/tests/fl/test_fl_monai_algo_stats.py @@ -21,7 +21,7 @@ from monai.fl.client import MonaiAlgoStats from monai.fl.utils.constants import ExtraItems, FlStatistics from monai.fl.utils.exchange_object import ExchangeObject -from tests.utils import SkipIfNoModule +from tests.utils.utils import SkipIfNoModule _root_dir = Path(__file__).resolve().parents[1] _data_dir = os.path.join(_root_dir, "testing_data") diff --git a/tests/fl/utils/test_fl_exchange_object.py b/tests/fl/utils/test_fl_exchange_object.py index dab4eae037..77cca7aa48 100644 --- a/tests/fl/utils/test_fl_exchange_object.py +++ b/tests/fl/utils/test_fl_exchange_object.py @@ -19,7 +19,7 @@ from monai.fl.utils.constants import WeightType from monai.fl.utils.exchange_object import ExchangeObject from monai.utils.module import optional_import -from tests.utils import SkipIfNoModule +from tests.utils.utils import SkipIfNoModule models, has_torchvision = optional_import("torchvision.models") diff --git a/tests/handlers/test_handler_checkpoint_loader.py b/tests/handlers/test_handler_checkpoint_loader.py index 7b281665b4..24ec948562 100644 --- a/tests/handlers/test_handler_checkpoint_loader.py +++ b/tests/handlers/test_handler_checkpoint_loader.py @@ -19,7 +19,7 @@ from ignite.engine import Engine, Events from monai.handlers import CheckpointLoader, CheckpointSaver -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class TestHandlerCheckpointLoader(unittest.TestCase): diff --git a/tests/handlers/test_handler_classification_saver_dist.py b/tests/handlers/test_handler_classification_saver_dist.py index 47dca2d999..50372bd275 100644 --- a/tests/handlers/test_handler_classification_saver_dist.py +++ b/tests/handlers/test_handler_classification_saver_dist.py @@ -23,7 +23,7 @@ from monai.data import decollate_batch from monai.handlers import ClassificationSaver -from tests.utils import DistCall, DistTestCase +from tests.utils.utils import DistCall, DistTestCase class DistributedHandlerClassificationSaver(DistTestCase): diff --git a/tests/handlers/test_handler_confusion_matrix.py b/tests/handlers/test_handler_confusion_matrix.py index 5f3ee3ae97..a1c39d6ff4 100644 --- a/tests/handlers/test_handler_confusion_matrix.py +++ b/tests/handlers/test_handler_confusion_matrix.py @@ -19,7 +19,7 @@ from parameterized import parameterized from monai.handlers import ConfusionMatrix -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_1 = [{"include_background": True, "save_details": False, "metric_name": "f1"}, 0.75] TEST_CASE_2 = [{"include_background": False, "save_details": False, "metric_name": "ppv"}, 1.0] diff --git a/tests/handlers/test_handler_confusion_matrix_dist.py b/tests/handlers/test_handler_confusion_matrix_dist.py index dd30f04142..7e2f34ca80 100644 --- a/tests/handlers/test_handler_confusion_matrix_dist.py +++ b/tests/handlers/test_handler_confusion_matrix_dist.py @@ -19,7 +19,7 @@ from ignite.engine import Engine from monai.handlers import ConfusionMatrix -from tests.utils import DistCall, DistTestCase +from tests.utils.utils import DistCall, DistTestCase class DistributedConfusionMatrix(DistTestCase): diff --git a/tests/handlers/test_handler_decollate_batch.py b/tests/handlers/test_handler_decollate_batch.py index 37ca7f6870..95eb90b9d4 100644 --- a/tests/handlers/test_handler_decollate_batch.py +++ b/tests/handlers/test_handler_decollate_batch.py @@ -18,7 +18,7 @@ from monai.engines import SupervisedEvaluator from monai.handlers import DecollateBatch, PostProcessing from monai.transforms import Activationsd, AsDiscreted, Compose, CopyItemsd -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class TestHandlerDecollateBatch(unittest.TestCase): diff --git a/tests/handlers/test_handler_hausdorff_distance.py b/tests/handlers/test_handler_hausdorff_distance.py index 906db86d62..afe8156d55 100644 --- a/tests/handlers/test_handler_hausdorff_distance.py +++ b/tests/handlers/test_handler_hausdorff_distance.py @@ -18,7 +18,7 @@ from ignite.engine import Engine from monai.handlers import HausdorffDistance -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose def create_spherical_seg_3d( diff --git a/tests/handlers/test_handler_ignite_metric.py b/tests/handlers/test_handler_ignite_metric.py index 3e42bda35d..5cbf9d040d 100644 --- a/tests/handlers/test_handler_ignite_metric.py +++ b/tests/handlers/test_handler_ignite_metric.py @@ -19,7 +19,7 @@ from monai.handlers import IgniteMetricHandler, from_engine from monai.losses import DiceLoss from monai.metrics import LossMetric -from tests.utils import SkipIfNoModule, assert_allclose, optional_import +from tests.utils.utils import SkipIfNoModule, assert_allclose, optional_import try: _, has_ignite = optional_import("ignite") diff --git a/tests/handlers/test_handler_mean_dice.py b/tests/handlers/test_handler_mean_dice.py index 6f91b6d3af..a2c69ba988 100644 --- a/tests/handlers/test_handler_mean_dice.py +++ b/tests/handlers/test_handler_mean_dice.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.handlers import MeanDice, from_engine -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_1 = [{"include_background": True, "output_transform": from_engine(["pred", "label"])}, 0.75, (4, 2)] TEST_CASE_2 = [{"include_background": False, "output_transform": from_engine(["pred", "label"])}, 0.66666, (4, 1)] diff --git a/tests/handlers/test_handler_mean_iou.py b/tests/handlers/test_handler_mean_iou.py index 89dae3af58..8883b4af4f 100644 --- a/tests/handlers/test_handler_mean_iou.py +++ b/tests/handlers/test_handler_mean_iou.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.handlers import MeanIoUHandler, from_engine -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_1 = [{"include_background": True, "output_transform": from_engine(["pred", "label"])}, 0.75, (4, 2)] TEST_CASE_2 = [{"include_background": False, "output_transform": from_engine(["pred", "label"])}, 2 / 3, (4, 1)] diff --git a/tests/handlers/test_handler_metrics_reloaded.py b/tests/handlers/test_handler_metrics_reloaded.py index b8fb39d2e8..7f00bafa14 100644 --- a/tests/handlers/test_handler_metrics_reloaded.py +++ b/tests/handlers/test_handler_metrics_reloaded.py @@ -19,7 +19,7 @@ from monai.handlers import MetricsReloadedBinaryHandler, MetricsReloadedCategoricalHandler, from_engine from monai.utils import optional_import -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose _, has_metrics = optional_import("MetricsReloaded") diff --git a/tests/handlers/test_handler_metrics_saver_dist.py b/tests/handlers/test_handler_metrics_saver_dist.py index 96af35dbc9..ea71f2ed7c 100644 --- a/tests/handlers/test_handler_metrics_saver_dist.py +++ b/tests/handlers/test_handler_metrics_saver_dist.py @@ -23,7 +23,7 @@ from monai.handlers import MetricsSaver from monai.utils import evenly_divisible_all_gather from monai.utils.enums import PostFix -from tests.utils import DistCall, DistTestCase +from tests.utils.utils import DistCall, DistTestCase class DistributedMetricsSaver(DistTestCase): diff --git a/tests/handlers/test_handler_mlflow.py b/tests/handlers/test_handler_mlflow.py index 36d59ff1bf..a0f906c3e5 100644 --- a/tests/handlers/test_handler_mlflow.py +++ b/tests/handlers/test_handler_mlflow.py @@ -27,7 +27,7 @@ from monai.bundle import ConfigWorkflow, download from monai.handlers import MLFlowHandler from monai.utils import optional_import, path_to_uri -from tests.utils import skip_if_downloading_fails, skip_if_quick +from tests.utils.utils import skip_if_downloading_fails, skip_if_quick _, has_dataset_tracking = optional_import("mlflow", "2.4.0") diff --git a/tests/handlers/test_handler_nvtx.py b/tests/handlers/test_handler_nvtx.py index a0d1cdb4d5..608f3c03c0 100644 --- a/tests/handlers/test_handler_nvtx.py +++ b/tests/handlers/test_handler_nvtx.py @@ -21,7 +21,7 @@ from monai.handlers import StatsHandler, from_engine from monai.handlers.nvtx_handlers import MarkHandler, RangeHandler, RangePopHandler, RangePushHandler from monai.utils import optional_import -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose _, has_nvtx = optional_import("torch._C._nvtx", descriptor="NVTX is not installed. Are you sure you have a CUDA build?") diff --git a/tests/handlers/test_handler_panoptic_quality.py b/tests/handlers/test_handler_panoptic_quality.py index 337f9c7b49..0a0bf679e5 100644 --- a/tests/handlers/test_handler_panoptic_quality.py +++ b/tests/handlers/test_handler_panoptic_quality.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.handlers import PanopticQuality, from_engine -from tests.utils import SkipIfNoModule, assert_allclose +from tests.utils.utils import SkipIfNoModule, assert_allclose sample_1_pred = torch.as_tensor( [[[0, 1, 1, 1], [0, 0, 5, 5], [2, 0, 3, 3], [2, 2, 2, 0]], [[0, 1, 1, 1], [0, 0, 0, 0], [2, 0, 3, 3], [4, 2, 2, 0]]] diff --git a/tests/handlers/test_handler_parameter_scheduler.py b/tests/handlers/test_handler_parameter_scheduler.py index 0bcc794381..91a8f1f428 100644 --- a/tests/handlers/test_handler_parameter_scheduler.py +++ b/tests/handlers/test_handler_parameter_scheduler.py @@ -17,7 +17,7 @@ from torch.nn import Module from monai.handlers.parameter_scheduler import ParamSchedulerHandler -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class ToyNet(Module): diff --git a/tests/handlers/test_handler_post_processing.py b/tests/handlers/test_handler_post_processing.py index 0dd518325b..4e297a9a14 100644 --- a/tests/handlers/test_handler_post_processing.py +++ b/tests/handlers/test_handler_post_processing.py @@ -19,7 +19,7 @@ from monai.engines import SupervisedEvaluator from monai.handlers import PostProcessing from monai.transforms import Activationsd, AsDiscreted, Compose, CopyItemsd -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose # test lambda function as `transform` TEST_CASE_1 = [{"transform": lambda x: dict(pred=x["pred"] + 1.0)}, False, torch.tensor([[[[1.9975], [1.9997]]]])] diff --git a/tests/handlers/test_handler_regression_metrics_dist.py b/tests/handlers/test_handler_regression_metrics_dist.py index f57db429e8..f842b1abea 100644 --- a/tests/handlers/test_handler_regression_metrics_dist.py +++ b/tests/handlers/test_handler_regression_metrics_dist.py @@ -20,7 +20,7 @@ from monai.handlers import MeanAbsoluteError, MeanSquaredError, PeakSignalToNoiseRatio, RootMeanSquaredError from monai.utils import set_determinism -from tests.utils import DistCall, DistTestCase +from tests.utils.utils import DistCall, DistTestCase # define a numpy flatten function that only preserves batch dimension diff --git a/tests/handlers/test_handler_rocauc_dist.py b/tests/handlers/test_handler_rocauc_dist.py index 6088251b11..3c7b5be7aa 100644 --- a/tests/handlers/test_handler_rocauc_dist.py +++ b/tests/handlers/test_handler_rocauc_dist.py @@ -19,7 +19,7 @@ from monai.handlers import ROCAUC from monai.transforms import Activations, AsDiscrete -from tests.utils import DistCall, DistTestCase +from tests.utils.utils import DistCall, DistTestCase class DistributedROCAUC(DistTestCase): diff --git a/tests/handlers/test_handler_surface_distance.py b/tests/handlers/test_handler_surface_distance.py index 736f7e251a..324efd0645 100644 --- a/tests/handlers/test_handler_surface_distance.py +++ b/tests/handlers/test_handler_surface_distance.py @@ -18,7 +18,7 @@ from ignite.engine import Engine from monai.handlers import SurfaceDistance -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose def create_spherical_seg_3d( diff --git a/tests/handlers/test_handler_tb_image.py b/tests/handlers/test_handler_tb_image.py index 197b175278..67d4789a3c 100644 --- a/tests/handlers/test_handler_tb_image.py +++ b/tests/handlers/test_handler_tb_image.py @@ -23,7 +23,7 @@ from monai.data import decollate_batch from monai.handlers import TensorBoardImageHandler from monai.utils import optional_import -from tests.utils import SkipIfBeforePyTorchVersion +from tests.utils.utils import SkipIfBeforePyTorchVersion _, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") diff --git a/tests/handlers/test_trt_compile.py b/tests/handlers/test_trt_compile.py index f7779fec9b..fac75ac09e 100644 --- a/tests/handlers/test_trt_compile.py +++ b/tests/handlers/test_trt_compile.py @@ -21,7 +21,7 @@ from monai.networks import trt_compile from monai.networks.nets import cell_sam_wrapper, vista3d132 from monai.utils import min_version, optional_import -from tests.utils import SkipIfBeforeComputeCapabilityVersion, skip_if_no_cuda, skip_if_quick, skip_if_windows +from tests.utils.utils import SkipIfBeforeComputeCapabilityVersion, skip_if_no_cuda, skip_if_quick, skip_if_windows trt, trt_imported = optional_import("tensorrt", "10.1.0", min_version) torch_tensorrt, torch_trt_imported = optional_import("torch_tensorrt") diff --git a/tests/hvd_evenly_divisible_all_gather.py b/tests/hvd_evenly_divisible_all_gather.py index 732ad13b83..ccee73c940 100644 --- a/tests/hvd_evenly_divisible_all_gather.py +++ b/tests/hvd_evenly_divisible_all_gather.py @@ -15,7 +15,7 @@ from monai.utils import evenly_divisible_all_gather from monai.utils.module import optional_import -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose hvd, has_hvd = optional_import("horovod", name="torch") diff --git a/tests/inferers/test_avg_merger.py b/tests/inferers/test_avg_merger.py index 7995d63271..3f4e5b8402 100644 --- a/tests/inferers/test_avg_merger.py +++ b/tests/inferers/test_avg_merger.py @@ -18,7 +18,7 @@ from torch.nn.functional import pad from monai.inferers import AvgMerger -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TENSOR_4x4 = torch.randint(low=0, high=255, size=(2, 3, 4, 4), dtype=torch.float32) TENSOR_4x4_WITH_NAN = TENSOR_4x4.clone() diff --git a/tests/inferers/test_patch_inferer.py b/tests/inferers/test_patch_inferer.py index c6308224b0..ad27feb917 100644 --- a/tests/inferers/test_patch_inferer.py +++ b/tests/inferers/test_patch_inferer.py @@ -19,7 +19,7 @@ from monai.data.meta_tensor import MetaTensor from monai.inferers import AvgMerger, PatchInferer, SlidingWindowSplitter -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TENSOR_4x4 = torch.randint(low=0, high=255, size=(2, 3, 4, 4), dtype=torch.float32) TENSOR_2x2 = avg_pool2d(TENSOR_4x4, 2, 2) diff --git a/tests/inferers/test_sliding_window_inference.py b/tests/inferers/test_sliding_window_inference.py index 33b38a5bc7..f389977683 100644 --- a/tests/inferers/test_sliding_window_inference.py +++ b/tests/inferers/test_sliding_window_inference.py @@ -21,7 +21,7 @@ from monai.data.utils import list_data_collate from monai.inferers import SlidingWindowInferer, SlidingWindowInfererAdapt, sliding_window_inference from monai.utils import optional_import -from tests.utils import TEST_TORCH_AND_META_TENSORS, skip_if_no_cuda, test_is_quick +from tests.utils.utils import TEST_TORCH_AND_META_TENSORS, skip_if_no_cuda, test_is_quick _, has_tqdm = optional_import("tqdm") diff --git a/tests/inferers/test_sliding_window_splitter.py b/tests/inferers/test_sliding_window_splitter.py index ad136c61a4..6335810d0a 100644 --- a/tests/inferers/test_sliding_window_splitter.py +++ b/tests/inferers/test_sliding_window_splitter.py @@ -18,7 +18,7 @@ from torch.nn.functional import pad from monai.inferers import SlidingWindowSplitter -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose # ---------------------------------------------------------------------------- # Tensor test cases diff --git a/tests/inferers/test_wsi_sliding_window_splitter.py b/tests/inferers/test_wsi_sliding_window_splitter.py index f917f0358a..b707ae3cab 100644 --- a/tests/inferers/test_wsi_sliding_window_splitter.py +++ b/tests/inferers/test_wsi_sliding_window_splitter.py @@ -21,7 +21,7 @@ from monai.data import CuCIMWSIReader, ImageReader, OpenSlideWSIReader, WSIReader from monai.inferers import WSISlidingWindowSplitter -from tests.utils import download_url_or_skip_test, optional_import, testing_data_config +from tests.utils.utils import download_url_or_skip_test, optional_import, testing_data_config cucim, has_cucim = optional_import("cucim") has_cucim = has_cucim and hasattr(cucim, "CuImage") diff --git a/tests/inferers/test_zarr_avg_merger.py b/tests/inferers/test_zarr_avg_merger.py index de7fad48da..b2b840926e 100644 --- a/tests/inferers/test_zarr_avg_merger.py +++ b/tests/inferers/test_zarr_avg_merger.py @@ -20,7 +20,7 @@ from monai.inferers import ZarrAvgMerger from monai.utils import optional_import -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose np.seterr(divide="ignore", invalid="ignore") zarr, has_zarr = optional_import("zarr") diff --git a/tests/integration/test_auto3dseg_ensemble.py b/tests/integration/test_auto3dseg_ensemble.py index 7ac553cc0c..823615ee7d 100644 --- a/tests/integration/test_auto3dseg_ensemble.py +++ b/tests/integration/test_auto3dseg_ensemble.py @@ -32,7 +32,7 @@ from monai.transforms import SaveImage from monai.utils import check_parent_dir, optional_import, set_determinism from monai.utils.enums import AlgoKeys -from tests.utils import ( +from tests.utils.utils import ( SkipIfBeforePyTorchVersion, get_testing_algo_template_path, skip_if_downloading_fails, diff --git a/tests/integration/test_auto3dseg_hpo.py b/tests/integration/test_auto3dseg_hpo.py index 53d09defa0..7ee3f3bacc 100644 --- a/tests/integration/test_auto3dseg_hpo.py +++ b/tests/integration/test_auto3dseg_hpo.py @@ -25,7 +25,7 @@ from monai.data import create_test_image_3d from monai.utils import optional_import from monai.utils.enums import AlgoKeys -from tests.utils import ( +from tests.utils.utils import ( SkipIfBeforePyTorchVersion, get_testing_algo_template_path, skip_if_downloading_fails, diff --git a/tests/integration/test_hovernet_nuclear_type_post_processingd.py b/tests/integration/test_hovernet_nuclear_type_post_processingd.py index 26cf80592c..2fd8e65a60 100644 --- a/tests/integration/test_hovernet_nuclear_type_post_processingd.py +++ b/tests/integration/test_hovernet_nuclear_type_post_processingd.py @@ -23,7 +23,7 @@ from monai.transforms import ComputeHoVerMaps from monai.utils import min_version, optional_import from monai.utils.enums import HoVerNetBranch -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose _, has_scipy = optional_import("scipy", "1.8.1", min_version) _, has_skimage = optional_import("skimage", "0.19.3", min_version) diff --git a/tests/integration/test_image_rw.py b/tests/integration/test_image_rw.py index 7e1c1deecc..77fcd5ff63 100644 --- a/tests/integration/test_image_rw.py +++ b/tests/integration/test_image_rw.py @@ -26,7 +26,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import LoadImage, SaveImage, moveaxis from monai.utils import MetaKeys, OptionalImportError, optional_import -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose _, has_itk = optional_import("itk", allow_namespace_pkg=True) diff --git a/tests/integration/test_integration_autorunner.py b/tests/integration/test_integration_autorunner.py index 31a0813abc..34506b2384 100644 --- a/tests/integration/test_integration_autorunner.py +++ b/tests/integration/test_integration_autorunner.py @@ -23,7 +23,7 @@ from monai.bundle.config_parser import ConfigParser from monai.data import create_test_image_3d from monai.utils import optional_import -from tests.utils import ( +from tests.utils.utils import ( SkipIfBeforePyTorchVersion, get_testing_algo_template_path, skip_if_downloading_fails, diff --git a/tests/integration/test_integration_bundle_run.py b/tests/integration/test_integration_bundle_run.py index 0454a3a549..8d3733f4d0 100644 --- a/tests/integration/test_integration_bundle_run.py +++ b/tests/integration/test_integration_bundle_run.py @@ -30,7 +30,7 @@ from monai.bundle.utils import DEFAULT_HANDLERS_ID from monai.transforms import LoadImage from monai.utils import path_to_uri -from tests.utils import command_line_tests +from tests.utils.utils import command_line_tests TESTS_PATH = Path(__file__).parents[1] TEST_CASE_1 = [os.path.join(TESTS_PATH, "testing_data", "inference.json"), (128, 128, 128)] diff --git a/tests/integration/test_integration_classification_2d.py b/tests/integration/test_integration_classification_2d.py index 159f3bd911..14f9d1f3fd 100644 --- a/tests/integration/test_integration_classification_2d.py +++ b/tests/integration/test_integration_classification_2d.py @@ -39,7 +39,7 @@ ) from monai.utils import set_determinism from tests.testing_data.integration_answers import test_integration_value -from tests.utils import DistTestCase, TimedCall, skip_if_downloading_fails, skip_if_quick, testing_data_config +from tests.utils.utils import DistTestCase, TimedCall, skip_if_downloading_fails, skip_if_quick, testing_data_config TASK = "integration_classification_2d" diff --git a/tests/integration/test_integration_determinism.py b/tests/integration/test_integration_determinism.py index 3e88f05620..b5251228b4 100644 --- a/tests/integration/test_integration_determinism.py +++ b/tests/integration/test_integration_determinism.py @@ -22,7 +22,7 @@ from monai.networks.nets import UNet from monai.transforms import Compose, EnsureChannelFirst, RandRotate90, RandSpatialCrop, ScaleIntensity from monai.utils import set_determinism -from tests.utils import DistTestCase, TimedCall +from tests.utils.utils import DistTestCase, TimedCall def run_test(batch_size=64, train_steps=200, device="cuda:0"): diff --git a/tests/integration/test_integration_fast_train.py b/tests/integration/test_integration_fast_train.py index 071eb5cf78..12ee9406c5 100644 --- a/tests/integration/test_integration_fast_train.py +++ b/tests/integration/test_integration_fast_train.py @@ -52,7 +52,7 @@ ToDeviced, ) from monai.utils import set_determinism -from tests.utils import DistTestCase, TimedCall, skip_if_no_cuda, skip_if_quick +from tests.utils.utils import DistTestCase, TimedCall, skip_if_no_cuda, skip_if_quick @skip_if_no_cuda diff --git a/tests/integration/test_integration_gpu_customization.py b/tests/integration/test_integration_gpu_customization.py index 043405a580..af21543e88 100644 --- a/tests/integration/test_integration_gpu_customization.py +++ b/tests/integration/test_integration_gpu_customization.py @@ -24,7 +24,7 @@ from monai.data import create_test_image_3d from monai.utils import optional_import from monai.utils.enums import AlgoKeys -from tests.utils import ( +from tests.utils.utils import ( SkipIfBeforePyTorchVersion, get_testing_algo_template_path, skip_if_downloading_fails, diff --git a/tests/integration/test_integration_lazy_samples.py b/tests/integration/test_integration_lazy_samples.py index 51d80e7305..fa3f22ae7e 100644 --- a/tests/integration/test_integration_lazy_samples.py +++ b/tests/integration/test_integration_lazy_samples.py @@ -26,7 +26,7 @@ from monai.data import create_test_image_3d, decollate_batch from monai.transforms.utils import has_status_keys from monai.utils import TraceStatusKeys, set_determinism -from tests.utils import HAS_CUPY, DistTestCase, SkipIfBeforePyTorchVersion, skip_if_quick +from tests.utils.utils import HAS_CUPY, DistTestCase, SkipIfBeforePyTorchVersion, skip_if_quick def _no_op(x): diff --git a/tests/integration/test_integration_nnunetv2_runner.py b/tests/integration/test_integration_nnunetv2_runner.py index 822d454f52..8925663f0e 100644 --- a/tests/integration/test_integration_nnunetv2_runner.py +++ b/tests/integration/test_integration_nnunetv2_runner.py @@ -22,7 +22,7 @@ from monai.bundle.config_parser import ConfigParser from monai.data import create_test_image_3d from monai.utils import optional_import -from tests.utils import SkipIfBeforePyTorchVersion, skip_if_downloading_fails, skip_if_no_cuda, skip_if_quick +from tests.utils.utils import SkipIfBeforePyTorchVersion, skip_if_downloading_fails, skip_if_no_cuda, skip_if_quick _, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") _, has_nnunet = optional_import("nnunetv2") diff --git a/tests/integration/test_integration_segmentation_3d.py b/tests/integration/test_integration_segmentation_3d.py index 270a7487fb..4e2e86228e 100644 --- a/tests/integration/test_integration_segmentation_3d.py +++ b/tests/integration/test_integration_segmentation_3d.py @@ -42,7 +42,7 @@ from monai.utils import optional_import, set_determinism from monai.visualize import plot_2d_or_3d_image from tests.testing_data.integration_answers import test_integration_value -from tests.utils import DistTestCase, TimedCall, skip_if_quick +from tests.utils.utils import DistTestCase, TimedCall, skip_if_quick SummaryWriter, _ = optional_import("torch.utils.tensorboard", name="SummaryWriter") diff --git a/tests/integration/test_integration_sliding_window.py b/tests/integration/test_integration_sliding_window.py index 8b53e94941..de92f0a68f 100644 --- a/tests/integration/test_integration_sliding_window.py +++ b/tests/integration/test_integration_sliding_window.py @@ -27,7 +27,7 @@ from monai.networks.nets import UNet from monai.transforms import EnsureChannelFirst, SaveImage from monai.utils import pytorch_after, set_determinism -from tests.utils import DistTestCase, TimedCall, make_nifti_image, skip_if_quick +from tests.utils.utils import DistTestCase, TimedCall, make_nifti_image, skip_if_quick def run_test(batch_size, img_name, seg_name, output_dir, device="cuda:0"): diff --git a/tests/integration/test_integration_stn.py b/tests/integration/test_integration_stn.py index 750a20ea5c..9fba0cd6d7 100644 --- a/tests/integration/test_integration_stn.py +++ b/tests/integration/test_integration_stn.py @@ -22,7 +22,7 @@ from monai.data import create_test_image_2d from monai.networks.layers import AffineTransform from monai.utils import set_determinism -from tests.utils import DistTestCase, TimedCall +from tests.utils.utils import DistTestCase, TimedCall class STNBenchmark(nn.Module): diff --git a/tests/integration/test_integration_unet_2d.py b/tests/integration/test_integration_unet_2d.py index 3b40682de0..dbc6942773 100644 --- a/tests/integration/test_integration_unet_2d.py +++ b/tests/integration/test_integration_unet_2d.py @@ -21,7 +21,7 @@ from monai.data import create_test_image_2d from monai.losses import DiceLoss from monai.networks.nets import BasicUNet, UNet -from tests.utils import DistTestCase, TimedCall, skip_if_quick +from tests.utils.utils import DistTestCase, TimedCall, skip_if_quick def run_test(net_name="basicunet", batch_size=64, train_steps=100, device="cuda:0"): diff --git a/tests/integration/test_integration_workers.py b/tests/integration/test_integration_workers.py index 123b1ddc6f..6c4627f74e 100644 --- a/tests/integration/test_integration_workers.py +++ b/tests/integration/test_integration_workers.py @@ -18,7 +18,7 @@ from monai.data import DataLoader from monai.utils import set_determinism -from tests.utils import DistTestCase, SkipIfBeforePyTorchVersion, TimedCall, skip_if_no_cuda, skip_if_quick +from tests.utils.utils import DistTestCase, SkipIfBeforePyTorchVersion, TimedCall, skip_if_no_cuda, skip_if_quick def run_loading_test(num_workers=50, device=None, pw=False): diff --git a/tests/integration/test_integration_workflows.py b/tests/integration/test_integration_workflows.py index fafb66f675..e058743599 100644 --- a/tests/integration/test_integration_workflows.py +++ b/tests/integration/test_integration_workflows.py @@ -54,7 +54,7 @@ ) from monai.utils import optional_import, set_determinism from tests.testing_data.integration_answers import test_integration_value -from tests.utils import DistTestCase, TimedCall, assert_allclose, pytorch_after, skip_if_quick +from tests.utils.utils import DistTestCase, TimedCall, assert_allclose, pytorch_after, skip_if_quick SummaryWriter, _ = optional_import("torch.utils.tensorboard", name="SummaryWriter") diff --git a/tests/integration/test_integration_workflows_adversarial.py b/tests/integration/test_integration_workflows_adversarial.py index f323fc9917..c71778ad43 100644 --- a/tests/integration/test_integration_workflows_adversarial.py +++ b/tests/integration/test_integration_workflows_adversarial.py @@ -28,7 +28,7 @@ from monai.transforms import Compose, EnsureChannelFirstd, LoadImaged, RandFlipd, ScaleIntensityd from monai.utils import AdversarialKeys as Keys from monai.utils import CommonKeys, optional_import, set_determinism -from tests.utils import DistTestCase, TimedCall, skip_if_quick +from tests.utils.utils import DistTestCase, TimedCall, skip_if_quick nib, has_nibabel = optional_import("nibabel") diff --git a/tests/integration/test_integration_workflows_gan.py b/tests/integration/test_integration_workflows_gan.py index 1428506020..5590274833 100644 --- a/tests/integration/test_integration_workflows_gan.py +++ b/tests/integration/test_integration_workflows_gan.py @@ -30,7 +30,7 @@ from monai.transforms import Compose, EnsureChannelFirstd, LoadImaged, RandFlipd, ScaleIntensityd from monai.utils import GanKeys as Keys from monai.utils import set_determinism -from tests.utils import DistTestCase, TimedCall, skip_if_quick +from tests.utils.utils import DistTestCase, TimedCall, skip_if_quick def run_training_test(root_dir, device="cuda:0"): diff --git a/tests/integration/test_meta_affine.py b/tests/integration/test_meta_affine.py index b50ce6792f..32ae5b8fba 100644 --- a/tests/integration/test_meta_affine.py +++ b/tests/integration/test_meta_affine.py @@ -35,7 +35,7 @@ Transform, ) from monai.utils import convert_data_type, optional_import -from tests.utils import assert_allclose, download_url_or_skip_test, testing_data_config +from tests.utils.utils import assert_allclose, download_url_or_skip_test, testing_data_config itk, has_itk = optional_import("itk") TINY_DIFF = 1e-4 diff --git a/tests/integration/test_metatensor_integration.py b/tests/integration/test_metatensor_integration.py index 054d8cce87..8f07fa12b2 100644 --- a/tests/integration/test_metatensor_integration.py +++ b/tests/integration/test_metatensor_integration.py @@ -26,7 +26,7 @@ from monai.data.utils import TraceKeys from monai.transforms import InvertD, SaveImageD, reset_ops_id from monai.utils import optional_import, set_determinism -from tests.utils import assert_allclose, download_url_or_skip_test, testing_data_config +from tests.utils.utils import assert_allclose, download_url_or_skip_test, testing_data_config nib, has_nib = optional_import("nibabel") TINY_DIFF = 0.1 diff --git a/tests/integration/test_reg_loss_integration.py b/tests/integration/test_reg_loss_integration.py index 8afc2da6ad..04b7c6bee6 100644 --- a/tests/integration/test_reg_loss_integration.py +++ b/tests/integration/test_reg_loss_integration.py @@ -19,7 +19,7 @@ from parameterized import parameterized from monai.losses import BendingEnergyLoss, GlobalMutualInformationLoss, LocalNormalizedCrossCorrelationLoss -from tests.utils import SkipIfBeforePyTorchVersion +from tests.utils.utils import SkipIfBeforePyTorchVersion TEST_CASES = [ [BendingEnergyLoss, {}, ["pred"], 3], diff --git a/tests/integration/test_spatial_combine_transforms.py b/tests/integration/test_spatial_combine_transforms.py index 8479e9084b..ae808733f1 100644 --- a/tests/integration/test_spatial_combine_transforms.py +++ b/tests/integration/test_spatial_combine_transforms.py @@ -24,7 +24,7 @@ from monai.transforms.transform import MapTransform from monai.utils import set_determinism from tests.lazy_transforms_utils import get_apply_param -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_2D = [ [ diff --git a/tests/integration/test_testtimeaugmentation.py b/tests/integration/test_testtimeaugmentation.py index 746ad122b2..8d63201aa8 100644 --- a/tests/integration/test_testtimeaugmentation.py +++ b/tests/integration/test_testtimeaugmentation.py @@ -37,7 +37,7 @@ from monai.transforms.spatial.dictionary import RandFlipd from monai.utils import optional_import, set_determinism from monai.utils.enums import PostFix -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS if TYPE_CHECKING: import tqdm diff --git a/tests/integration/test_vista3d_utils.py b/tests/integration/test_vista3d_utils.py index 5a0caedd61..96fea03f51 100644 --- a/tests/integration/test_vista3d_utils.py +++ b/tests/integration/test_vista3d_utils.py @@ -21,7 +21,7 @@ from monai.transforms.utils import convert_points_to_disc, keep_merge_components_with_points, sample_points_from_label from monai.utils import min_version from monai.utils.module import optional_import -from tests.utils import skip_if_no_cuda, skip_if_quick +from tests.utils.utils import skip_if_no_cuda, skip_if_quick cp, has_cp = optional_import("cupy") cucim_skimage, has_cucim = optional_import("cucim.skimage") diff --git a/tests/lazy_transforms_utils.py b/tests/lazy_transforms_utils.py index 1681e26037..706bd9f7a6 100644 --- a/tests/lazy_transforms_utils.py +++ b/tests/lazy_transforms_utils.py @@ -16,7 +16,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import InvertibleTransform, MapTransform, Randomizable from monai.transforms.lazy.functional import apply_pending -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose apply_transforms_kwargs = ("pending", "mode", "padding_mode", "dtype", "align_corners") diff --git a/tests/losses/image_dissimilarity/test_global_mutual_information_loss.py b/tests/losses/image_dissimilarity/test_global_mutual_information_loss.py index ec3876887b..77a43a5ee5 100644 --- a/tests/losses/image_dissimilarity/test_global_mutual_information_loss.py +++ b/tests/losses/image_dissimilarity/test_global_mutual_information_loss.py @@ -20,7 +20,7 @@ from monai import transforms from monai.losses.image_dissimilarity import GlobalMutualInformationLoss -from tests.utils import SkipIfBeforePyTorchVersion, download_url_or_skip_test, skip_if_quick, testing_data_config +from tests.utils.utils import SkipIfBeforePyTorchVersion, download_url_or_skip_test, skip_if_quick, testing_data_config device = "cuda:0" if torch.cuda.is_available() else "cpu" diff --git a/tests/losses/test_dice_focal_loss.py b/tests/losses/test_dice_focal_loss.py index f769aac69f..20318190a2 100644 --- a/tests/losses/test_dice_focal_loss.py +++ b/tests/losses/test_dice_focal_loss.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.losses import DiceFocalLoss, DiceLoss, FocalLoss -from tests.utils import test_script_save +from tests.utils.utils import test_script_save class TestDiceFocalLoss(unittest.TestCase): diff --git a/tests/losses/test_dice_loss.py b/tests/losses/test_dice_loss.py index cea6ccf113..bce7a4417b 100644 --- a/tests/losses/test_dice_loss.py +++ b/tests/losses/test_dice_loss.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.losses import DiceLoss -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_CASES = [ [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) diff --git a/tests/losses/test_ds_loss.py b/tests/losses/test_ds_loss.py index daa4ed1e5e..cb1203d9f3 100644 --- a/tests/losses/test_ds_loss.py +++ b/tests/losses/test_ds_loss.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.losses import DeepSupervisionLoss, DiceCELoss, DiceFocalLoss, DiceLoss -from tests.utils import SkipIfBeforePyTorchVersion, test_script_save +from tests.utils.utils import SkipIfBeforePyTorchVersion, test_script_save TEST_CASES_DICECE = [ [ diff --git a/tests/losses/test_focal_loss.py b/tests/losses/test_focal_loss.py index 0bb8a078ae..f2e536e979 100644 --- a/tests/losses/test_focal_loss.py +++ b/tests/losses/test_focal_loss.py @@ -21,7 +21,7 @@ from monai.losses import FocalLoss from monai.networks import one_hot -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_CASES = [] for device in ["cpu", "cuda"] if torch.cuda.is_available() else ["cpu"]: diff --git a/tests/losses/test_generalized_dice_focal_loss.py b/tests/losses/test_generalized_dice_focal_loss.py index 65252611ca..0984bb3954 100644 --- a/tests/losses/test_generalized_dice_focal_loss.py +++ b/tests/losses/test_generalized_dice_focal_loss.py @@ -17,7 +17,7 @@ import torch from monai.losses import FocalLoss, GeneralizedDiceFocalLoss, GeneralizedDiceLoss -from tests.utils import test_script_save +from tests.utils.utils import test_script_save class TestGeneralizedDiceFocalLoss(unittest.TestCase): diff --git a/tests/losses/test_generalized_dice_loss.py b/tests/losses/test_generalized_dice_loss.py index 9706c2e746..beec5de221 100644 --- a/tests/losses/test_generalized_dice_loss.py +++ b/tests/losses/test_generalized_dice_loss.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.losses import GeneralizedDiceLoss -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_CASES = [ [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) diff --git a/tests/losses/test_generalized_wasserstein_dice_loss.py b/tests/losses/test_generalized_wasserstein_dice_loss.py index 6b9d57e831..48851a55b9 100644 --- a/tests/losses/test_generalized_wasserstein_dice_loss.py +++ b/tests/losses/test_generalized_wasserstein_dice_loss.py @@ -20,7 +20,7 @@ import torch.optim as optim from monai.losses import GeneralizedWassersteinDiceLoss -from tests.utils import test_script_save +from tests.utils.utils import test_script_save class TestGeneralizedWassersteinDiceLoss(unittest.TestCase): diff --git a/tests/losses/test_masked_loss.py b/tests/losses/test_masked_loss.py index 3c04ffadcb..56fd7d73a8 100644 --- a/tests/losses/test_masked_loss.py +++ b/tests/losses/test_masked_loss.py @@ -19,7 +19,7 @@ from monai.losses.dice import DiceFocalLoss, DiceLoss from monai.losses.spatial_mask import MaskedLoss from monai.utils import set_determinism -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/losses/test_multi_scale.py b/tests/losses/test_multi_scale.py index 0b49087216..1f703518e9 100644 --- a/tests/losses/test_multi_scale.py +++ b/tests/losses/test_multi_scale.py @@ -18,7 +18,7 @@ from monai.losses import DiceLoss from monai.losses.multi_scale import MultiScaleLoss -from tests.utils import test_script_save +from tests.utils.utils import test_script_save dice_loss = DiceLoss(include_background=True, sigmoid=True, smooth_nr=1e-5, smooth_dr=1e-5) device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/losses/test_perceptual_loss.py b/tests/losses/test_perceptual_loss.py index b8aa2e5982..a3137a243e 100644 --- a/tests/losses/test_perceptual_loss.py +++ b/tests/losses/test_perceptual_loss.py @@ -18,7 +18,7 @@ from monai.losses import PerceptualLoss from monai.utils import optional_import -from tests.utils import SkipIfBeforePyTorchVersion, assert_allclose, skip_if_downloading_fails, skip_if_quick +from tests.utils.utils import SkipIfBeforePyTorchVersion, assert_allclose, skip_if_downloading_fails, skip_if_quick _, has_torchvision = optional_import("torchvision") TEST_CASES = [ diff --git a/tests/losses/test_spectral_loss.py b/tests/losses/test_spectral_loss.py index f62ae9030b..915c4546fb 100644 --- a/tests/losses/test_spectral_loss.py +++ b/tests/losses/test_spectral_loss.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.losses import JukeboxLoss -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_CASES = [ [ diff --git a/tests/losses/test_tversky_loss.py b/tests/losses/test_tversky_loss.py index 73a841a55d..092883f374 100644 --- a/tests/losses/test_tversky_loss.py +++ b/tests/losses/test_tversky_loss.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.losses import TverskyLoss -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_CASES = [ [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) diff --git a/tests/metrics/test_compute_confusion_matrix.py b/tests/metrics/test_compute_confusion_matrix.py index 248f16a7fe..d96d35961c 100644 --- a/tests/metrics/test_compute_confusion_matrix.py +++ b/tests/metrics/test_compute_confusion_matrix.py @@ -24,7 +24,7 @@ do_metric_reduction, get_confusion_matrix, ) -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose _device = "cuda:0" if torch.cuda.is_available() else "cpu" # input data diff --git a/tests/metrics/test_compute_f_beta.py b/tests/metrics/test_compute_f_beta.py index be2a7fc176..e1bf0da322 100644 --- a/tests/metrics/test_compute_f_beta.py +++ b/tests/metrics/test_compute_f_beta.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.metrics import FBetaScore -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose _device = "cuda:0" if torch.cuda.is_available() else "cpu" diff --git a/tests/metrics/test_compute_panoptic_quality.py b/tests/metrics/test_compute_panoptic_quality.py index a915eb64f9..782c3766f3 100644 --- a/tests/metrics/test_compute_panoptic_quality.py +++ b/tests/metrics/test_compute_panoptic_quality.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.metrics import PanopticQualityMetric, compute_panoptic_quality -from tests.utils import SkipIfNoModule +from tests.utils.utils import SkipIfNoModule _device = "cuda:0" if torch.cuda.is_available() else "cpu" diff --git a/tests/metrics/test_cumulative.py b/tests/metrics/test_cumulative.py index d3b6ba094c..ace1483703 100644 --- a/tests/metrics/test_cumulative.py +++ b/tests/metrics/test_cumulative.py @@ -16,7 +16,7 @@ import torch from monai.metrics import Cumulative -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class TestCumulative(unittest.TestCase): diff --git a/tests/metrics/test_cumulative_average_dist.py b/tests/metrics/test_cumulative_average_dist.py index 30c01c21ee..fe79948b33 100644 --- a/tests/metrics/test_cumulative_average_dist.py +++ b/tests/metrics/test_cumulative_average_dist.py @@ -18,7 +18,7 @@ import torch.distributed as dist from monai.metrics import CumulativeAverage -from tests.utils import DistCall, DistTestCase, SkipIfBeforePyTorchVersion +from tests.utils.utils import DistCall, DistTestCase, SkipIfBeforePyTorchVersion @SkipIfBeforePyTorchVersion((1, 8)) diff --git a/tests/metrics/test_surface_dice.py b/tests/metrics/test_surface_dice.py index 2ef19a4eea..e09be103f5 100644 --- a/tests/metrics/test_surface_dice.py +++ b/tests/metrics/test_surface_dice.py @@ -18,7 +18,7 @@ import torch.nn.functional as F from monai.metrics.surface_dice import SurfaceDiceMetric, compute_surface_dice -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose _device = "cuda:0" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/blocks/test_adn.py b/tests/networks/blocks/test_adn.py index 327bf7b20c..db482a5b21 100644 --- a/tests/networks/blocks/test_adn.py +++ b/tests/networks/blocks/test_adn.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.networks.blocks import ADN -from tests.utils import TorchImageTestCase2D, TorchImageTestCase3D +from tests.utils.utils import TorchImageTestCase2D, TorchImageTestCase3D TEST_CASES_2D = [ [{"act": None}], diff --git a/tests/networks/blocks/test_convolutions.py b/tests/networks/blocks/test_convolutions.py index 77bc12770f..36f892753c 100644 --- a/tests/networks/blocks/test_convolutions.py +++ b/tests/networks/blocks/test_convolutions.py @@ -14,7 +14,7 @@ import unittest from monai.networks.blocks import Convolution, ResidualUnit -from tests.utils import TorchImageTestCase2D, TorchImageTestCase3D +from tests.utils.utils import TorchImageTestCase2D, TorchImageTestCase3D class TestConvolution2D(TorchImageTestCase2D): diff --git a/tests/networks/blocks/test_crf_cpu.py b/tests/networks/blocks/test_crf_cpu.py index a7ae0ff2df..e1c70c84d9 100644 --- a/tests/networks/blocks/test_crf_cpu.py +++ b/tests/networks/blocks/test_crf_cpu.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.networks.blocks import CRF -from tests.utils import skip_if_no_cpp_extension +from tests.utils.utils import skip_if_no_cpp_extension TEST_CASES = [ [ diff --git a/tests/networks/blocks/test_crf_cuda.py b/tests/networks/blocks/test_crf_cuda.py index d5329aab15..ef012ecae3 100644 --- a/tests/networks/blocks/test_crf_cuda.py +++ b/tests/networks/blocks/test_crf_cuda.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.networks.blocks import CRF -from tests.utils import skip_if_no_cpp_extension, skip_if_no_cuda +from tests.utils.utils import skip_if_no_cpp_extension, skip_if_no_cuda TEST_CASES = [ [ diff --git a/tests/networks/blocks/test_crossattention.py b/tests/networks/blocks/test_crossattention.py index e034e42290..652e7070b0 100644 --- a/tests/networks/blocks/test_crossattention.py +++ b/tests/networks/blocks/test_crossattention.py @@ -22,7 +22,7 @@ from monai.networks.blocks.crossattention import CrossAttentionBlock from monai.networks.layers.factories import RelPosEmbedding from monai.utils import optional_import -from tests.utils import SkipIfBeforePyTorchVersion, assert_allclose +from tests.utils.utils import SkipIfBeforePyTorchVersion, assert_allclose einops, has_einops = optional_import("einops") diff --git a/tests/networks/blocks/test_denseblock.py b/tests/networks/blocks/test_denseblock.py index b741582422..89fd6b545e 100644 --- a/tests/networks/blocks/test_denseblock.py +++ b/tests/networks/blocks/test_denseblock.py @@ -16,7 +16,7 @@ import torch.nn as nn from monai.networks.blocks import ConvDenseBlock, DenseBlock -from tests.utils import TorchImageTestCase2D, TorchImageTestCase3D +from tests.utils.utils import TorchImageTestCase2D, TorchImageTestCase3D class TestDenseBlock2D(TorchImageTestCase2D): diff --git a/tests/networks/blocks/test_dynunet_block.py b/tests/networks/blocks/test_dynunet_block.py index 4d9e06670b..6c3c2a515f 100644 --- a/tests/networks/blocks/test_dynunet_block.py +++ b/tests/networks/blocks/test_dynunet_block.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.blocks.dynunet_block import UnetBasicBlock, UnetResBlock, UnetUpBlock, get_padding -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_CASE_RES_BASIC_BLOCK = [] for spatial_dims in range(2, 4): diff --git a/tests/networks/blocks/test_fpn_block.py b/tests/networks/blocks/test_fpn_block.py index 969800e80a..c47235f1f7 100644 --- a/tests/networks/blocks/test_fpn_block.py +++ b/tests/networks/blocks/test_fpn_block.py @@ -21,7 +21,7 @@ from monai.networks.blocks.feature_pyramid_network import FeaturePyramidNetwork from monai.networks.nets.resnet import resnet50 from monai.utils import optional_import -from tests.utils import SkipIfBeforePyTorchVersion, test_script_save +from tests.utils.utils import SkipIfBeforePyTorchVersion, test_script_save _, has_torchvision = optional_import("torchvision") diff --git a/tests/networks/blocks/test_patchembedding.py b/tests/networks/blocks/test_patchembedding.py index 71ac767966..377b4dfa12 100644 --- a/tests/networks/blocks/test_patchembedding.py +++ b/tests/networks/blocks/test_patchembedding.py @@ -21,7 +21,7 @@ from monai.networks import eval_mode from monai.networks.blocks.patchembedding import PatchEmbed, PatchEmbeddingBlock from monai.utils import optional_import -from tests.utils import SkipIfBeforePyTorchVersion +from tests.utils.utils import SkipIfBeforePyTorchVersion einops, has_einops = optional_import("einops") diff --git a/tests/networks/blocks/test_se_block.py b/tests/networks/blocks/test_se_block.py index ca60643635..cee36c7876 100644 --- a/tests/networks/blocks/test_se_block.py +++ b/tests/networks/blocks/test_se_block.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.blocks import SEBlock from monai.networks.layers.factories import Act, Norm -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/blocks/test_se_blocks.py b/tests/networks/blocks/test_se_blocks.py index c1e72749cc..8fa8161f15 100644 --- a/tests/networks/blocks/test_se_blocks.py +++ b/tests/networks/blocks/test_se_blocks.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.blocks import ChannelSELayer, ResidualSELayer -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_CASES = [ # single channel 3D, batch 16 [{"spatial_dims": 2, "in_channels": 4, "r": 3}, (7, 4, 64, 48), (7, 4, 64, 48)], # 4-channel 2D, batch 7 diff --git a/tests/networks/blocks/test_selfattention.py b/tests/networks/blocks/test_selfattention.py index 338f1bf840..0335630b3c 100644 --- a/tests/networks/blocks/test_selfattention.py +++ b/tests/networks/blocks/test_selfattention.py @@ -22,7 +22,7 @@ from monai.networks.blocks.selfattention import SABlock from monai.networks.layers.factories import RelPosEmbedding 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 einops, has_einops = optional_import("einops") diff --git a/tests/networks/blocks/test_subpixel_upsample.py b/tests/networks/blocks/test_subpixel_upsample.py index fe9fb1c328..6b74a54fbc 100644 --- a/tests/networks/blocks/test_subpixel_upsample.py +++ b/tests/networks/blocks/test_subpixel_upsample.py @@ -20,7 +20,7 @@ from monai.networks import eval_mode from monai.networks.blocks import SubpixelUpsample from monai.networks.layers.factories import Conv -from tests.utils import SkipIfBeforePyTorchVersion, test_script_save +from tests.utils.utils import SkipIfBeforePyTorchVersion, test_script_save TEST_CASE_SUBPIXEL = [] for inch in range(1, 5): diff --git a/tests/networks/blocks/test_text_encoding.py b/tests/networks/blocks/test_text_encoding.py index 902f7a4b1d..091c098371 100644 --- a/tests/networks/blocks/test_text_encoding.py +++ b/tests/networks/blocks/test_text_encoding.py @@ -14,7 +14,7 @@ import unittest from monai.networks.blocks.text_embedding import TextEncoder -from tests.utils import skip_if_downloading_fails +from tests.utils.utils import skip_if_downloading_fails class TestTextEncoder(unittest.TestCase): diff --git a/tests/networks/blocks/test_unetr_block.py b/tests/networks/blocks/test_unetr_block.py index 9701557ed6..88c967c709 100644 --- a/tests/networks/blocks/test_unetr_block.py +++ b/tests/networks/blocks/test_unetr_block.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.blocks.dynunet_block import get_padding from monai.networks.blocks.unetr_block import UnetrBasicBlock, UnetrPrUpBlock, UnetrUpBlock -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_CASE_UNETR_BASIC_BLOCK = [] for spatial_dims in range(1, 4): diff --git a/tests/networks/blocks/warp/test_warp.py b/tests/networks/blocks/warp/test_warp.py index 549acc5982..c299d729cb 100644 --- a/tests/networks/blocks/warp/test_warp.py +++ b/tests/networks/blocks/warp/test_warp.py @@ -23,7 +23,7 @@ from monai.networks.blocks.warp import Warp from monai.transforms import LoadImaged from monai.utils import GridSampleMode, GridSamplePadMode -from tests.utils import ( +from tests.utils.utils import ( SkipIfBeforePyTorchVersion, SkipIfNoModule, download_url_or_skip_test, diff --git a/tests/networks/layers/filtering/test_bilateral_approx_cpu.py b/tests/networks/layers/filtering/test_bilateral_approx_cpu.py index e8a55e1f76..98bb827a2f 100644 --- a/tests/networks/layers/filtering/test_bilateral_approx_cpu.py +++ b/tests/networks/layers/filtering/test_bilateral_approx_cpu.py @@ -19,7 +19,7 @@ from torch.autograd import gradcheck from monai.networks.layers.filtering import BilateralFilter -from tests.utils import skip_if_no_cpp_extension +from tests.utils.utils import skip_if_no_cpp_extension TEST_CASES = [ [ diff --git a/tests/networks/layers/filtering/test_bilateral_approx_cuda.py b/tests/networks/layers/filtering/test_bilateral_approx_cuda.py index 4ad15d9646..7a518bab29 100644 --- a/tests/networks/layers/filtering/test_bilateral_approx_cuda.py +++ b/tests/networks/layers/filtering/test_bilateral_approx_cuda.py @@ -19,7 +19,7 @@ from torch.autograd import gradcheck from monai.networks.layers.filtering import BilateralFilter -from tests.utils import skip_if_no_cpp_extension, skip_if_no_cuda +from tests.utils.utils import skip_if_no_cpp_extension, skip_if_no_cuda TEST_CASES = [ [ diff --git a/tests/networks/layers/filtering/test_bilateral_precise.py b/tests/networks/layers/filtering/test_bilateral_precise.py index e13ede5bfd..618cf7f97d 100644 --- a/tests/networks/layers/filtering/test_bilateral_precise.py +++ b/tests/networks/layers/filtering/test_bilateral_precise.py @@ -19,7 +19,7 @@ from torch.autograd import gradcheck from monai.networks.layers.filtering import BilateralFilter -from tests.utils import skip_if_no_cpp_extension, skip_if_no_cuda, skip_if_quick +from tests.utils.utils import skip_if_no_cpp_extension, skip_if_no_cuda, skip_if_quick TEST_CASES = [ [ diff --git a/tests/networks/layers/filtering/test_phl_cpu.py b/tests/networks/layers/filtering/test_phl_cpu.py index 6f872a4776..a07edf96f0 100644 --- a/tests/networks/layers/filtering/test_phl_cpu.py +++ b/tests/networks/layers/filtering/test_phl_cpu.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.networks.layers.filtering import PHLFilter -from tests.utils import skip_if_no_cpp_extension +from tests.utils.utils import skip_if_no_cpp_extension TEST_CASES = [ [ diff --git a/tests/networks/layers/filtering/test_phl_cuda.py b/tests/networks/layers/filtering/test_phl_cuda.py index b410ea8722..48513764cc 100644 --- a/tests/networks/layers/filtering/test_phl_cuda.py +++ b/tests/networks/layers/filtering/test_phl_cuda.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.networks.layers.filtering import PHLFilter -from tests.utils import skip_if_no_cpp_extension, skip_if_no_cuda +from tests.utils.utils import skip_if_no_cpp_extension, skip_if_no_cuda TEST_CASES = [ [ diff --git a/tests/networks/layers/filtering/test_trainable_bilateral.py b/tests/networks/layers/filtering/test_trainable_bilateral.py index c69eff4071..3a51527aee 100644 --- a/tests/networks/layers/filtering/test_trainable_bilateral.py +++ b/tests/networks/layers/filtering/test_trainable_bilateral.py @@ -19,7 +19,7 @@ from torch.autograd import gradcheck from monai.networks.layers.filtering import TrainableBilateralFilterFunction -from tests.utils import skip_if_no_cpp_extension, skip_if_no_cuda +from tests.utils.utils import skip_if_no_cpp_extension, skip_if_no_cuda TEST_CASES = [ [ diff --git a/tests/networks/layers/filtering/test_trainable_joint_bilateral.py b/tests/networks/layers/filtering/test_trainable_joint_bilateral.py index 4263683ce2..6fb2eb2f28 100644 --- a/tests/networks/layers/filtering/test_trainable_joint_bilateral.py +++ b/tests/networks/layers/filtering/test_trainable_joint_bilateral.py @@ -19,7 +19,7 @@ from torch.autograd import gradcheck from monai.networks.layers.filtering import TrainableJointBilateralFilterFunction -from tests.utils import skip_if_no_cpp_extension, skip_if_no_cuda, skip_if_quick +from tests.utils.utils import skip_if_no_cpp_extension, skip_if_no_cuda, skip_if_quick TEST_CASES = [ [ diff --git a/tests/networks/layers/test_affine_transform.py b/tests/networks/layers/test_affine_transform.py index 11464070e0..2a9c919be0 100644 --- a/tests/networks/layers/test_affine_transform.py +++ b/tests/networks/layers/test_affine_transform.py @@ -19,7 +19,7 @@ from monai.networks import normalize_transform, to_norm_affine from monai.networks.layers import AffineTransform -from tests.utils import is_tf32_env +from tests.utils.utils import is_tf32_env _rtol = 1e-4 if not is_tf32_env() else 5e-3 diff --git a/tests/networks/layers/test_gaussian_filter.py b/tests/networks/layers/test_gaussian_filter.py index 2167591c66..1166bd9c5d 100644 --- a/tests/networks/layers/test_gaussian_filter.py +++ b/tests/networks/layers/test_gaussian_filter.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.networks.layers import GaussianFilter -from tests.utils import SkipIfAtLeastPyTorchVersion, skip_if_quick +from tests.utils.utils import SkipIfAtLeastPyTorchVersion, skip_if_quick TEST_CASES = [[{"type": "erf", "gt": 2.0}], [{"type": "scalespace", "gt": 3.0}], [{"type": "sampled", "gt": 5.0}]] TEST_CASES_GPU = [[{"type": "erf", "gt": 0.8, "device": "cuda"}], [{"type": "sampled", "gt": 5.0, "device": "cuda"}]] diff --git a/tests/networks/layers/test_gmm.py b/tests/networks/layers/test_gmm.py index 549e8f1ec4..19258fdc37 100644 --- a/tests/networks/layers/test_gmm.py +++ b/tests/networks/layers/test_gmm.py @@ -22,7 +22,7 @@ from monai._extensions import load_module from monai.networks.layers import GaussianMixtureModel -from tests.utils import skip_if_darwin, skip_if_no_cuda, skip_if_quick, skip_if_windows +from tests.utils.utils import skip_if_darwin, skip_if_no_cuda, skip_if_quick, skip_if_windows TEST_CASES = [ [ diff --git a/tests/networks/layers/test_grid_pull.py b/tests/networks/layers/test_grid_pull.py index f80874d216..cd0eba02f0 100644 --- a/tests/networks/layers/test_grid_pull.py +++ b/tests/networks/layers/test_grid_pull.py @@ -21,7 +21,7 @@ from monai.networks.utils import meshgrid_ij from monai.utils import optional_import from tests.testing_data.cpp_resample_answers import Expected_1D_GP_bwd, Expected_1D_GP_fwd -from tests.utils import skip_if_no_cpp_extension +from tests.utils.utils import skip_if_no_cpp_extension BType, has_b_type = optional_import("monai._C", name="BoundType") PType, has_p_type = optional_import("monai._C", name="InterpolationType") diff --git a/tests/networks/layers/test_hilbert_transform.py b/tests/networks/layers/test_hilbert_transform.py index b91ba3f6b7..8cc9828474 100644 --- a/tests/networks/layers/test_hilbert_transform.py +++ b/tests/networks/layers/test_hilbert_transform.py @@ -19,7 +19,7 @@ from monai.networks.layers import HilbertTransform from monai.utils import OptionalImportError -from tests.utils import SkipIfModule, SkipIfNoModule +from tests.utils.utils import SkipIfModule, SkipIfNoModule def create_expected_numpy_output(input_datum, **kwargs): diff --git a/tests/networks/layers/test_lltm.py b/tests/networks/layers/test_lltm.py index cc64672e77..968e7e09b9 100644 --- a/tests/networks/layers/test_lltm.py +++ b/tests/networks/layers/test_lltm.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.networks.layers import LLTM -from tests.utils import SkipIfNoModule, assert_allclose, is_tf32_env +from tests.utils.utils import SkipIfNoModule, assert_allclose, is_tf32_env _rtol = 0.001 if is_tf32_env() else 0.0001 diff --git a/tests/networks/layers/test_savitzky_golay_filter.py b/tests/networks/layers/test_savitzky_golay_filter.py index 7c60287e2d..d0ae2269a0 100644 --- a/tests/networks/layers/test_savitzky_golay_filter.py +++ b/tests/networks/layers/test_savitzky_golay_filter.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.networks.layers import SavitzkyGolayFilter -from tests.utils import skip_if_no_cuda +from tests.utils.utils import skip_if_no_cuda # Zero-padding trivial tests diff --git a/tests/networks/nets/dints/test_dints_mixop.py b/tests/networks/nets/dints/test_dints_mixop.py index 683a8d1005..db4df3369c 100644 --- a/tests/networks/nets/dints/test_dints_mixop.py +++ b/tests/networks/nets/dints/test_dints_mixop.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.networks.nets.dints import Cell, MixedOp -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_CASES_3D = [ [ diff --git a/tests/networks/nets/regunet/test_localnet.py b/tests/networks/nets/regunet/test_localnet.py index 97aa94d2c5..cebd7965b8 100644 --- a/tests/networks/nets/regunet/test_localnet.py +++ b/tests/networks/nets/regunet/test_localnet.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets.regunet import LocalNet -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/nets/regunet/test_regunet.py b/tests/networks/nets/regunet/test_regunet.py index 3100d7660c..3533f64360 100644 --- a/tests/networks/nets/regunet/test_regunet.py +++ b/tests/networks/nets/regunet/test_regunet.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets.regunet import RegUNet -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/nets/test_ahnet.py b/tests/networks/nets/test_ahnet.py index 99a177f395..2d932f018e 100644 --- a/tests/networks/nets/test_ahnet.py +++ b/tests/networks/nets/test_ahnet.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.blocks import FCN, MCFCN from monai.networks.nets import AHNet -from tests.utils import skip_if_quick, test_pretrained_networks, test_script_save +from tests.utils.utils import skip_if_quick, test_pretrained_networks, test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/nets/test_attentionunet.py b/tests/networks/nets/test_attentionunet.py index 6a577f763f..4258221d50 100644 --- a/tests/networks/nets/test_attentionunet.py +++ b/tests/networks/nets/test_attentionunet.py @@ -17,7 +17,7 @@ import torch.nn as nn import monai.networks.nets.attentionunet as att -from tests.utils import skip_if_no_cuda, skip_if_quick +from tests.utils.utils import skip_if_no_cuda, skip_if_quick def get_net_parameters(net: nn.Module) -> int: diff --git a/tests/networks/nets/test_autoencoder.py b/tests/networks/nets/test_autoencoder.py index 6408f6a6d0..325dc5f3ec 100644 --- a/tests/networks/nets/test_autoencoder.py +++ b/tests/networks/nets/test_autoencoder.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.layers import Act from monai.networks.nets import AutoEncoder -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") diff --git a/tests/networks/nets/test_autoencoderkl.py b/tests/networks/nets/test_autoencoderkl.py index d15cb79084..5b117408de 100644 --- a/tests/networks/nets/test_autoencoderkl.py +++ b/tests/networks/nets/test_autoencoderkl.py @@ -23,7 +23,7 @@ from monai.networks import eval_mode from monai.networks.nets import AutoencoderKL from monai.utils import optional_import -from tests.utils import SkipIfBeforePyTorchVersion, skip_if_downloading_fails, testing_data_config +from tests.utils.utils import SkipIfBeforePyTorchVersion, skip_if_downloading_fails, testing_data_config tqdm, has_tqdm = optional_import("tqdm", name="tqdm") _, has_einops = optional_import("einops") diff --git a/tests/networks/nets/test_basic_unet.py b/tests/networks/nets/test_basic_unet.py index 770750851f..554f2a508e 100644 --- a/tests/networks/nets/test_basic_unet.py +++ b/tests/networks/nets/test_basic_unet.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets import BasicUNet -from tests.utils import test_script_save +from tests.utils.utils import test_script_save CASES_1D = [] for mode in ["pixelshuffle", "nontrainable", "deconv", None]: diff --git a/tests/networks/nets/test_basic_unetplusplus.py b/tests/networks/nets/test_basic_unetplusplus.py index 6438b5e0d4..cc6ebe049a 100644 --- a/tests/networks/nets/test_basic_unetplusplus.py +++ b/tests/networks/nets/test_basic_unetplusplus.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets import BasicUNetPlusPlus -from tests.utils import test_script_save +from tests.utils.utils import test_script_save CASES_1D = [] for mode in ["pixelshuffle", "nontrainable", "deconv", None]: diff --git a/tests/networks/nets/test_bundle_init_bundle.py b/tests/networks/nets/test_bundle_init_bundle.py index eb831093d5..9271adb6ba 100644 --- a/tests/networks/nets/test_bundle_init_bundle.py +++ b/tests/networks/nets/test_bundle_init_bundle.py @@ -18,7 +18,7 @@ import torch from monai.networks.nets import UNet -from tests.utils import command_line_tests, skip_if_windows +from tests.utils.utils import command_line_tests, skip_if_windows @skip_if_windows diff --git a/tests/networks/nets/test_controlnet.py b/tests/networks/nets/test_controlnet.py index 4746c7ce22..16c51774d6 100644 --- a/tests/networks/nets/test_controlnet.py +++ b/tests/networks/nets/test_controlnet.py @@ -23,7 +23,7 @@ from monai.networks import eval_mode from monai.networks.nets.controlnet import ControlNet from monai.utils import optional_import -from tests.utils import skip_if_downloading_fails, testing_data_config +from tests.utils.utils import skip_if_downloading_fails, testing_data_config _, has_einops = optional_import("einops") UNCOND_CASES_2D = [ diff --git a/tests/networks/nets/test_daf3d.py b/tests/networks/nets/test_daf3d.py index d20cb3cfd1..ff851d553f 100644 --- a/tests/networks/nets/test_daf3d.py +++ b/tests/networks/nets/test_daf3d.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.nets import DAF3D from monai.utils import optional_import -from tests.utils import test_script_save +from tests.utils.utils import test_script_save _, has_tv = optional_import("torchvision") diff --git a/tests/networks/nets/test_densenet.py b/tests/networks/nets/test_densenet.py index ee4be9003b..5d45ddce46 100644 --- a/tests/networks/nets/test_densenet.py +++ b/tests/networks/nets/test_densenet.py @@ -21,7 +21,7 @@ from monai.networks import eval_mode from monai.networks.nets import DenseNet121, Densenet169, DenseNet264, densenet201 from monai.utils import optional_import -from tests.utils import skip_if_downloading_fails, skip_if_quick, test_script_save +from tests.utils.utils import skip_if_downloading_fails, skip_if_quick, test_script_save if TYPE_CHECKING: import torchvision diff --git a/tests/networks/nets/test_diffusion_model_unet.py b/tests/networks/nets/test_diffusion_model_unet.py index 7f764d85de..c795c71c2f 100644 --- a/tests/networks/nets/test_diffusion_model_unet.py +++ b/tests/networks/nets/test_diffusion_model_unet.py @@ -23,7 +23,7 @@ from monai.networks import eval_mode from monai.networks.nets import DiffusionModelUNet from monai.utils import optional_import -from tests.utils import skip_if_downloading_fails, testing_data_config +from tests.utils.utils import skip_if_downloading_fails, testing_data_config _, has_einops = optional_import("einops") diff --git a/tests/networks/nets/test_dints_network.py b/tests/networks/nets/test_dints_network.py index 5ee4db7a4e..eb7ac76220 100644 --- a/tests/networks/nets/test_dints_network.py +++ b/tests/networks/nets/test_dints_network.py @@ -19,7 +19,7 @@ from monai.networks.nets import DiNTS, TopologyInstance, TopologySearch from monai.networks.nets.dints import Cell -from tests.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save +from tests.utils.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save TEST_CASES_3D = [ [ diff --git a/tests/networks/nets/test_discriminator.py b/tests/networks/nets/test_discriminator.py index f615605e56..be01701c4e 100644 --- a/tests/networks/nets/test_discriminator.py +++ b/tests/networks/nets/test_discriminator.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets import Discriminator -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_CASE_0 = [ {"in_shape": (1, 64, 64), "channels": (2, 4, 8), "strides": (2, 2, 2), "num_res_units": 0}, diff --git a/tests/networks/nets/test_dynunet.py b/tests/networks/nets/test_dynunet.py index 7c4882fcbb..e21125eda2 100644 --- a/tests/networks/nets/test_dynunet.py +++ b/tests/networks/nets/test_dynunet.py @@ -22,7 +22,7 @@ from monai.networks import eval_mode from monai.networks.nets import DynUNet from monai.utils import optional_import -from tests.utils import assert_allclose, skip_if_no_cuda, skip_if_windows, test_script_save +from tests.utils.utils import assert_allclose, skip_if_no_cuda, skip_if_windows, test_script_save InstanceNorm3dNVFuser, _ = optional_import("apex.normalization", name="InstanceNorm3dNVFuser") diff --git a/tests/networks/nets/test_efficientnet.py b/tests/networks/nets/test_efficientnet.py index 266500b4c8..de09fd6904 100644 --- a/tests/networks/nets/test_efficientnet.py +++ b/tests/networks/nets/test_efficientnet.py @@ -29,7 +29,7 @@ get_efficientnet_image_size, ) from monai.utils import optional_import -from tests.utils import skip_if_downloading_fails, skip_if_quick, test_pretrained_networks, test_script_save +from tests.utils.utils import skip_if_downloading_fails, skip_if_quick, test_pretrained_networks, test_script_save TESTS_PATH = Path(__file__).parents[1] diff --git a/tests/networks/nets/test_flexible_unet.py b/tests/networks/nets/test_flexible_unet.py index 42baa28b71..f1e4774519 100644 --- a/tests/networks/nets/test_flexible_unet.py +++ b/tests/networks/nets/test_flexible_unet.py @@ -27,7 +27,7 @@ ResNetFeatures, ) from monai.utils import optional_import -from tests.utils import SkipIfNoModule, skip_if_downloading_fails, skip_if_quick +from tests.utils.utils import SkipIfNoModule, skip_if_downloading_fails, skip_if_quick torchvision, has_torchvision = optional_import("torchvision") PIL, has_pil = optional_import("PIL") diff --git a/tests/networks/nets/test_generator.py b/tests/networks/nets/test_generator.py index f531f928da..178e5dd502 100644 --- a/tests/networks/nets/test_generator.py +++ b/tests/networks/nets/test_generator.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets import Generator -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_CASE_0 = [ {"latent_shape": (64,), "start_shape": (8, 8, 8), "channels": (8, 4, 1), "strides": (2, 2, 2), "num_res_units": 0}, diff --git a/tests/networks/nets/test_globalnet.py b/tests/networks/nets/test_globalnet.py index 626053377c..3127b9e02c 100644 --- a/tests/networks/nets/test_globalnet.py +++ b/tests/networks/nets/test_globalnet.py @@ -21,7 +21,7 @@ from monai.networks.blocks import Warp from monai.networks.nets import GlobalNet from monai.networks.nets.regunet import AffineHead -from tests.utils import assert_allclose, test_script_save +from tests.utils.utils import assert_allclose, test_script_save TEST_CASES_AFFINE_TRANSFORM = [ [ diff --git a/tests/networks/nets/test_highresnet.py b/tests/networks/nets/test_highresnet.py index bcc5739900..1e43e56ebe 100644 --- a/tests/networks/nets/test_highresnet.py +++ b/tests/networks/nets/test_highresnet.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets import HighResNet -from tests.utils import DistTestCase, TimedCall, test_script_save +from tests.utils.utils import DistTestCase, TimedCall, test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/nets/test_hovernet.py b/tests/networks/nets/test_hovernet.py index fb4946b011..b477fa2de4 100644 --- a/tests/networks/nets/test_hovernet.py +++ b/tests/networks/nets/test_hovernet.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode, train_mode from monai.networks.nets import HoVerNet from monai.networks.nets.hovernet import _DenseLayerDecoder -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/nets/test_milmodel.py b/tests/networks/nets/test_milmodel.py index 42116e8220..ad9c6fb0e9 100644 --- a/tests/networks/nets/test_milmodel.py +++ b/tests/networks/nets/test_milmodel.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.nets import MILModel from monai.utils.module import optional_import -from tests.utils import skip_if_downloading_fails, test_script_save +from tests.utils.utils import skip_if_downloading_fails, test_script_save models, _ = optional_import("torchvision.models") diff --git a/tests/networks/nets/test_net_adapter.py b/tests/networks/nets/test_net_adapter.py index 242326e242..52e3c6b6c4 100644 --- a/tests/networks/nets/test_net_adapter.py +++ b/tests/networks/nets/test_net_adapter.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets import NetAdapter, resnet18 -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/nets/test_network_consistency.py b/tests/networks/nets/test_network_consistency.py index bcfd448144..901d209c7f 100644 --- a/tests/networks/nets/test_network_consistency.py +++ b/tests/networks/nets/test_network_consistency.py @@ -24,7 +24,7 @@ import monai.networks.nets as nets from monai.utils import set_determinism from monai.utils.misc import MONAIEnvVars -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose extra_test_data_dir = MONAIEnvVars.extra_test_data() diff --git a/tests/networks/nets/test_patch_gan_dicriminator.py b/tests/networks/nets/test_patch_gan_dicriminator.py index c19898e70d..196a5edd80 100644 --- a/tests/networks/nets/test_patch_gan_dicriminator.py +++ b/tests/networks/nets/test_patch_gan_dicriminator.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets import MultiScalePatchDiscriminator, PatchDiscriminator -from tests.utils import test_script_save +from tests.utils.utils import test_script_save TEST_PATCHGAN = [ [ diff --git a/tests/networks/nets/test_quicknat.py b/tests/networks/nets/test_quicknat.py index f6786405d2..fddab226aa 100644 --- a/tests/networks/nets/test_quicknat.py +++ b/tests/networks/nets/test_quicknat.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.nets import Quicknat from monai.utils import optional_import -from tests.utils import test_script_save +from tests.utils.utils import test_script_save _, has_se = optional_import("squeeze_and_excitation") diff --git a/tests/networks/nets/test_resnet.py b/tests/networks/nets/test_resnet.py index a55d18f5de..03dc91042f 100644 --- a/tests/networks/nets/test_resnet.py +++ b/tests/networks/nets/test_resnet.py @@ -37,7 +37,7 @@ ) from monai.networks.nets.resnet import ResNetBlock from monai.utils import optional_import -from tests.utils import ( +from tests.utils.utils import ( SkipIfNoModule, equal_state_dict, skip_if_downloading_fails, diff --git a/tests/networks/nets/test_segresnet.py b/tests/networks/nets/test_segresnet.py index 728699c434..7949cfd95f 100644 --- a/tests/networks/nets/test_segresnet.py +++ b/tests/networks/nets/test_segresnet.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.nets import SegResNet, SegResNetVAE from monai.utils import UpsampleMode -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/nets/test_segresnet_ds.py b/tests/networks/nets/test_segresnet_ds.py index eab7bac9a0..46b48c1685 100644 --- a/tests/networks/nets/test_segresnet_ds.py +++ b/tests/networks/nets/test_segresnet_ds.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets import SegResNetDS, SegResNetDS2 -from tests.utils import SkipIfBeforePyTorchVersion, test_script_save +from tests.utils.utils import SkipIfBeforePyTorchVersion, test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" TEST_CASE_SEGRESNET_DS = [] diff --git a/tests/networks/nets/test_senet.py b/tests/networks/nets/test_senet.py index 6809d4562b..5edd7ff14f 100644 --- a/tests/networks/nets/test_senet.py +++ b/tests/networks/nets/test_senet.py @@ -23,7 +23,7 @@ from monai.networks import eval_mode from monai.networks.nets import SENet, SENet154, SEResNet50, SEResNet101, SEResNet152, SEResNext50, SEResNext101 from monai.utils import optional_import -from tests.utils import test_is_quick, test_pretrained_networks, test_script_save, testing_data_config +from tests.utils.utils import test_is_quick, test_pretrained_networks, test_script_save, testing_data_config if TYPE_CHECKING: import pretrainedmodels diff --git a/tests/networks/nets/test_swin_unetr.py b/tests/networks/nets/test_swin_unetr.py index 5b33475c7e..630c541f33 100644 --- a/tests/networks/nets/test_swin_unetr.py +++ b/tests/networks/nets/test_swin_unetr.py @@ -24,7 +24,7 @@ from monai.networks.nets.swin_unetr import PatchMerging, PatchMergingV2, SwinUNETR, filter_swinunetr from monai.networks.utils import copy_model_state from monai.utils import optional_import -from tests.utils import ( +from tests.utils.utils import ( assert_allclose, pytorch_after, skip_if_downloading_fails, diff --git a/tests/networks/nets/test_torchvision_fc_model.py b/tests/networks/nets/test_torchvision_fc_model.py index 9cc19db62c..84d9d79d11 100644 --- a/tests/networks/nets/test_torchvision_fc_model.py +++ b/tests/networks/nets/test_torchvision_fc_model.py @@ -21,7 +21,7 @@ from monai.networks.nets import TorchVisionFCModel, UNet from monai.networks.utils import look_up_named_module, set_named_module from monai.utils import min_version, optional_import -from tests.utils import skip_if_downloading_fails +from tests.utils.utils import skip_if_downloading_fails Inception_V3_Weights, has_enum = optional_import("torchvision.models.inception", name="Inception_V3_Weights") diff --git a/tests/networks/nets/test_transchex.py b/tests/networks/nets/test_transchex.py index 481c20e285..2875eacf92 100644 --- a/tests/networks/nets/test_transchex.py +++ b/tests/networks/nets/test_transchex.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets.transchex import Transchex -from tests.utils import skip_if_quick +from tests.utils.utils import skip_if_quick TEST_CASE_TRANSCHEX = [] for drop_out in [0.4]: diff --git a/tests/networks/nets/test_transformer.py b/tests/networks/nets/test_transformer.py index b371809d47..d595f29bcf 100644 --- a/tests/networks/nets/test_transformer.py +++ b/tests/networks/nets/test_transformer.py @@ -24,7 +24,7 @@ from monai.networks import eval_mode from monai.networks.nets import DecoderOnlyTransformer from monai.utils import optional_import -from tests.utils import skip_if_downloading_fails, testing_data_config +from tests.utils.utils import skip_if_downloading_fails, testing_data_config _, has_einops = optional_import("einops") TEST_CASES = [] diff --git a/tests/networks/nets/test_unet.py b/tests/networks/nets/test_unet.py index 1fb98f84b0..323020a3f7 100644 --- a/tests/networks/nets/test_unet.py +++ b/tests/networks/nets/test_unet.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.layers import Act, Norm from monai.networks.nets import UNet -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/nets/test_unetr.py b/tests/networks/nets/test_unetr.py index 8c5ecb32e1..3eeef5de43 100644 --- a/tests/networks/nets/test_unetr.py +++ b/tests/networks/nets/test_unetr.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets.unetr import UNETR -from tests.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save +from tests.utils.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save TEST_CASE_UNETR = [] for dropout_rate in [0.4]: diff --git a/tests/networks/nets/test_varautoencoder.py b/tests/networks/nets/test_varautoencoder.py index e957dcfb61..145d3e4dcc 100644 --- a/tests/networks/nets/test_varautoencoder.py +++ b/tests/networks/nets/test_varautoencoder.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.layers import Act from monai.networks.nets import VarAutoEncoder -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") diff --git a/tests/networks/nets/test_vista3d.py b/tests/networks/nets/test_vista3d.py index d3b4e0c10e..f47db4557d 100644 --- a/tests/networks/nets/test_vista3d.py +++ b/tests/networks/nets/test_vista3d.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.nets import VISTA3D, SegResNetDS2 from monai.networks.nets.vista3d import ClassMappingClassify, PointMappingSAM -from tests.utils import SkipIfBeforePyTorchVersion, skip_if_quick +from tests.utils.utils import SkipIfBeforePyTorchVersion, skip_if_quick device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/nets/test_vit.py b/tests/networks/nets/test_vit.py index a3ffd0b2ef..6df3b6b4a6 100644 --- a/tests/networks/nets/test_vit.py +++ b/tests/networks/nets/test_vit.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets.vit import ViT -from tests.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save +from tests.utils.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save TEST_CASE_Vit = [] for dropout_rate in [0.6]: diff --git a/tests/networks/nets/test_vitautoenc.py b/tests/networks/nets/test_vitautoenc.py index 9a503948d0..5928529b15 100644 --- a/tests/networks/nets/test_vitautoenc.py +++ b/tests/networks/nets/test_vitautoenc.py @@ -17,7 +17,7 @@ from monai.networks import eval_mode from monai.networks.nets.vitautoenc import ViTAutoEnc -from tests.utils import skip_if_quick, skip_if_windows +from tests.utils.utils import skip_if_quick, skip_if_windows TEST_CASE_Vitautoenc = [] for in_channels in [1, 4]: diff --git a/tests/networks/nets/test_vnet.py b/tests/networks/nets/test_vnet.py index 0ebf060434..c8067e7362 100644 --- a/tests/networks/nets/test_vnet.py +++ b/tests/networks/nets/test_vnet.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets import VNet -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/nets/test_voxelmorph.py b/tests/networks/nets/test_voxelmorph.py index ef420ef20c..4763b9e1e7 100644 --- a/tests/networks/nets/test_voxelmorph.py +++ b/tests/networks/nets/test_voxelmorph.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets import VoxelMorph, VoxelMorphUNet -from tests.utils import test_script_save +from tests.utils.utils import test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/nets/test_vqvae.py b/tests/networks/nets/test_vqvae.py index 4916dc2faa..c733879467 100644 --- a/tests/networks/nets/test_vqvae.py +++ b/tests/networks/nets/test_vqvae.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets.vqvae import VQVAE -from tests.utils import SkipIfBeforePyTorchVersion +from tests.utils.utils import SkipIfBeforePyTorchVersion TEST_CASES = [ [ diff --git a/tests/networks/schedulers/test_scheduler_ddim.py b/tests/networks/schedulers/test_scheduler_ddim.py index 1a8f8cab67..4cd672afbc 100644 --- a/tests/networks/schedulers/test_scheduler_ddim.py +++ b/tests/networks/schedulers/test_scheduler_ddim.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.networks.schedulers import DDIMScheduler -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_2D_CASE = [] for beta_schedule in ["linear_beta", "scaled_linear_beta"]: diff --git a/tests/networks/schedulers/test_scheduler_ddpm.py b/tests/networks/schedulers/test_scheduler_ddpm.py index f0447aded2..42232e7fb4 100644 --- a/tests/networks/schedulers/test_scheduler_ddpm.py +++ b/tests/networks/schedulers/test_scheduler_ddpm.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.networks.schedulers import DDPMScheduler -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_2D_CASE = [] for beta_schedule in ["linear_beta", "scaled_linear_beta"]: diff --git a/tests/networks/schedulers/test_scheduler_pndm.py b/tests/networks/schedulers/test_scheduler_pndm.py index 69e5e403f5..a23f2c0709 100644 --- a/tests/networks/schedulers/test_scheduler_pndm.py +++ b/tests/networks/schedulers/test_scheduler_pndm.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.networks.schedulers import PNDMScheduler -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_2D_CASE = [] for beta_schedule in ["linear_beta", "scaled_linear_beta"]: diff --git a/tests/networks/test_bundle_onnx_export.py b/tests/networks/test_bundle_onnx_export.py index 7ed9f8d2cd..b02692bfe0 100644 --- a/tests/networks/test_bundle_onnx_export.py +++ b/tests/networks/test_bundle_onnx_export.py @@ -20,7 +20,7 @@ from monai.bundle import ConfigParser from monai.networks import save_state -from tests.utils import SkipIfBeforePyTorchVersion, SkipIfNoModule, command_line_tests, skip_if_windows +from tests.utils.utils import SkipIfBeforePyTorchVersion, SkipIfNoModule, command_line_tests, skip_if_windows TEST_CASE_1 = ["True"] TEST_CASE_2 = ["False"] diff --git a/tests/networks/test_convert_to_onnx.py b/tests/networks/test_convert_to_onnx.py index 798c510800..8af4625d21 100644 --- a/tests/networks/test_convert_to_onnx.py +++ b/tests/networks/test_convert_to_onnx.py @@ -21,7 +21,7 @@ from monai.networks import convert_to_onnx from monai.networks.nets import SegResNet, UNet from monai.utils.module import pytorch_after -from tests.utils import SkipIfBeforePyTorchVersion, SkipIfNoModule, optional_import, skip_if_quick +from tests.utils.utils import SkipIfBeforePyTorchVersion, SkipIfNoModule, optional_import, skip_if_quick if torch.cuda.is_available(): TORCH_DEVICE_OPTIONS = ["cpu", "cuda"] diff --git a/tests/networks/test_convert_to_trt.py b/tests/networks/test_convert_to_trt.py index a7b1edec3c..d62ff7e87e 100644 --- a/tests/networks/test_convert_to_trt.py +++ b/tests/networks/test_convert_to_trt.py @@ -20,7 +20,7 @@ from monai.networks import convert_to_trt from monai.networks.nets import UNet from monai.utils import optional_import -from tests.utils import SkipIfBeforeComputeCapabilityVersion, skip_if_no_cuda, skip_if_quick, skip_if_windows +from tests.utils.utils import SkipIfBeforeComputeCapabilityVersion, skip_if_no_cuda, skip_if_quick, skip_if_windows _, has_torchtrt = optional_import( "torch_tensorrt", diff --git a/tests/networks/test_varnet.py b/tests/networks/test_varnet.py index a46d58d6a2..4efc713cc6 100644 --- a/tests/networks/test_varnet.py +++ b/tests/networks/test_varnet.py @@ -20,7 +20,7 @@ from monai.apps.reconstruction.networks.nets.complex_unet import ComplexUnet from monai.apps.reconstruction.networks.nets.varnet import VariationalNetworkModel from monai.networks import eval_mode -from tests.utils import SkipIfBeforePyTorchVersion, test_script_save +from tests.utils.utils import SkipIfBeforePyTorchVersion, test_script_save device = torch.device("cuda" if torch.cuda.is_available() else "cpu") coil_sens_model = CoilSensitivityModel(spatial_dims=2, features=[8, 16, 32, 64, 128, 8]) diff --git a/tests/networks/utils/test_replace_module.py b/tests/networks/utils/test_replace_module.py index f3964ac65d..cebe106f71 100644 --- a/tests/networks/utils/test_replace_module.py +++ b/tests/networks/utils/test_replace_module.py @@ -18,7 +18,7 @@ from monai.networks.nets import DenseNet121 from monai.networks.utils import replace_modules, replace_modules_temp -from tests.utils import TEST_DEVICES +from tests.utils.utils import TEST_DEVICES TESTS = [] for device in TEST_DEVICES: diff --git a/tests/ngc_bundle_download.py b/tests/ngc_bundle_download.py index cf0d53a743..d99a5ca85b 100644 --- a/tests/ngc_bundle_download.py +++ b/tests/ngc_bundle_download.py @@ -24,7 +24,7 @@ from monai.bundle import download, load from monai.config import print_debug_info from monai.networks.utils import copy_model_state -from tests.utils import assert_allclose, skip_if_downloading_fails, skip_if_quick, skip_if_windows +from tests.utils.utils import assert_allclose, skip_if_downloading_fails, skip_if_quick, skip_if_windows TEST_CASE_NGC_1 = [ "spleen_ct_segmentation", diff --git a/tests/optimizers/test_generate_param_groups.py b/tests/optimizers/test_generate_param_groups.py index a78dba9f03..a4a78bb024 100644 --- a/tests/optimizers/test_generate_param_groups.py +++ b/tests/optimizers/test_generate_param_groups.py @@ -19,7 +19,7 @@ from monai.networks.nets import Unet from monai.optimizers import generate_param_groups from monai.utils import ensure_tuple -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_1 = [{"layer_matches": [lambda x: x.model[-1]], "match_types": "select", "lr_values": [1]}, (1, 100), [5, 21]] diff --git a/tests/optimizers/test_lr_finder.py b/tests/optimizers/test_lr_finder.py index d26cb23a90..8af9ab7660 100644 --- a/tests/optimizers/test_lr_finder.py +++ b/tests/optimizers/test_lr_finder.py @@ -27,7 +27,7 @@ from monai.transforms import Compose, EnsureChannelFirstd, LoadImaged, ScaleIntensityd, ToTensord from monai.utils import optional_import, set_determinism from monai.utils.misc import MONAIEnvVars -from tests.utils import skip_if_downloading_fails +from tests.utils.utils import skip_if_downloading_fails if TYPE_CHECKING: import matplotlib.pyplot as plt diff --git a/tests/padders.py b/tests/padders.py index a7dce263bb..f310025ab6 100644 --- a/tests/padders.py +++ b/tests/padders.py @@ -21,7 +21,7 @@ from monai.transforms.lazy.functional import apply_pending from monai.transforms.transform import MapTransform from monai.utils.enums import NumpyPadMode, PytorchPadMode -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose MODES = [] # Test modes diff --git a/tests/test_auto3dseg.py b/tests/test_auto3dseg.py index 5273f0663a..41766e1da0 100644 --- a/tests/test_auto3dseg.py +++ b/tests/test_auto3dseg.py @@ -54,7 +54,7 @@ ToDeviced, ) from monai.utils.enums import DataStatsKeys -from tests.utils import skip_if_no_cuda +from tests.utils.utils import skip_if_no_cuda device = "cpu" n_workers = 2 diff --git a/tests/test_call_dist.py b/tests/test_call_dist.py index 503cb5e792..3c0f07ea1f 100644 --- a/tests/test_call_dist.py +++ b/tests/test_call_dist.py @@ -13,7 +13,7 @@ import unittest -from tests.utils import DistCall, DistTestCase +from tests.utils.utils import DistCall, DistTestCase class DistributedCallTest(DistTestCase): diff --git a/tests/test_masked_autoencoder_vit.py b/tests/test_masked_autoencoder_vit.py index f8f6977cc2..4f0cdbf318 100644 --- a/tests/test_masked_autoencoder_vit.py +++ b/tests/test_masked_autoencoder_vit.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets.masked_autoencoder_vit import MaskedAutoEncoderViT -from tests.utils import skip_if_quick +from tests.utils.utils import skip_if_quick TEST_CASE_MaskedAutoEncoderViT = [] for masking_ratio in [0.5]: diff --git a/tests/test_query_memory.py b/tests/test_query_memory.py index 77c34ede39..328d719229 100644 --- a/tests/test_query_memory.py +++ b/tests/test_query_memory.py @@ -13,7 +13,7 @@ import unittest -from tests.utils import query_memory +from tests.utils.utils import query_memory class TestQueryMemory(unittest.TestCase): diff --git a/tests/test_rand_torchiod.py b/tests/test_rand_torchiod.py index 52bcf7c576..679adb9ac9 100644 --- a/tests/test_rand_torchiod.py +++ b/tests/test_rand_torchiod.py @@ -20,7 +20,7 @@ from monai.transforms import RandTorchIOd from monai.utils import optional_import, set_determinism -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose _, has_torchio = optional_import("torchio") diff --git a/tests/test_set_visible_devices.py b/tests/test_set_visible_devices.py index b4f44957a2..cb60e6a3bf 100644 --- a/tests/test_set_visible_devices.py +++ b/tests/test_set_visible_devices.py @@ -14,7 +14,7 @@ import os import unittest -from tests.utils import SkipIfAtLeastPyTorchVersion, skip_if_no_cuda +from tests.utils.utils import SkipIfAtLeastPyTorchVersion, skip_if_no_cuda class TestVisibleDevices(unittest.TestCase): diff --git a/tests/test_timedcall_dist.py b/tests/test_timedcall_dist.py index a814a99b25..534fecfa95 100644 --- a/tests/test_timedcall_dist.py +++ b/tests/test_timedcall_dist.py @@ -16,7 +16,7 @@ import time import unittest -from tests.utils import TimedCall +from tests.utils.utils import TimedCall @TimedCall(seconds=20 if sys.platform == "linux" else 60, force_quit=False) diff --git a/tests/test_torchiod.py b/tests/test_torchiod.py index 892287461c..65513cd582 100644 --- a/tests/test_torchiod.py +++ b/tests/test_torchiod.py @@ -19,7 +19,7 @@ from monai.transforms import TorchIOd from monai.utils import optional_import -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose _, has_torchio = optional_import("torchio") diff --git a/tests/transforms/croppad/test_rand_weighted_crop.py b/tests/transforms/croppad/test_rand_weighted_crop.py index f509065a56..53f4053242 100644 --- a/tests/transforms/croppad/test_rand_weighted_crop.py +++ b/tests/transforms/croppad/test_rand_weighted_crop.py @@ -20,7 +20,7 @@ from monai.transforms.croppad.array import RandWeightedCrop from monai.transforms.lazy.functional import apply_pending from tests.croppers import CropTest -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, assert_allclose def get_data(ndim): diff --git a/tests/transforms/croppad/test_rand_weighted_cropd.py b/tests/transforms/croppad/test_rand_weighted_cropd.py index a1414df0ac..9990972d22 100644 --- a/tests/transforms/croppad/test_rand_weighted_cropd.py +++ b/tests/transforms/croppad/test_rand_weighted_cropd.py @@ -19,7 +19,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms.croppad.dictionary import RandWeightedCropd from monai.transforms.lazy.functional import apply_pending -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, assert_allclose def get_data(ndim): diff --git a/tests/transforms/intensity/test_compute_ho_ver_maps.py b/tests/transforms/intensity/test_compute_ho_ver_maps.py index 6e46cf2b1e..ad5747032a 100644 --- a/tests/transforms/intensity/test_compute_ho_ver_maps.py +++ b/tests/transforms/intensity/test_compute_ho_ver_maps.py @@ -19,7 +19,7 @@ from monai.transforms.intensity.array import ComputeHoVerMaps 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.0", min_version) diff --git a/tests/transforms/intensity/test_compute_ho_ver_maps_d.py b/tests/transforms/intensity/test_compute_ho_ver_maps_d.py index 0734e2e731..4726ce0ba6 100644 --- a/tests/transforms/intensity/test_compute_ho_ver_maps_d.py +++ b/tests/transforms/intensity/test_compute_ho_ver_maps_d.py @@ -19,7 +19,7 @@ from monai.transforms.intensity.dictionary import ComputeHoVerMapsd 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.0", min_version) diff --git a/tests/transforms/intensity/test_foreground_mask.py b/tests/transforms/intensity/test_foreground_mask.py index 1aa54f4d3a..0ac533a0b1 100644 --- a/tests/transforms/intensity/test_foreground_mask.py +++ b/tests/transforms/intensity/test_foreground_mask.py @@ -18,7 +18,7 @@ from monai.transforms.intensity.array import ForegroundMask from monai.utils import min_version, optional_import, set_determinism -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose skimage, has_skimage = optional_import("skimage", "0.19.0", min_version) set_determinism(1234) diff --git a/tests/transforms/intensity/test_foreground_maskd.py b/tests/transforms/intensity/test_foreground_maskd.py index dc7b6cfb24..cab40ce40b 100644 --- a/tests/transforms/intensity/test_foreground_maskd.py +++ b/tests/transforms/intensity/test_foreground_maskd.py @@ -18,7 +18,7 @@ from monai.transforms.intensity.dictionary import ForegroundMaskd from monai.utils import min_version, optional_import, set_determinism -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose skimage, has_skimage = optional_import("skimage", "0.19.0", min_version) set_determinism(1234) diff --git a/tests/transforms/intensity/test_rand_histogram_shiftd.py b/tests/transforms/intensity/test_rand_histogram_shiftd.py index fced270e90..ae35fbb771 100644 --- a/tests/transforms/intensity/test_rand_histogram_shiftd.py +++ b/tests/transforms/intensity/test_rand_histogram_shiftd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms.intensity.dictionary import RandHistogramShiftd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/intensity/test_scale_intensity_range_percentiles.py b/tests/transforms/intensity/test_scale_intensity_range_percentiles.py index a7390efe72..f5e9cb473b 100644 --- a/tests/transforms/intensity/test_scale_intensity_range_percentiles.py +++ b/tests/transforms/intensity/test_scale_intensity_range_percentiles.py @@ -17,7 +17,7 @@ import torch from monai.transforms.intensity.array import ScaleIntensityRangePercentiles -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestScaleIntensityRangePercentiles(NumpyImageTestCase2D): diff --git a/tests/transforms/intensity/test_scale_intensity_range_percentilesd.py b/tests/transforms/intensity/test_scale_intensity_range_percentilesd.py index ab0347fbbf..19f021e086 100644 --- a/tests/transforms/intensity/test_scale_intensity_range_percentilesd.py +++ b/tests/transforms/intensity/test_scale_intensity_range_percentilesd.py @@ -16,7 +16,7 @@ import numpy as np from monai.transforms.intensity.dictionary import ScaleIntensityRangePercentilesd -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestScaleIntensityRangePercentilesd(NumpyImageTestCase2D): diff --git a/tests/transforms/inverse/test_inverse_array.py b/tests/transforms/inverse/test_inverse_array.py index 4da9ee34b9..271c2f7d3d 100644 --- a/tests/transforms/inverse/test_inverse_array.py +++ b/tests/transforms/inverse/test_inverse_array.py @@ -20,7 +20,7 @@ from monai.transforms import Compose, EnsureChannelFirst, Flip, Orientation, Spacing from monai.transforms.inverse import InvertibleTransform from monai.utils import optional_import -from tests.utils import TEST_DEVICES +from tests.utils.utils import TEST_DEVICES _, has_nib = optional_import("nibabel") diff --git a/tests/transforms/lazy/functional/test_apply.py b/tests/transforms/lazy/functional/test_apply.py index ca37e945ba..2c996915d2 100644 --- a/tests/transforms/lazy/functional/test_apply.py +++ b/tests/transforms/lazy/functional/test_apply.py @@ -19,7 +19,7 @@ from monai.transforms.lazy.functional import apply_pending from monai.transforms.utils import create_rotate from monai.utils import LazyAttr, convert_to_tensor -from tests.utils import get_arange_img +from tests.utils.utils import get_arange_img def single_2d_transform_cases(): diff --git a/tests/transforms/lazy/functional/test_resample.py b/tests/transforms/lazy/functional/test_resample.py index 68b08b8b87..cbdf9bbbd6 100644 --- a/tests/transforms/lazy/functional/test_resample.py +++ b/tests/transforms/lazy/functional/test_resample.py @@ -18,7 +18,7 @@ from monai.transforms.lazy.functional import resample from monai.utils import convert_to_tensor -from tests.utils import assert_allclose, get_arange_img +from tests.utils.utils import assert_allclose, get_arange_img def rotate_90_2d(): diff --git a/tests/transforms/post/test_label_filterd.py b/tests/transforms/post/test_label_filterd.py index fba8100f25..43aab8b4f5 100644 --- a/tests/transforms/post/test_label_filterd.py +++ b/tests/transforms/post/test_label_filterd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms.post.dictionary import LabelFilterd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose grid_1 = torch.tensor([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]) diff --git a/tests/transforms/post/test_probnms.py b/tests/transforms/post/test_probnms.py index 2b52583ad4..830f436f9f 100644 --- a/tests/transforms/post/test_probnms.py +++ b/tests/transforms/post/test_probnms.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms.post.array import ProbNMS -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/post/test_probnmsd.py b/tests/transforms/post/test_probnmsd.py index aeb32bdb79..bd7057de7f 100644 --- a/tests/transforms/post/test_probnmsd.py +++ b/tests/transforms/post/test_probnmsd.py @@ -19,7 +19,7 @@ from parameterized import parameterized from monai.transforms.post.dictionary import ProbNMSD -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TESTS: list[Any] = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/post/test_remove_small_objects.py b/tests/transforms/post/test_remove_small_objects.py index 633a6d9a99..a4d58ec04d 100644 --- a/tests/transforms/post/test_remove_small_objects.py +++ b/tests/transforms/post/test_remove_small_objects.py @@ -21,7 +21,7 @@ from monai.transforms.post.array import RemoveSmallObjects from monai.transforms.post.dictionary import RemoveSmallObjectsd from monai.utils import optional_import -from tests.utils import TEST_NDARRAYS, SkipIfNoModule, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, SkipIfNoModule, assert_allclose morphology, has_morphology = optional_import("skimage.morphology") diff --git a/tests/transforms/spatial/test_convert_box_points.py b/tests/transforms/spatial/test_convert_box_points.py index 5e3d7ee645..80fe25489c 100644 --- a/tests/transforms/spatial/test_convert_box_points.py +++ b/tests/transforms/spatial/test_convert_box_points.py @@ -18,7 +18,7 @@ from monai.data.box_utils import convert_box_to_standard_mode from monai.transforms.spatial.array import ConvertBoxToPoints, ConvertPointsToBoxes -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_POINTS_2D = [ [ diff --git a/tests/transforms/spatial/test_grid_patch.py b/tests/transforms/spatial/test_grid_patch.py index 56af123548..b876306213 100644 --- a/tests/transforms/spatial/test_grid_patch.py +++ b/tests/transforms/spatial/test_grid_patch.py @@ -19,7 +19,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms.spatial.array import GridPatch -from tests.utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose A = np.arange(16).repeat(3).reshape(4, 4, 3).transpose(2, 0, 1) A11 = A[:, :2, :2] diff --git a/tests/transforms/spatial/test_grid_patchd.py b/tests/transforms/spatial/test_grid_patchd.py index 53313b3a8f..ea80d335f8 100644 --- a/tests/transforms/spatial/test_grid_patchd.py +++ b/tests/transforms/spatial/test_grid_patchd.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms.spatial.dictionary import GridPatchd -from tests.utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose A = np.arange(16).repeat(3).reshape(4, 4, 3).transpose(2, 0, 1) A11 = A[:, :2, :2] diff --git a/tests/transforms/spatial/test_rand_grid_patch.py b/tests/transforms/spatial/test_rand_grid_patch.py index 26863f01b2..e542d91087 100644 --- a/tests/transforms/spatial/test_rand_grid_patch.py +++ b/tests/transforms/spatial/test_rand_grid_patch.py @@ -20,7 +20,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms.spatial.array import RandGridPatch from monai.utils import set_determinism -from tests.utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose A = np.arange(16).repeat(3).reshape(4, 4, 3).transpose(2, 0, 1) A11 = A[:, :2, :2] diff --git a/tests/transforms/spatial/test_rand_grid_patchd.py b/tests/transforms/spatial/test_rand_grid_patchd.py index 031e834512..296bb34675 100644 --- a/tests/transforms/spatial/test_rand_grid_patchd.py +++ b/tests/transforms/spatial/test_rand_grid_patchd.py @@ -19,7 +19,7 @@ from monai.transforms.spatial.dictionary import RandGridPatchd from monai.utils import set_determinism -from tests.utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose A = np.arange(16).repeat(3).reshape(4, 4, 3).transpose(2, 0, 1) A11 = A[:, :2, :2] diff --git a/tests/transforms/spatial/test_spatial_resampled.py b/tests/transforms/spatial/test_spatial_resampled.py index d5c86258d7..b9351f0c7f 100644 --- a/tests/transforms/spatial/test_spatial_resampled.py +++ b/tests/transforms/spatial/test_spatial_resampled.py @@ -22,7 +22,7 @@ from monai.data.utils import to_affine_nd from monai.transforms.spatial.dictionary import SpatialResampled from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_DEVICES, assert_allclose +from tests.utils.utils import TEST_DEVICES, assert_allclose ON_AARCH64 = platform.machine() == "aarch64" if ON_AARCH64: diff --git a/tests/transforms/test_activations.py b/tests/transforms/test_activations.py index ad18e2bbec..0dd182d349 100644 --- a/tests/transforms/test_activations.py +++ b/tests/transforms/test_activations.py @@ -18,7 +18,7 @@ from monai.networks.layers.factories import Act from monai.transforms import Activations -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TEST_CASES = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_activationsd.py b/tests/transforms/test_activationsd.py index 74968c0bb4..6a2656123f 100644 --- a/tests/transforms/test_activationsd.py +++ b/tests/transforms/test_activationsd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import Activationsd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TEST_CASES = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_add_coordinate_channels.py b/tests/transforms/test_add_coordinate_channels.py index 199fe071e3..bd0a989332 100644 --- a/tests/transforms/test_add_coordinate_channels.py +++ b/tests/transforms/test_add_coordinate_channels.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import AddCoordinateChannels -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS, TEST_CASES_ERROR_1, TEST_CASES_ERROR_2 = [], [], [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_add_coordinate_channelsd.py b/tests/transforms/test_add_coordinate_channelsd.py index c00240c2d5..e0495e8362 100644 --- a/tests/transforms/test_add_coordinate_channelsd.py +++ b/tests/transforms/test_add_coordinate_channelsd.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import AddCoordinateChannelsd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS, TEST_CASES_ERROR_1, TEST_CASES_ERROR_2 = [], [], [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_add_extreme_points_channel.py b/tests/transforms/test_add_extreme_points_channel.py index c453322d6b..b8d25113e6 100644 --- a/tests/transforms/test_add_extreme_points_channel.py +++ b/tests/transforms/test_add_extreme_points_channel.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import AddExtremePointsChannel -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose IMG_CHANNEL = 3 TESTS = [] diff --git a/tests/transforms/test_add_extreme_points_channeld.py b/tests/transforms/test_add_extreme_points_channeld.py index 026f71200a..9a10a324d0 100644 --- a/tests/transforms/test_add_extreme_points_channeld.py +++ b/tests/transforms/test_add_extreme_points_channeld.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import AddExtremePointsChanneld -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose IMG_CHANNEL = 3 diff --git a/tests/transforms/test_adjust_contrast.py b/tests/transforms/test_adjust_contrast.py index 2236056558..9215f0e146 100644 --- a/tests/transforms/test_adjust_contrast.py +++ b/tests/transforms/test_adjust_contrast.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import AdjustContrast -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose TESTS = [] for invert_image in (True, False): diff --git a/tests/transforms/test_adjust_contrastd.py b/tests/transforms/test_adjust_contrastd.py index 38eb001226..ff2d397f7d 100644 --- a/tests/transforms/test_adjust_contrastd.py +++ b/tests/transforms/test_adjust_contrastd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import AdjustContrastd -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose TESTS = [] for invert_image in (True, False): diff --git a/tests/transforms/test_affine.py b/tests/transforms/test_affine.py index a08a22ae6f..d872aa9cf5 100644 --- a/tests/transforms/test_affine.py +++ b/tests/transforms/test_affine.py @@ -23,7 +23,7 @@ from monai.transforms.lazy.functional import apply_pending from monai.utils import optional_import from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose, test_local_inversion TESTS = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_affine_grid.py b/tests/transforms/test_affine_grid.py index 2d89725bb7..9247d2e5ea 100644 --- a/tests/transforms/test_affine_grid.py +++ b/tests/transforms/test_affine_grid.py @@ -19,7 +19,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import AffineGrid -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose, is_tf32_env +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose, is_tf32_env TESTS = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_affined.py b/tests/transforms/test_affined.py index 94903ff8c7..0580097966 100644 --- a/tests/transforms/test_affined.py +++ b/tests/transforms/test_affined.py @@ -20,7 +20,7 @@ from monai.transforms import Affined from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose, test_local_inversion TESTS = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_as_channel_last.py b/tests/transforms/test_as_channel_last.py index 51e1a5c0fd..50cf122084 100644 --- a/tests/transforms/test_as_channel_last.py +++ b/tests/transforms/test_as_channel_last.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import AsChannelLast -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_as_channel_lastd.py b/tests/transforms/test_as_channel_lastd.py index aa51ab6056..f4f4ab9a3b 100644 --- a/tests/transforms/test_as_channel_lastd.py +++ b/tests/transforms/test_as_channel_lastd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import AsChannelLastd -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_as_discrete.py b/tests/transforms/test_as_discrete.py index bf59752920..9fa5b84c8f 100644 --- a/tests/transforms/test_as_discrete.py +++ b/tests/transforms/test_as_discrete.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import AsDiscrete -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TEST_CASES = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_as_discreted.py b/tests/transforms/test_as_discreted.py index ed1b3c5b3e..9cd8a800d5 100644 --- a/tests/transforms/test_as_discreted.py +++ b/tests/transforms/test_as_discreted.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import AsDiscreted -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TEST_CASES = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_bounding_rect.py b/tests/transforms/test_bounding_rect.py index b879fa6093..3e9a13fe0d 100644 --- a/tests/transforms/test_bounding_rect.py +++ b/tests/transforms/test_bounding_rect.py @@ -18,7 +18,7 @@ import monai from monai.transforms import BoundingRect -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TEST_CASE_1 = [(2, 3), [[0, 0], [1, 2]]] diff --git a/tests/transforms/test_bounding_rectd.py b/tests/transforms/test_bounding_rectd.py index 96435036b1..64adf53be3 100644 --- a/tests/transforms/test_bounding_rectd.py +++ b/tests/transforms/test_bounding_rectd.py @@ -18,7 +18,7 @@ import monai from monai.transforms import BoundingRectD -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TEST_CASE_1 = [(2, 3), [[0, 0], [1, 2]]] diff --git a/tests/transforms/test_cast_to_type.py b/tests/transforms/test_cast_to_type.py index 035260804e..cc98b38531 100644 --- a/tests/transforms/test_cast_to_type.py +++ b/tests/transforms/test_cast_to_type.py @@ -20,7 +20,7 @@ from monai.transforms import CastToType from monai.utils import optional_import from monai.utils.type_conversion import get_equivalent_dtype -from tests.utils import HAS_CUPY, TEST_NDARRAYS +from tests.utils.utils import HAS_CUPY, TEST_NDARRAYS cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_cast_to_typed.py b/tests/transforms/test_cast_to_typed.py index 81e17117a9..ad691d8eb7 100644 --- a/tests/transforms/test_cast_to_typed.py +++ b/tests/transforms/test_cast_to_typed.py @@ -19,7 +19,7 @@ from monai.transforms import CastToTyped from monai.utils import optional_import -from tests.utils import HAS_CUPY +from tests.utils.utils import HAS_CUPY cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_classes_to_indices.py b/tests/transforms/test_classes_to_indices.py index a7377dac16..1bfd5ab41b 100644 --- a/tests/transforms/test_classes_to_indices.py +++ b/tests/transforms/test_classes_to_indices.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import ClassesToIndices -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS_CASES = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_classes_to_indicesd.py b/tests/transforms/test_classes_to_indicesd.py index dead1ae753..d15d21a16e 100644 --- a/tests/transforms/test_classes_to_indicesd.py +++ b/tests/transforms/test_classes_to_indicesd.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import ClassesToIndicesd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS_CASES = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_clip_intensity_percentiles.py b/tests/transforms/test_clip_intensity_percentiles.py index 77f811db87..12b4abfde8 100644 --- a/tests/transforms/test_clip_intensity_percentiles.py +++ b/tests/transforms/test_clip_intensity_percentiles.py @@ -19,7 +19,7 @@ from monai.transforms.utils import soft_clip from monai.transforms.utils_pytorch_numpy_unification import clip, percentile from monai.utils.type_conversion import convert_to_tensor -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, NumpyImageTestCase3D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, NumpyImageTestCase3D, assert_allclose def test_hard_clip_func(im, lower, upper): diff --git a/tests/transforms/test_clip_intensity_percentilesd.py b/tests/transforms/test_clip_intensity_percentilesd.py index 334cd01620..793e5093dc 100644 --- a/tests/transforms/test_clip_intensity_percentilesd.py +++ b/tests/transforms/test_clip_intensity_percentilesd.py @@ -19,7 +19,7 @@ from monai.transforms.utils_pytorch_numpy_unification import clip, percentile from monai.utils.type_conversion import convert_to_tensor from tests.transforms.test_clip_intensity_percentiles import test_hard_clip_func, test_soft_clip_func -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, NumpyImageTestCase3D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, NumpyImageTestCase3D, assert_allclose class TestClipIntensityPercentilesd2D(NumpyImageTestCase2D): diff --git a/tests/transforms/test_concat_itemsd.py b/tests/transforms/test_concat_itemsd.py index 564ddf5c1f..ea3650e60d 100644 --- a/tests/transforms/test_concat_itemsd.py +++ b/tests/transforms/test_concat_itemsd.py @@ -18,7 +18,7 @@ from monai.data import MetaTensor from monai.transforms import ConcatItemsd -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class TestConcatItemsd(unittest.TestCase): diff --git a/tests/transforms/test_convert_to_multi_channel.py b/tests/transforms/test_convert_to_multi_channel.py index 98bbea1ebf..35715fbb76 100644 --- a/tests/transforms/test_convert_to_multi_channel.py +++ b/tests/transforms/test_convert_to_multi_channel.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import ConvertToMultiChannelBasedOnBratsClasses -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_copy_itemsd.py b/tests/transforms/test_copy_itemsd.py index a78e08897b..d19ca1c245 100644 --- a/tests/transforms/test_copy_itemsd.py +++ b/tests/transforms/test_copy_itemsd.py @@ -20,7 +20,7 @@ from monai.networks import eval_mode from monai.transforms import CopyItemsd from monai.utils import ensure_tuple -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_1 = ["img", 1, "img_1"] diff --git a/tests/transforms/test_create_grid_and_affine.py b/tests/transforms/test_create_grid_and_affine.py index 4910a10470..8e95960277 100644 --- a/tests/transforms/test_create_grid_and_affine.py +++ b/tests/transforms/test_create_grid_and_affine.py @@ -24,7 +24,7 @@ create_shear, create_translate, ) -from tests.utils import assert_allclose, is_tf32_env +from tests.utils.utils import assert_allclose, is_tf32_env class TestCreateGrid(unittest.TestCase): diff --git a/tests/transforms/test_crop_foreground.py b/tests/transforms/test_crop_foreground.py index f63cb3e8b0..186926c352 100644 --- a/tests/transforms/test_crop_foreground.py +++ b/tests/transforms/test_crop_foreground.py @@ -20,7 +20,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import CropForeground from monai.transforms.lazy.functional import apply_pending -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TEST_COORDS, TESTS, TEST_LAZY_ERROR = [], [], [] diff --git a/tests/transforms/test_crop_foregroundd.py b/tests/transforms/test_crop_foregroundd.py index 92954aa81e..d3b5349957 100644 --- a/tests/transforms/test_crop_foregroundd.py +++ b/tests/transforms/test_crop_foregroundd.py @@ -19,7 +19,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import CropForegroundd from monai.transforms.lazy.functional import apply_pending -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TEST_POSITION, TESTS = [], [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_cucim_dict_transform.py b/tests/transforms/test_cucim_dict_transform.py index 3c5703a34c..c90609d7db 100644 --- a/tests/transforms/test_cucim_dict_transform.py +++ b/tests/transforms/test_cucim_dict_transform.py @@ -18,7 +18,7 @@ from monai.transforms import CuCIMd from monai.utils import optional_import, set_determinism -from tests.utils import HAS_CUPY, skip_if_no_cuda +from tests.utils.utils import HAS_CUPY, skip_if_no_cuda _, has_cut = optional_import("cucim.core.operations.expose.transform") cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_cucim_transform.py b/tests/transforms/test_cucim_transform.py index 162e16b52a..49ceecb5f4 100644 --- a/tests/transforms/test_cucim_transform.py +++ b/tests/transforms/test_cucim_transform.py @@ -18,7 +18,7 @@ from monai.transforms import CuCIM from monai.utils import optional_import, set_determinism -from tests.utils import HAS_CUPY, skip_if_no_cuda +from tests.utils.utils import HAS_CUPY, skip_if_no_cuda _, has_cut = optional_import("cucim.core.operations.expose.transform") cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_detect_envelope.py b/tests/transforms/test_detect_envelope.py index f9c2b5ac53..398bb74c5b 100644 --- a/tests/transforms/test_detect_envelope.py +++ b/tests/transforms/test_detect_envelope.py @@ -19,7 +19,7 @@ from monai.transforms import DetectEnvelope from monai.utils import OptionalImportError -from tests.utils import TEST_NDARRAYS, SkipIfModule, SkipIfNoModule, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, SkipIfModule, SkipIfNoModule, assert_allclose n_samples = 500 hann_windowed_sine = np.sin(2 * np.pi * 10 * np.linspace(0, 1, n_samples)) * np.hanning(n_samples) diff --git a/tests/transforms/test_distance_transform_edt.py b/tests/transforms/test_distance_transform_edt.py index cf5c253c0c..0ce710b2fc 100644 --- a/tests/transforms/test_distance_transform_edt.py +++ b/tests/transforms/test_distance_transform_edt.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import DistanceTransformEDT, DistanceTransformEDTd -from tests.utils import HAS_CUPY, assert_allclose, optional_import, skip_if_no_cuda +from tests.utils.utils import HAS_CUPY, assert_allclose, optional_import, skip_if_no_cuda momorphology, has_cucim = optional_import("cucim.core.operations.morphology") ndimage, has_ndimage = optional_import("scipy.ndimage") diff --git a/tests/transforms/test_ensure_type.py b/tests/transforms/test_ensure_type.py index 00b01898b3..c7eec4d7c0 100644 --- a/tests/transforms/test_ensure_type.py +++ b/tests/transforms/test_ensure_type.py @@ -18,7 +18,7 @@ from monai.data import MetaTensor from monai.transforms import EnsureType -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class TestEnsureType(unittest.TestCase): diff --git a/tests/transforms/test_ensure_typed.py b/tests/transforms/test_ensure_typed.py index fe543347de..a7a116f355 100644 --- a/tests/transforms/test_ensure_typed.py +++ b/tests/transforms/test_ensure_typed.py @@ -18,7 +18,7 @@ from monai.data import MetaTensor from monai.transforms import EnsureTyped -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class TestEnsureTyped(unittest.TestCase): diff --git a/tests/transforms/test_fg_bg_to_indices.py b/tests/transforms/test_fg_bg_to_indices.py index a28c491333..9dedcf1433 100644 --- a/tests/transforms/test_fg_bg_to_indices.py +++ b/tests/transforms/test_fg_bg_to_indices.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import FgBgToIndices -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS_CASES = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_fg_bg_to_indicesd.py b/tests/transforms/test_fg_bg_to_indicesd.py index c6dd2059f4..7f81625dad 100644 --- a/tests/transforms/test_fg_bg_to_indicesd.py +++ b/tests/transforms/test_fg_bg_to_indicesd.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import FgBgToIndicesd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TEST_CASES = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_fill_holes.py b/tests/transforms/test_fill_holes.py index 241f7f8254..aa76b6d812 100644 --- a/tests/transforms/test_fill_holes.py +++ b/tests/transforms/test_fill_holes.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import FillHoles -from tests.utils import TEST_NDARRAYS, assert_allclose, clone +from tests.utils.utils import TEST_NDARRAYS, assert_allclose, clone grid_1_raw = [[1, 1, 1], [1, 0, 1], [1, 1, 1]] diff --git a/tests/transforms/test_fill_holesd.py b/tests/transforms/test_fill_holesd.py index 28c17b00ac..70005fe368 100644 --- a/tests/transforms/test_fill_holesd.py +++ b/tests/transforms/test_fill_holesd.py @@ -18,7 +18,7 @@ from monai.transforms import FillHolesd from monai.utils.enums import CommonKeys -from tests.utils import TEST_NDARRAYS, assert_allclose, clone +from tests.utils.utils import TEST_NDARRAYS, assert_allclose, clone grid_1_raw = [[1, 1, 1], [1, 0, 1], [1, 1, 1]] diff --git a/tests/transforms/test_flip.py b/tests/transforms/test_flip.py index 789ec86920..aa3cedbfec 100644 --- a/tests/transforms/test_flip.py +++ b/tests/transforms/test_flip.py @@ -21,7 +21,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import Flip from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_DEVICES, TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_DEVICES, TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion INVALID_CASES = [("wrong_axis", ["s", 1], TypeError), ("not_numbers", "s", TypeError)] diff --git a/tests/transforms/test_flipd.py b/tests/transforms/test_flipd.py index 1df6d34056..658ab6f97c 100644 --- a/tests/transforms/test_flipd.py +++ b/tests/transforms/test_flipd.py @@ -22,7 +22,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import Flipd from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_DEVICES, TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_DEVICES, TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion INVALID_CASES = [("wrong_axis", ["s", 1], TypeError), ("not_numbers", "s", TypeError)] diff --git a/tests/transforms/test_fourier.py b/tests/transforms/test_fourier.py index 177fc280f7..374605500f 100644 --- a/tests/transforms/test_fourier.py +++ b/tests/transforms/test_fourier.py @@ -20,7 +20,7 @@ from monai.data.synthetic import create_test_image_2d, create_test_image_3d from monai.transforms import Fourier from monai.utils.misc import set_determinism -from tests.utils import SkipIfBeforePyTorchVersion, SkipIfNoModule +from tests.utils.utils import SkipIfBeforePyTorchVersion, SkipIfNoModule TEST_CASES = [((128, 64),), ((64, 48, 80),)] diff --git a/tests/transforms/test_gaussian_sharpen.py b/tests/transforms/test_gaussian_sharpen.py index 392a7b376b..c5246cde66 100644 --- a/tests/transforms/test_gaussian_sharpen.py +++ b/tests/transforms/test_gaussian_sharpen.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import GaussianSharpen -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] diff --git a/tests/transforms/test_gaussian_sharpend.py b/tests/transforms/test_gaussian_sharpend.py index 15b219fd2c..43a9f10de3 100644 --- a/tests/transforms/test_gaussian_sharpend.py +++ b/tests/transforms/test_gaussian_sharpend.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import GaussianSharpend -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_gaussian_smooth.py b/tests/transforms/test_gaussian_smooth.py index 9f99ebe0f8..88a4fbaca6 100644 --- a/tests/transforms/test_gaussian_smooth.py +++ b/tests/transforms/test_gaussian_smooth.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import GaussianSmooth -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] diff --git a/tests/transforms/test_gaussian_smoothd.py b/tests/transforms/test_gaussian_smoothd.py index a6de4a159b..635d58a6af 100644 --- a/tests/transforms/test_gaussian_smoothd.py +++ b/tests/transforms/test_gaussian_smoothd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import GaussianSmoothd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_generate_label_classes_crop_centers.py b/tests/transforms/test_generate_label_classes_crop_centers.py index 1cbb5f05c3..abef65ec98 100644 --- a/tests/transforms/test_generate_label_classes_crop_centers.py +++ b/tests/transforms/test_generate_label_classes_crop_centers.py @@ -18,7 +18,7 @@ from monai.transforms import generate_label_classes_crop_centers from monai.utils.misc import set_determinism -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TEST_CASE_1 = [ { diff --git a/tests/transforms/test_generate_pos_neg_label_crop_centers.py b/tests/transforms/test_generate_pos_neg_label_crop_centers.py index de127b33df..9bc091cd80 100644 --- a/tests/transforms/test_generate_pos_neg_label_crop_centers.py +++ b/tests/transforms/test_generate_pos_neg_label_crop_centers.py @@ -18,7 +18,7 @@ from monai.transforms import generate_pos_neg_label_crop_centers from monai.utils.misc import set_determinism -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [ [ diff --git a/tests/transforms/test_generate_spatial_bounding_box.py b/tests/transforms/test_generate_spatial_bounding_box.py index 6d5b415ec2..717fb3e0c9 100644 --- a/tests/transforms/test_generate_spatial_bounding_box.py +++ b/tests/transforms/test_generate_spatial_bounding_box.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import generate_spatial_bounding_box -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_get_extreme_points.py b/tests/transforms/test_get_extreme_points.py index e60715e2fe..6c83874150 100644 --- a/tests/transforms/test_get_extreme_points.py +++ b/tests/transforms/test_get_extreme_points.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import get_extreme_points -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_gibbs_noise.py b/tests/transforms/test_gibbs_noise.py index bdc66b9495..c0a150fe5a 100644 --- a/tests/transforms/test_gibbs_noise.py +++ b/tests/transforms/test_gibbs_noise.py @@ -21,7 +21,7 @@ from monai.transforms import GibbsNoise from monai.utils.misc import set_determinism from monai.utils.module import optional_import -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose _, has_torch_fft = optional_import("torch.fft", name="fftshift") diff --git a/tests/transforms/test_gibbs_noised.py b/tests/transforms/test_gibbs_noised.py index 3b2cae7e84..dd5deac72c 100644 --- a/tests/transforms/test_gibbs_noised.py +++ b/tests/transforms/test_gibbs_noised.py @@ -21,7 +21,7 @@ from monai.transforms import GibbsNoised from monai.utils.misc import set_determinism from monai.utils.module import optional_import -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose _, has_torch_fft = optional_import("torch.fft", name="fftshift") diff --git a/tests/transforms/test_grid_distortion.py b/tests/transforms/test_grid_distortion.py index 9ec85250e8..8d5fcf997e 100644 --- a/tests/transforms/test_grid_distortion.py +++ b/tests/transforms/test_grid_distortion.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import GridDistortion -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_grid_distortiond.py b/tests/transforms/test_grid_distortiond.py index ce73593dc7..7e4006a18f 100644 --- a/tests/transforms/test_grid_distortiond.py +++ b/tests/transforms/test_grid_distortiond.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import GridDistortiond -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS = [] num_cells = (2, 2) diff --git a/tests/transforms/test_grid_split.py b/tests/transforms/test_grid_split.py index 852a4847a6..5204d7e86a 100644 --- a/tests/transforms/test_grid_split.py +++ b/tests/transforms/test_grid_split.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import GridSplit -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose A11 = torch.randn(3, 2, 2) A12 = torch.randn(3, 2, 2) diff --git a/tests/transforms/test_grid_splitd.py b/tests/transforms/test_grid_splitd.py index 215076d5a3..4ef098682e 100644 --- a/tests/transforms/test_grid_splitd.py +++ b/tests/transforms/test_grid_splitd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import GridSplitd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose A11 = torch.randn(3, 2, 2) A12 = torch.randn(3, 2, 2) diff --git a/tests/transforms/test_histogram_normalize.py b/tests/transforms/test_histogram_normalize.py index 25c0afb64d..c89ea148a1 100644 --- a/tests/transforms/test_histogram_normalize.py +++ b/tests/transforms/test_histogram_normalize.py @@ -18,7 +18,7 @@ from monai.transforms import HistogramNormalize from monai.utils import get_equivalent_dtype -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_histogram_normalized.py b/tests/transforms/test_histogram_normalized.py index a390375441..4de640692e 100644 --- a/tests/transforms/test_histogram_normalized.py +++ b/tests/transforms/test_histogram_normalized.py @@ -18,7 +18,7 @@ from monai.transforms import HistogramNormalized from monai.utils import get_equivalent_dtype -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_intensity_stats.py b/tests/transforms/test_intensity_stats.py index e45c2acbad..5725a8b0c2 100644 --- a/tests/transforms/test_intensity_stats.py +++ b/tests/transforms/test_intensity_stats.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import IntensityStats -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_inverse.py b/tests/transforms/test_inverse.py index 6bd14a19f1..84e8373011 100644 --- a/tests/transforms/test_inverse.py +++ b/tests/transforms/test_inverse.py @@ -69,7 +69,7 @@ reset_ops_id, ) from monai.utils import first, get_seed, optional_import, set_determinism -from tests.utils import make_nifti_image, make_rand_affine +from tests.utils.utils import make_nifti_image, make_rand_affine if TYPE_CHECKING: has_nib = True diff --git a/tests/transforms/test_inverse_collation.py b/tests/transforms/test_inverse_collation.py index bf3972e6bd..5c7b032ec4 100644 --- a/tests/transforms/test_inverse_collation.py +++ b/tests/transforms/test_inverse_collation.py @@ -43,7 +43,7 @@ Rotated, ) from monai.utils import optional_import, set_determinism -from tests.utils import make_nifti_image +from tests.utils.utils import make_nifti_image if TYPE_CHECKING: has_nib = True diff --git a/tests/transforms/test_invert.py b/tests/transforms/test_invert.py index 69d31edfc8..a018388acc 100644 --- a/tests/transforms/test_invert.py +++ b/tests/transforms/test_invert.py @@ -37,7 +37,7 @@ Spacing, ) from monai.utils import set_determinism -from tests.utils import assert_allclose, make_nifti_image +from tests.utils.utils import assert_allclose, make_nifti_image class TestInvert(unittest.TestCase): diff --git a/tests/transforms/test_invertd.py b/tests/transforms/test_invertd.py index f6e8fc40e7..515c2e939c 100644 --- a/tests/transforms/test_invertd.py +++ b/tests/transforms/test_invertd.py @@ -37,7 +37,7 @@ Spacingd, ) from monai.utils import set_determinism -from tests.utils import assert_allclose, make_nifti_image +from tests.utils.utils import assert_allclose, make_nifti_image KEYS = ["image", "label"] diff --git a/tests/transforms/test_k_space_spike_noise.py b/tests/transforms/test_k_space_spike_noise.py index 17acedf319..77a1323428 100644 --- a/tests/transforms/test_k_space_spike_noise.py +++ b/tests/transforms/test_k_space_spike_noise.py @@ -22,7 +22,7 @@ from monai.data.synthetic import create_test_image_2d, create_test_image_3d from monai.transforms import KSpaceSpikeNoise from monai.utils.misc import set_determinism -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TESTS = [] for shape in ((128, 64), (64, 48, 80)): diff --git a/tests/transforms/test_k_space_spike_noised.py b/tests/transforms/test_k_space_spike_noised.py index ce542af0aa..02da2c6b36 100644 --- a/tests/transforms/test_k_space_spike_noised.py +++ b/tests/transforms/test_k_space_spike_noised.py @@ -22,7 +22,7 @@ from monai.data.synthetic import create_test_image_2d, create_test_image_3d from monai.transforms import KSpaceSpikeNoised from monai.utils.misc import set_determinism -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for shape in ((128, 64), (64, 48, 80)): diff --git a/tests/transforms/test_keep_largest_connected_component.py b/tests/transforms/test_keep_largest_connected_component.py index 2dfac1142e..d0ade077ff 100644 --- a/tests/transforms/test_keep_largest_connected_component.py +++ b/tests/transforms/test_keep_largest_connected_component.py @@ -21,7 +21,7 @@ from monai.transforms import KeepLargestConnectedComponent from monai.transforms.utils_pytorch_numpy_unification import moveaxis from monai.utils.type_conversion import convert_to_dst_type -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose def to_onehot(x): diff --git a/tests/transforms/test_keep_largest_connected_componentd.py b/tests/transforms/test_keep_largest_connected_componentd.py index 4d3172741d..ca2c4e03c6 100644 --- a/tests/transforms/test_keep_largest_connected_componentd.py +++ b/tests/transforms/test_keep_largest_connected_componentd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import KeepLargestConnectedComponentd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose grid_1 = [[[0, 0, 1, 0, 0], [0, 2, 1, 1, 1], [1, 2, 1, 0, 0], [1, 2, 0, 1, 0], [2, 2, 0, 0, 2]]] grid_2 = [[[0, 0, 0, 0, 1], [0, 0, 1, 1, 1], [1, 0, 1, 1, 2], [1, 0, 1, 2, 2], [0, 0, 0, 0, 1]]] diff --git a/tests/transforms/test_label_filter.py b/tests/transforms/test_label_filter.py index 93cf95a2a0..9c63697e05 100644 --- a/tests/transforms/test_label_filter.py +++ b/tests/transforms/test_label_filter.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import LabelFilter -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose grid_1 = torch.tensor([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]) diff --git a/tests/transforms/test_label_to_contour.py b/tests/transforms/test_label_to_contour.py index d7fbfc9b8d..d2716fe4b1 100644 --- a/tests/transforms/test_label_to_contour.py +++ b/tests/transforms/test_label_to_contour.py @@ -17,7 +17,7 @@ import torch from monai.transforms import LabelToContour -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose expected_output_for_cube = [ [ diff --git a/tests/transforms/test_label_to_contourd.py b/tests/transforms/test_label_to_contourd.py index a91a712da6..fd4ed5334b 100644 --- a/tests/transforms/test_label_to_contourd.py +++ b/tests/transforms/test_label_to_contourd.py @@ -17,7 +17,7 @@ import torch from monai.transforms import LabelToContourd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose expected_output_for_cube = [ [ diff --git a/tests/transforms/test_label_to_mask.py b/tests/transforms/test_label_to_mask.py index 47a58cc989..9fb7f5533b 100644 --- a/tests/transforms/test_label_to_mask.py +++ b/tests/transforms/test_label_to_mask.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import LabelToMask -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_label_to_maskd.py b/tests/transforms/test_label_to_maskd.py index 44b537128d..de2cd75c3c 100644 --- a/tests/transforms/test_label_to_maskd.py +++ b/tests/transforms/test_label_to_maskd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import LabelToMaskd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_load_image.py b/tests/transforms/test_load_image.py index 0207079d7d..d2129a1f1d 100644 --- a/tests/transforms/test_load_image.py +++ b/tests/transforms/test_load_image.py @@ -29,7 +29,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import LoadImage from monai.utils import optional_import -from tests.utils import assert_allclose, skip_if_downloading_fails, testing_data_config +from tests.utils.utils import assert_allclose, skip_if_downloading_fails, testing_data_config itk, has_itk = optional_import("itk", allow_namespace_pkg=True) ITKReader, _ = optional_import("monai.data", name="ITKReader", as_type="decorator") diff --git a/tests/transforms/test_load_imaged.py b/tests/transforms/test_load_imaged.py index 914240c705..93e277ceb9 100644 --- a/tests/transforms/test_load_imaged.py +++ b/tests/transforms/test_load_imaged.py @@ -28,7 +28,7 @@ from monai.transforms import Compose, EnsureChannelFirstD, FromMetaTensord, LoadImaged, SaveImageD from monai.transforms.meta_utility.dictionary import ToMetaTensord from monai.utils import optional_import -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose itk, has_itk = optional_import("itk", allow_namespace_pkg=True) diff --git a/tests/transforms/test_map_and_generate_sampling_centers.py b/tests/transforms/test_map_and_generate_sampling_centers.py index ff74f974b9..486513ff87 100644 --- a/tests/transforms/test_map_and_generate_sampling_centers.py +++ b/tests/transforms/test_map_and_generate_sampling_centers.py @@ -19,7 +19,7 @@ from monai.transforms import map_and_generate_sampling_centers from monai.utils.misc import set_determinism -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TEST_CASE_1 = [ # test Argmax data diff --git a/tests/transforms/test_map_binary_to_indices.py b/tests/transforms/test_map_binary_to_indices.py index 9931d997bb..0598836b3d 100644 --- a/tests/transforms/test_map_binary_to_indices.py +++ b/tests/transforms/test_map_binary_to_indices.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import map_binary_to_indices -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_map_classes_to_indices.py b/tests/transforms/test_map_classes_to_indices.py index 902744ab65..f05739d78e 100644 --- a/tests/transforms/test_map_classes_to_indices.py +++ b/tests/transforms/test_map_classes_to_indices.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import map_classes_to_indices -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_map_label_value.py b/tests/transforms/test_map_label_value.py index cd311df6bd..d9899aa5dd 100644 --- a/tests/transforms/test_map_label_value.py +++ b/tests/transforms/test_map_label_value.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import MapLabelValue -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_map_label_valued.py b/tests/transforms/test_map_label_valued.py index 0fb46f2515..37a02b5747 100644 --- a/tests/transforms/test_map_label_valued.py +++ b/tests/transforms/test_map_label_valued.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import MapLabelValued -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_1 = [ {"keys": "seg", "orig_labels": [3, 2, 1], "target_labels": [0, 1, 2]}, diff --git a/tests/transforms/test_mask_intensity.py b/tests/transforms/test_mask_intensity.py index b7ff324946..e112f2ec41 100644 --- a/tests/transforms/test_mask_intensity.py +++ b/tests/transforms/test_mask_intensity.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import MaskIntensity -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TEST_CASE_1 = [ {"mask_data": np.array([[[0, 0, 0], [0, 1, 0], [0, 0, 0]]])}, diff --git a/tests/transforms/test_mean_ensemble.py b/tests/transforms/test_mean_ensemble.py index 6b463f8530..f1457f2ec0 100644 --- a/tests/transforms/test_mean_ensemble.py +++ b/tests/transforms/test_mean_ensemble.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import MeanEnsemble -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_mean_ensembled.py b/tests/transforms/test_mean_ensembled.py index 795ae47368..eed953c0d8 100644 --- a/tests/transforms/test_mean_ensembled.py +++ b/tests/transforms/test_mean_ensembled.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import MeanEnsembled -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_median_smooth.py b/tests/transforms/test_median_smooth.py index 5930c0c6b6..d0bf806d70 100644 --- a/tests/transforms/test_median_smooth.py +++ b/tests/transforms/test_median_smooth.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import MedianSmooth -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] diff --git a/tests/transforms/test_median_smoothd.py b/tests/transforms/test_median_smoothd.py index e0bdb331c8..f6423d863b 100644 --- a/tests/transforms/test_median_smoothd.py +++ b/tests/transforms/test_median_smoothd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import MedianSmoothd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS[0:1]: diff --git a/tests/transforms/test_morphological_ops.py b/tests/transforms/test_morphological_ops.py index 422e8c4b9d..b7a9d539cd 100644 --- a/tests/transforms/test_morphological_ops.py +++ b/tests/transforms/test_morphological_ops.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms.utils_morphological_ops import dilate, erode, get_morphological_filter_result_t -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS_SHAPE = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_normalize_intensity.py b/tests/transforms/test_normalize_intensity.py index 72ebf579e1..29f0213abd 100644 --- a/tests/transforms/test_normalize_intensity.py +++ b/tests/transforms/test_normalize_intensity.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import NormalizeIntensity -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_normalize_intensityd.py b/tests/transforms/test_normalize_intensityd.py index 229dcd00ff..ad9b8ef21b 100644 --- a/tests/transforms/test_normalize_intensityd.py +++ b/tests/transforms/test_normalize_intensityd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import NormalizeIntensityd -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_nvtx_decorator.py b/tests/transforms/test_nvtx_decorator.py index efd2906972..b8f83c1c8c 100644 --- a/tests/transforms/test_nvtx_decorator.py +++ b/tests/transforms/test_nvtx_decorator.py @@ -35,7 +35,7 @@ ToTensord, ) from monai.utils import Range, optional_import -from tests.utils import HAS_CUPY +from tests.utils.utils import HAS_CUPY _, has_nvtx = optional_import("torch._C._nvtx", descriptor="NVTX is not installed. Are you sure you have a CUDA build?") _, has_tvt = optional_import("torchvision.transforms") diff --git a/tests/transforms/test_orientation.py b/tests/transforms/test_orientation.py index 2f3334e622..7255b7ea46 100644 --- a/tests/transforms/test_orientation.py +++ b/tests/transforms/test_orientation.py @@ -22,7 +22,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import Orientation, create_rotate, create_translate from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_DEVICES, assert_allclose +from tests.utils.utils import TEST_DEVICES, assert_allclose TESTS = [] for device in TEST_DEVICES: diff --git a/tests/transforms/test_orientationd.py b/tests/transforms/test_orientationd.py index b885266c69..a7f78b4d24 100644 --- a/tests/transforms/test_orientationd.py +++ b/tests/transforms/test_orientationd.py @@ -22,7 +22,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import Orientationd from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_DEVICES +from tests.utils.utils import TEST_DEVICES TESTS = [] for device in TEST_DEVICES: diff --git a/tests/transforms/test_rand_adjust_contrast.py b/tests/transforms/test_rand_adjust_contrast.py index 72d0df141e..8ecd33d4ca 100644 --- a/tests/transforms/test_rand_adjust_contrast.py +++ b/tests/transforms/test_rand_adjust_contrast.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandAdjustContrast -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose TEST_CASE_1 = [(0.5, 4.5)] diff --git a/tests/transforms/test_rand_adjust_contrastd.py b/tests/transforms/test_rand_adjust_contrastd.py index bbd5c22009..b6f8e4cd7a 100644 --- a/tests/transforms/test_rand_adjust_contrastd.py +++ b/tests/transforms/test_rand_adjust_contrastd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandAdjustContrastd -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose TEST_CASE_1 = [(0.5, 4.5)] diff --git a/tests/transforms/test_rand_affine.py b/tests/transforms/test_rand_affine.py index 2c827b7426..9e0e07d203 100644 --- a/tests/transforms/test_rand_affine.py +++ b/tests/transforms/test_rand_affine.py @@ -20,7 +20,7 @@ from monai.transforms import RandAffine from monai.utils.type_conversion import convert_data_type from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose, is_tf32_env +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose, is_tf32_env _rtol = 1e-3 if is_tf32_env() else 1e-4 diff --git a/tests/transforms/test_rand_affine_grid.py b/tests/transforms/test_rand_affine_grid.py index 91558ebd03..9f1bc9d833 100644 --- a/tests/transforms/test_rand_affine_grid.py +++ b/tests/transforms/test_rand_affine_grid.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import RandAffineGrid -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose, is_tf32_env +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose, is_tf32_env _rtol = 1e-1 if is_tf32_env() else 1e-4 diff --git a/tests/transforms/test_rand_affined.py b/tests/transforms/test_rand_affined.py index eb8ebd06c5..35c080cad0 100644 --- a/tests/transforms/test_rand_affined.py +++ b/tests/transforms/test_rand_affined.py @@ -22,7 +22,7 @@ from monai.transforms import RandAffined from monai.utils import GridSampleMode, ensure_tuple_rep from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import assert_allclose, is_tf32_env +from tests.utils.utils import assert_allclose, is_tf32_env _rtol = 1e-3 if is_tf32_env() else 1e-4 diff --git a/tests/transforms/test_rand_axis_flip.py b/tests/transforms/test_rand_axis_flip.py index 9c465a0bcb..2759e90085 100644 --- a/tests/transforms/test_rand_axis_flip.py +++ b/tests/transforms/test_rand_axis_flip.py @@ -19,7 +19,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import RandAxisFlip from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion class TestRandAxisFlip(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rand_axis_flipd.py b/tests/transforms/test_rand_axis_flipd.py index d3abef1be4..1514f5b30f 100644 --- a/tests/transforms/test_rand_axis_flipd.py +++ b/tests/transforms/test_rand_axis_flipd.py @@ -19,7 +19,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import RandAxisFlipd from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase3D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase3D, assert_allclose, test_local_inversion class TestRandAxisFlip(NumpyImageTestCase3D): diff --git a/tests/transforms/test_rand_bias_field.py b/tests/transforms/test_rand_bias_field.py index 328f46b7ee..da76ab08bd 100644 --- a/tests/transforms/test_rand_bias_field.py +++ b/tests/transforms/test_rand_bias_field.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import RandBiasField -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TEST_CASES_2D = [{"prob": 1.0}, (3, 32, 32)] TEST_CASES_3D = [{"prob": 1.0}, (3, 32, 32, 32)] diff --git a/tests/transforms/test_rand_coarse_dropout.py b/tests/transforms/test_rand_coarse_dropout.py index ac857f9184..40a180fa01 100644 --- a/tests/transforms/test_rand_coarse_dropout.py +++ b/tests/transforms/test_rand_coarse_dropout.py @@ -19,7 +19,7 @@ from monai.transforms import RandCoarseDropout from monai.utils import fall_back_tuple -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TEST_CASE_0 = [ {"holes": 2, "spatial_size": [2, 2, 2], "fill_value": 5, "prob": 1.0}, diff --git a/tests/transforms/test_rand_crop_by_label_classes.py b/tests/transforms/test_rand_crop_by_label_classes.py index 743b894d75..9c1a4d31a5 100644 --- a/tests/transforms/test_rand_crop_by_label_classes.py +++ b/tests/transforms/test_rand_crop_by_label_classes.py @@ -19,7 +19,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import ClassesToIndices, RandCropByLabelClasses from monai.transforms.lazy.functional import apply_pending -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS_INDICES, TESTS_SHAPE = [], [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_rand_crop_by_label_classesd.py b/tests/transforms/test_rand_crop_by_label_classesd.py index 8908c456ee..bf39d7a17b 100644 --- a/tests/transforms/test_rand_crop_by_label_classesd.py +++ b/tests/transforms/test_rand_crop_by_label_classesd.py @@ -19,7 +19,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import ClassesToIndicesd, RandCropByLabelClassesd from monai.transforms.lazy.functional import apply_pending -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_rand_crop_by_pos_neg_label.py b/tests/transforms/test_rand_crop_by_pos_neg_label.py index 66e7a5e849..e5c8750e25 100644 --- a/tests/transforms/test_rand_crop_by_pos_neg_label.py +++ b/tests/transforms/test_rand_crop_by_pos_neg_label.py @@ -20,7 +20,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import RandCropByPosNegLabel from monai.transforms.lazy.functional import apply_pending -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS = [ [ diff --git a/tests/transforms/test_rand_crop_by_pos_neg_labeld.py b/tests/transforms/test_rand_crop_by_pos_neg_labeld.py index 11381e226d..20ff2715ff 100644 --- a/tests/transforms/test_rand_crop_by_pos_neg_labeld.py +++ b/tests/transforms/test_rand_crop_by_pos_neg_labeld.py @@ -20,7 +20,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import RandCropByPosNegLabeld from monai.transforms.lazy.functional import apply_pending -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS = [ [ diff --git a/tests/transforms/test_rand_cucim_dict_transform.py b/tests/transforms/test_rand_cucim_dict_transform.py index 3f473897dd..0649d1da4e 100644 --- a/tests/transforms/test_rand_cucim_dict_transform.py +++ b/tests/transforms/test_rand_cucim_dict_transform.py @@ -18,7 +18,7 @@ from monai.transforms import RandCuCIMd from monai.utils import optional_import, set_determinism -from tests.utils import HAS_CUPY, skip_if_no_cuda +from tests.utils.utils import HAS_CUPY, skip_if_no_cuda _, has_cut = optional_import("cucim.core.operations.expose.transform") cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_rand_cucim_transform.py b/tests/transforms/test_rand_cucim_transform.py index ce731a05ae..feb7266dca 100644 --- a/tests/transforms/test_rand_cucim_transform.py +++ b/tests/transforms/test_rand_cucim_transform.py @@ -18,7 +18,7 @@ from monai.transforms import RandCuCIM from monai.utils import optional_import, set_determinism -from tests.utils import HAS_CUPY, skip_if_no_cuda +from tests.utils.utils import HAS_CUPY, skip_if_no_cuda _, has_cut = optional_import("cucim.core.operations.expose.transform") cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_rand_deform_grid.py b/tests/transforms/test_rand_deform_grid.py index 88fc1333ec..3a801f8ba0 100644 --- a/tests/transforms/test_rand_deform_grid.py +++ b/tests/transforms/test_rand_deform_grid.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandDeformGrid -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASES = [ [ diff --git a/tests/transforms/test_rand_elastic_2d.py b/tests/transforms/test_rand_elastic_2d.py index 1f3d389a93..9b90c64d49 100644 --- a/tests/transforms/test_rand_elastic_2d.py +++ b/tests/transforms/test_rand_elastic_2d.py @@ -19,7 +19,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import Rand2DElastic -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose, is_tf32_env +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose, is_tf32_env _rtol = 5e-3 if is_tf32_env() else 1e-4 diff --git a/tests/transforms/test_rand_elastic_3d.py b/tests/transforms/test_rand_elastic_3d.py index 5bfa8a6e83..e476020f48 100644 --- a/tests/transforms/test_rand_elastic_3d.py +++ b/tests/transforms/test_rand_elastic_3d.py @@ -19,7 +19,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import Rand3DElastic -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_rand_elasticd_2d.py b/tests/transforms/test_rand_elasticd_2d.py index 10aa116192..c9fa30de24 100644 --- a/tests/transforms/test_rand_elasticd_2d.py +++ b/tests/transforms/test_rand_elasticd_2d.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import Rand2DElasticd -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose, is_tf32_env +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose, is_tf32_env _rtol = 5e-3 if is_tf32_env() else 1e-4 diff --git a/tests/transforms/test_rand_elasticd_3d.py b/tests/transforms/test_rand_elasticd_3d.py index 3838f43f29..6475623de3 100644 --- a/tests/transforms/test_rand_elasticd_3d.py +++ b/tests/transforms/test_rand_elasticd_3d.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import Rand3DElasticd -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_rand_flip.py b/tests/transforms/test_rand_flip.py index faeae94cab..7df3c8955c 100644 --- a/tests/transforms/test_rand_flip.py +++ b/tests/transforms/test_rand_flip.py @@ -20,7 +20,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import RandFlip from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion INVALID_CASES = [("wrong_axis", ["s", 1], TypeError), ("not_numbers", "s", TypeError)] diff --git a/tests/transforms/test_rand_flipd.py b/tests/transforms/test_rand_flipd.py index a34aa58ed2..064e1cb8d1 100644 --- a/tests/transforms/test_rand_flipd.py +++ b/tests/transforms/test_rand_flipd.py @@ -20,7 +20,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import RandFlipd from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion VALID_CASES = [("no_axis", None), ("one_axis", 1), ("many_axis", [0, 1])] diff --git a/tests/transforms/test_rand_gaussian_noise.py b/tests/transforms/test_rand_gaussian_noise.py index 233b4dd1b6..703812409f 100644 --- a/tests/transforms/test_rand_gaussian_noise.py +++ b/tests/transforms/test_rand_gaussian_noise.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import RandGaussianNoise -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_rand_gaussian_noised.py b/tests/transforms/test_rand_gaussian_noised.py index e3df196be2..a4bbd7ce91 100644 --- a/tests/transforms/test_rand_gaussian_noised.py +++ b/tests/transforms/test_rand_gaussian_noised.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import RandGaussianNoised -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_rand_gaussian_sharpen.py b/tests/transforms/test_rand_gaussian_sharpen.py index ee8604c14b..69b37d0b8b 100644 --- a/tests/transforms/test_rand_gaussian_sharpen.py +++ b/tests/transforms/test_rand_gaussian_sharpen.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import RandGaussianSharpen -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] diff --git a/tests/transforms/test_rand_gaussian_sharpend.py b/tests/transforms/test_rand_gaussian_sharpend.py index b9bae529db..79e1171a81 100644 --- a/tests/transforms/test_rand_gaussian_sharpend.py +++ b/tests/transforms/test_rand_gaussian_sharpend.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandGaussianSharpend -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_rand_gaussian_smooth.py b/tests/transforms/test_rand_gaussian_smooth.py index 8bb36ca0fa..3664f4d811 100644 --- a/tests/transforms/test_rand_gaussian_smooth.py +++ b/tests/transforms/test_rand_gaussian_smooth.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandGaussianSmooth -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_rand_gaussian_smoothd.py b/tests/transforms/test_rand_gaussian_smoothd.py index a93b355184..95fbcc17f5 100644 --- a/tests/transforms/test_rand_gaussian_smoothd.py +++ b/tests/transforms/test_rand_gaussian_smoothd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandGaussianSmoothd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_rand_gibbs_noise.py b/tests/transforms/test_rand_gibbs_noise.py index 5ef249a1f4..422d0ec15f 100644 --- a/tests/transforms/test_rand_gibbs_noise.py +++ b/tests/transforms/test_rand_gibbs_noise.py @@ -21,7 +21,7 @@ from monai.transforms import RandGibbsNoise from monai.utils.misc import set_determinism from monai.utils.module import optional_import -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose _, has_torch_fft = optional_import("torch.fft", name="fftshift") diff --git a/tests/transforms/test_rand_gibbs_noised.py b/tests/transforms/test_rand_gibbs_noised.py index 382290dd39..c3bdafe1d5 100644 --- a/tests/transforms/test_rand_gibbs_noised.py +++ b/tests/transforms/test_rand_gibbs_noised.py @@ -21,7 +21,7 @@ from monai.transforms import RandGibbsNoised from monai.utils.misc import set_determinism from monai.utils.module import optional_import -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose _, has_torch_fft = optional_import("torch.fft", name="fftshift") diff --git a/tests/transforms/test_rand_grid_distortion.py b/tests/transforms/test_rand_grid_distortion.py index e07c311b25..00fbb6df2b 100644 --- a/tests/transforms/test_rand_grid_distortion.py +++ b/tests/transforms/test_rand_grid_distortion.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandGridDistortion -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_rand_grid_distortiond.py b/tests/transforms/test_rand_grid_distortiond.py index f28e0ae86e..d1f7877dcd 100644 --- a/tests/transforms/test_rand_grid_distortiond.py +++ b/tests/transforms/test_rand_grid_distortiond.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandGridDistortiond -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS = [] num_cells = 2 diff --git a/tests/transforms/test_rand_histogram_shift.py b/tests/transforms/test_rand_histogram_shift.py index 785e24e53b..b2d0c1db72 100644 --- a/tests/transforms/test_rand_histogram_shift.py +++ b/tests/transforms/test_rand_histogram_shift.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import RandHistogramShift -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_rand_k_space_spike_noise.py b/tests/transforms/test_rand_k_space_spike_noise.py index 7a9dd4288d..f1c59390ff 100644 --- a/tests/transforms/test_rand_k_space_spike_noise.py +++ b/tests/transforms/test_rand_k_space_spike_noise.py @@ -19,7 +19,7 @@ from monai.data.synthetic import create_test_image_2d, create_test_image_3d from monai.transforms import KSpaceSpikeNoise, RandKSpaceSpikeNoise from monai.utils.misc import set_determinism -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for shape in ((128, 64), (64, 48, 80)): diff --git a/tests/transforms/test_rand_k_space_spike_noised.py b/tests/transforms/test_rand_k_space_spike_noised.py index 86d4256637..2a3d5cf8f9 100644 --- a/tests/transforms/test_rand_k_space_spike_noised.py +++ b/tests/transforms/test_rand_k_space_spike_noised.py @@ -19,7 +19,7 @@ from monai.data.synthetic import create_test_image_2d, create_test_image_3d from monai.transforms import RandKSpaceSpikeNoised from monai.utils.misc import set_determinism -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for shape in ((128, 64), (64, 48, 80)): diff --git a/tests/transforms/test_rand_rician_noise.py b/tests/transforms/test_rand_rician_noise.py index 8dd1c48e29..5e6445028b 100644 --- a/tests/transforms/test_rand_rician_noise.py +++ b/tests/transforms/test_rand_rician_noise.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import RandRicianNoise -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_rand_rician_noised.py b/tests/transforms/test_rand_rician_noised.py index a190ba866d..07d464adde 100644 --- a/tests/transforms/test_rand_rician_noised.py +++ b/tests/transforms/test_rand_rician_noised.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import RandRicianNoised -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_rand_rotate.py b/tests/transforms/test_rand_rotate.py index c54229dcfe..4c5c041424 100644 --- a/tests/transforms/test_rand_rotate.py +++ b/tests/transforms/test_rand_rotate.py @@ -22,7 +22,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import RandRotate from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import ( +from tests.utils.utils import ( TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, diff --git a/tests/transforms/test_rand_rotate90.py b/tests/transforms/test_rand_rotate90.py index be2e658b78..5619145d8f 100644 --- a/tests/transforms/test_rand_rotate90.py +++ b/tests/transforms/test_rand_rotate90.py @@ -19,7 +19,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import RandRotate90 from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion class TestRandRotate90(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rand_rotate90d.py b/tests/transforms/test_rand_rotate90d.py index 02836b5dd8..c0a9d3f26b 100644 --- a/tests/transforms/test_rand_rotate90d.py +++ b/tests/transforms/test_rand_rotate90d.py @@ -19,7 +19,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import RandRotate90d from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion class TestRandRotate90d(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rand_rotated.py b/tests/transforms/test_rand_rotated.py index 71d0f67b63..8ee92aebf6 100644 --- a/tests/transforms/test_rand_rotated.py +++ b/tests/transforms/test_rand_rotated.py @@ -22,7 +22,7 @@ from monai.transforms import RandRotated from monai.utils import GridSampleMode, GridSamplePadMode from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, test_local_inversion TEST_CASES_2D: list[tuple] = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_rand_scale_crop.py b/tests/transforms/test_rand_scale_crop.py index bf43273fcf..68274c188b 100644 --- a/tests/transforms/test_rand_scale_crop.py +++ b/tests/transforms/test_rand_scale_crop.py @@ -18,7 +18,7 @@ from monai.transforms import RandScaleCrop from tests.croppers import CropTest -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TEST_SHAPES = [ [{"roi_scale": [1.0, 1.0, -1.0], "random_center": True}, (3, 3, 3, 4), (3, 3, 3, 4)], diff --git a/tests/transforms/test_rand_scale_cropd.py b/tests/transforms/test_rand_scale_cropd.py index 15a48a55d7..6eb23f2787 100644 --- a/tests/transforms/test_rand_scale_cropd.py +++ b/tests/transforms/test_rand_scale_cropd.py @@ -18,7 +18,7 @@ from monai.transforms import RandScaleCropd from tests.croppers import CropTest -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TEST_SHAPES = [ [{"keys": "img", "roi_scale": [1.0, 1.0, -1.0], "random_center": True}, (3, 3, 3, 4), (3, 3, 3, 4)], diff --git a/tests/transforms/test_rand_scale_intensity.py b/tests/transforms/test_rand_scale_intensity.py index 7e999c00b3..5a70e5b72b 100644 --- a/tests/transforms/test_rand_scale_intensity.py +++ b/tests/transforms/test_rand_scale_intensity.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandScaleIntensity -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestRandScaleIntensity(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rand_scale_intensity_fixed_mean.py b/tests/transforms/test_rand_scale_intensity_fixed_mean.py index 9324c711fa..0428e3eb77 100644 --- a/tests/transforms/test_rand_scale_intensity_fixed_mean.py +++ b/tests/transforms/test_rand_scale_intensity_fixed_mean.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandScaleIntensityFixedMean -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestRandScaleIntensity(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rand_scale_intensity_fixed_meand.py b/tests/transforms/test_rand_scale_intensity_fixed_meand.py index 8c127ac130..9ada2f5943 100644 --- a/tests/transforms/test_rand_scale_intensity_fixed_meand.py +++ b/tests/transforms/test_rand_scale_intensity_fixed_meand.py @@ -16,7 +16,7 @@ import numpy as np from monai.transforms import RandScaleIntensityFixedMeand -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestRandScaleIntensityFixedMeand(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rand_scale_intensityd.py b/tests/transforms/test_rand_scale_intensityd.py index 32c96f0313..c1e21847e0 100644 --- a/tests/transforms/test_rand_scale_intensityd.py +++ b/tests/transforms/test_rand_scale_intensityd.py @@ -16,7 +16,7 @@ import numpy as np from monai.transforms import RandScaleIntensityd -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestRandScaleIntensityd(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rand_shift_intensity.py b/tests/transforms/test_rand_shift_intensity.py index 907773ccf5..8b9c803cb8 100644 --- a/tests/transforms/test_rand_shift_intensity.py +++ b/tests/transforms/test_rand_shift_intensity.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandShiftIntensity -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestRandShiftIntensity(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rand_shift_intensityd.py b/tests/transforms/test_rand_shift_intensityd.py index 51675e324c..abd4e6a4cb 100644 --- a/tests/transforms/test_rand_shift_intensityd.py +++ b/tests/transforms/test_rand_shift_intensityd.py @@ -17,7 +17,7 @@ from monai.transforms import IntensityStatsd, RandShiftIntensityd from monai.utils.enums import PostFix -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestRandShiftIntensityd(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rand_simulate_low_resolution.py b/tests/transforms/test_rand_simulate_low_resolution.py index 6aa586fb0b..6c704587ed 100644 --- a/tests/transforms/test_rand_simulate_low_resolution.py +++ b/tests/transforms/test_rand_simulate_low_resolution.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandSimulateLowResolution -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_rand_simulate_low_resolutiond.py b/tests/transforms/test_rand_simulate_low_resolutiond.py index 5ec84eba1d..747a9a3e56 100644 --- a/tests/transforms/test_rand_simulate_low_resolutiond.py +++ b/tests/transforms/test_rand_simulate_low_resolutiond.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RandSimulateLowResolutiond -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_rand_spatial_crop.py b/tests/transforms/test_rand_spatial_crop.py index df121e2220..ba244c0fc7 100644 --- a/tests/transforms/test_rand_spatial_crop.py +++ b/tests/transforms/test_rand_spatial_crop.py @@ -20,7 +20,7 @@ from monai.transforms import RandScaleCrop, RandSpatialCrop from monai.transforms.lazy.functional import apply_pending from tests.croppers import CropTest -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TEST_SHAPES = [ [{"roi_size": [3, 3, -1], "random_center": True}, (3, 3, 3, 4), (3, 3, 3, 4)], diff --git a/tests/transforms/test_rand_spatial_crop_samples.py b/tests/transforms/test_rand_spatial_crop_samples.py index 92f0f9d9be..31bc481cce 100644 --- a/tests/transforms/test_rand_spatial_crop_samples.py +++ b/tests/transforms/test_rand_spatial_crop_samples.py @@ -20,7 +20,7 @@ from monai.transforms import RandSpatialCropSamples from monai.transforms.lazy.functional import apply_pending from tests.croppers import CropTest -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TEST_CASE_1 = [ {"roi_size": [3, 3, 3], "num_samples": 4, "random_center": True, "random_size": False}, diff --git a/tests/transforms/test_rand_spatial_crop_samplesd.py b/tests/transforms/test_rand_spatial_crop_samplesd.py index cb53e94b7d..7cf7b61bbf 100644 --- a/tests/transforms/test_rand_spatial_crop_samplesd.py +++ b/tests/transforms/test_rand_spatial_crop_samplesd.py @@ -19,7 +19,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import Compose, DivisiblePadd, RandSpatialCropSamplesd from monai.transforms.lazy.functional import apply_pending -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TEST_CASE_1 = [ {"keys": ["img", "seg"], "num_samples": 4, "roi_size": [2, 2, 2], "random_center": True, "random_size": True}, diff --git a/tests/transforms/test_rand_spatial_cropd.py b/tests/transforms/test_rand_spatial_cropd.py index 123459235f..57eaf7b218 100644 --- a/tests/transforms/test_rand_spatial_cropd.py +++ b/tests/transforms/test_rand_spatial_cropd.py @@ -20,7 +20,7 @@ from monai.transforms import RandScaleCropd, RandSpatialCropd from monai.transforms.lazy.functional import apply_pending from tests.croppers import CropTest -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TEST_SHAPES = [ [{"keys": "img", "roi_size": [3, 3, -1], "random_center": True}, (3, 3, 3, 5), (3, 3, 3, 5)], diff --git a/tests/transforms/test_rand_std_shift_intensity.py b/tests/transforms/test_rand_std_shift_intensity.py index 0ac5e9482e..7a17a949bb 100644 --- a/tests/transforms/test_rand_std_shift_intensity.py +++ b/tests/transforms/test_rand_std_shift_intensity.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import RandStdShiftIntensity -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestRandStdShiftIntensity(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rand_std_shift_intensityd.py b/tests/transforms/test_rand_std_shift_intensityd.py index 1fd0c5d2a8..c59c77a551 100644 --- a/tests/transforms/test_rand_std_shift_intensityd.py +++ b/tests/transforms/test_rand_std_shift_intensityd.py @@ -16,7 +16,7 @@ import numpy as np from monai.transforms import RandStdShiftIntensityd -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestRandStdShiftIntensityd(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rand_zoom.py b/tests/transforms/test_rand_zoom.py index 2da04fd652..cfebfc135e 100644 --- a/tests/transforms/test_rand_zoom.py +++ b/tests/transforms/test_rand_zoom.py @@ -22,7 +22,7 @@ from monai.transforms import RandZoom from monai.utils import InterpolateMode from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion VALID_CASES = [ (0.8, 1.2, "nearest", False), diff --git a/tests/transforms/test_rand_zoomd.py b/tests/transforms/test_rand_zoomd.py index bcbf188310..22a5c75246 100644 --- a/tests/transforms/test_rand_zoomd.py +++ b/tests/transforms/test_rand_zoomd.py @@ -21,7 +21,7 @@ from monai.config import USE_COMPILED from monai.transforms import RandZoomd from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion VALID_CASES = [ (0.8, 1.2, "nearest", None, False), diff --git a/tests/transforms/test_randidentity.py b/tests/transforms/test_randidentity.py index 3a8936f2d2..cf7d76c645 100644 --- a/tests/transforms/test_randidentity.py +++ b/tests/transforms/test_randidentity.py @@ -15,7 +15,7 @@ import monai.transforms as mt from monai.data import CacheDataset -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class T(mt.Transform): diff --git a/tests/transforms/test_randtorchvisiond.py b/tests/transforms/test_randtorchvisiond.py index 7ad06dfd2a..3090c386a6 100644 --- a/tests/transforms/test_randtorchvisiond.py +++ b/tests/transforms/test_randtorchvisiond.py @@ -18,7 +18,7 @@ from monai.transforms import RandomizableTrait, RandTorchVisiond from monai.utils import set_determinism -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_1 = [ {"keys": "img", "name": "ColorJitter"}, diff --git a/tests/transforms/test_regularization.py b/tests/transforms/test_regularization.py index 12d64637d5..023dcd6c9c 100644 --- a/tests/transforms/test_regularization.py +++ b/tests/transforms/test_regularization.py @@ -17,7 +17,7 @@ import torch from monai.transforms import CutMix, CutMixd, CutOut, CutOutd, MixUp, MixUpd -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class TestMixup(unittest.TestCase): diff --git a/tests/transforms/test_remove_repeated_channel.py b/tests/transforms/test_remove_repeated_channel.py index 7da00ee75d..819e99368d 100644 --- a/tests/transforms/test_remove_repeated_channel.py +++ b/tests/transforms/test_remove_repeated_channel.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import RemoveRepeatedChannel -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TEST_CASES = [] for q in TEST_NDARRAYS: diff --git a/tests/transforms/test_remove_repeated_channeld.py b/tests/transforms/test_remove_repeated_channeld.py index 08ec7fb44c..031f5c25ed 100644 --- a/tests/transforms/test_remove_repeated_channeld.py +++ b/tests/transforms/test_remove_repeated_channeld.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RemoveRepeatedChanneld -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_repeat_channel.py b/tests/transforms/test_repeat_channel.py index 82d1d92bd2..ff07fbcacc 100644 --- a/tests/transforms/test_repeat_channel.py +++ b/tests/transforms/test_repeat_channel.py @@ -16,7 +16,7 @@ from parameterized import parameterized from monai.transforms import RepeatChannel -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_repeat_channeld.py b/tests/transforms/test_repeat_channeld.py index 2be13a08d1..301dec7838 100644 --- a/tests/transforms/test_repeat_channeld.py +++ b/tests/transforms/test_repeat_channeld.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import RepeatChanneld -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_resample_backends.py b/tests/transforms/test_resample_backends.py index 7ddd9c7ec2..2e9d990a23 100644 --- a/tests/transforms/test_resample_backends.py +++ b/tests/transforms/test_resample_backends.py @@ -22,7 +22,7 @@ from monai.transforms import Resample from monai.transforms.utils import create_grid from monai.utils import GridSampleMode, GridSamplePadMode, NdimageMode, SplineMode, convert_to_numpy -from tests.utils import SkipIfBeforePyTorchVersion, assert_allclose, is_tf32_env +from tests.utils.utils import SkipIfBeforePyTorchVersion, assert_allclose, is_tf32_env _rtol = 1e-3 if is_tf32_env() else 1e-4 diff --git a/tests/transforms/test_resample_to_match.py b/tests/transforms/test_resample_to_match.py index f0d34547a7..6272d2513c 100644 --- a/tests/transforms/test_resample_to_match.py +++ b/tests/transforms/test_resample_to_match.py @@ -30,7 +30,7 @@ from monai.transforms import Compose, EnsureChannelFirstd, LoadImaged, ResampleToMatch, SaveImage, SaveImaged from monai.utils import optional_import from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import assert_allclose, download_url_or_skip_test, testing_data_config +from tests.utils.utils import assert_allclose, download_url_or_skip_test, testing_data_config _, has_itk = optional_import("itk", allow_namespace_pkg=True) diff --git a/tests/transforms/test_resample_to_matchd.py b/tests/transforms/test_resample_to_matchd.py index 9d104bf392..8cf1b3e685 100644 --- a/tests/transforms/test_resample_to_matchd.py +++ b/tests/transforms/test_resample_to_matchd.py @@ -27,7 +27,7 @@ SaveImaged, ) from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import assert_allclose, download_url_or_skip_test, testing_data_config +from tests.utils.utils import assert_allclose, download_url_or_skip_test, testing_data_config def update_fname(d): diff --git a/tests/transforms/test_resampler.py b/tests/transforms/test_resampler.py index af0db657aa..e52e370609 100644 --- a/tests/transforms/test_resampler.py +++ b/tests/transforms/test_resampler.py @@ -19,7 +19,7 @@ from monai.transforms import Resample from monai.transforms.utils import create_grid -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_resize.py b/tests/transforms/test_resize.py index d4c57e2742..f8e1f87498 100644 --- a/tests/transforms/test_resize.py +++ b/tests/transforms/test_resize.py @@ -21,7 +21,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import Resize from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import ( +from tests.utils.utils import ( TEST_NDARRAYS_ALL, NumpyImageTestCase2D, SkipIfAtLeastPyTorchVersion, diff --git a/tests/transforms/test_resize_with_pad_or_crop.py b/tests/transforms/test_resize_with_pad_or_crop.py index daf257f89f..15e58f5079 100644 --- a/tests/transforms/test_resize_with_pad_or_crop.py +++ b/tests/transforms/test_resize_with_pad_or_crop.py @@ -20,7 +20,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import ResizeWithPadOrCrop from monai.transforms.lazy.functional import apply_pending -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose, pytorch_after +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose, pytorch_after TEST_CASES = [ [{"spatial_size": [15, 8, 8], "mode": "constant"}, (3, 8, 8, 4), (3, 15, 8, 8), True], diff --git a/tests/transforms/test_resize_with_pad_or_cropd.py b/tests/transforms/test_resize_with_pad_or_cropd.py index 89c8e7a1fa..8900e5917b 100644 --- a/tests/transforms/test_resize_with_pad_or_cropd.py +++ b/tests/transforms/test_resize_with_pad_or_cropd.py @@ -22,7 +22,7 @@ from monai.transforms import ResizeWithPadOrCropd from monai.transforms.lazy.functional import apply_pending from tests.transforms.test_resize_with_pad_or_crop import TESTS_PENDING_MODE -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose, pytorch_after +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose, pytorch_after TEST_CASES = [ [{"keys": "img", "spatial_size": [15, 8, 8], "mode": "constant"}, {"img": np.zeros((3, 8, 8, 4))}, (3, 15, 8, 8)], diff --git a/tests/transforms/test_resized.py b/tests/transforms/test_resized.py index 243a4e6622..c21126c933 100644 --- a/tests/transforms/test_resized.py +++ b/tests/transforms/test_resized.py @@ -21,7 +21,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import Invertd, Resize, Resized from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import ( +from tests.utils.utils import ( TEST_NDARRAYS_ALL, NumpyImageTestCase2D, SkipIfAtLeastPyTorchVersion, diff --git a/tests/transforms/test_rotate.py b/tests/transforms/test_rotate.py index 19fbd1409f..f9a12a9115 100644 --- a/tests/transforms/test_rotate.py +++ b/tests/transforms/test_rotate.py @@ -22,7 +22,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import Rotate from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import HAS_CUPY, TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, test_local_inversion +from tests.utils.utils import HAS_CUPY, TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, test_local_inversion TEST_CASES_2D: list[tuple] = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_rotate90.py b/tests/transforms/test_rotate90.py index ebc3fba7e0..14a014dd2c 100644 --- a/tests/transforms/test_rotate90.py +++ b/tests/transforms/test_rotate90.py @@ -21,7 +21,7 @@ from monai.transforms.lazy.functional import apply_pending from monai.utils import optional_import from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import ( +from tests.utils.utils import ( TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, diff --git a/tests/transforms/test_rotate90d.py b/tests/transforms/test_rotate90d.py index ffe920992a..f668b07b20 100644 --- a/tests/transforms/test_rotate90d.py +++ b/tests/transforms/test_rotate90d.py @@ -18,7 +18,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import Rotate90d from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion class TestRotate90d(NumpyImageTestCase2D): diff --git a/tests/transforms/test_rotated.py b/tests/transforms/test_rotated.py index 28ca755661..003dd45195 100644 --- a/tests/transforms/test_rotated.py +++ b/tests/transforms/test_rotated.py @@ -22,7 +22,7 @@ from monai.data import MetaTensor from monai.transforms import Rotated from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, NumpyImageTestCase3D, test_local_inversion TEST_CASES_2D: list[tuple] = [] for p in TEST_NDARRAYS_ALL: diff --git a/tests/transforms/test_savitzky_golay_smooth.py b/tests/transforms/test_savitzky_golay_smooth.py index 14e403e238..ae2d87e1d1 100644 --- a/tests/transforms/test_savitzky_golay_smooth.py +++ b/tests/transforms/test_savitzky_golay_smooth.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import SavitzkyGolaySmooth -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose # Zero-padding trivial tests diff --git a/tests/transforms/test_savitzky_golay_smoothd.py b/tests/transforms/test_savitzky_golay_smoothd.py index 3bb4056046..555c56140c 100644 --- a/tests/transforms/test_savitzky_golay_smoothd.py +++ b/tests/transforms/test_savitzky_golay_smoothd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import SavitzkyGolaySmoothd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose # Zero-padding trivial tests diff --git a/tests/transforms/test_scale_intensity.py b/tests/transforms/test_scale_intensity.py index 17dfe305b2..7c00838fc2 100644 --- a/tests/transforms/test_scale_intensity.py +++ b/tests/transforms/test_scale_intensity.py @@ -18,7 +18,7 @@ from monai.transforms import ScaleIntensity from monai.transforms.utils import rescale_array -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestScaleIntensity(NumpyImageTestCase2D): diff --git a/tests/transforms/test_scale_intensity_fixed_mean.py b/tests/transforms/test_scale_intensity_fixed_mean.py index 35d38ef0b1..d2a92c6c5f 100644 --- a/tests/transforms/test_scale_intensity_fixed_mean.py +++ b/tests/transforms/test_scale_intensity_fixed_mean.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import ScaleIntensityFixedMean -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestScaleIntensityFixedMean(NumpyImageTestCase2D): diff --git a/tests/transforms/test_scale_intensity_range.py b/tests/transforms/test_scale_intensity_range.py index 6013a237db..e95587e39c 100644 --- a/tests/transforms/test_scale_intensity_range.py +++ b/tests/transforms/test_scale_intensity_range.py @@ -16,7 +16,7 @@ import numpy as np from monai.transforms import ScaleIntensityRange -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class IntensityScaleIntensityRange(NumpyImageTestCase2D): diff --git a/tests/transforms/test_scale_intensity_ranged.py b/tests/transforms/test_scale_intensity_ranged.py index cc3f1220e7..614268f591 100644 --- a/tests/transforms/test_scale_intensity_ranged.py +++ b/tests/transforms/test_scale_intensity_ranged.py @@ -14,7 +14,7 @@ import unittest from monai.transforms import ScaleIntensityRanged -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class IntensityScaleIntensityRanged(NumpyImageTestCase2D): diff --git a/tests/transforms/test_scale_intensityd.py b/tests/transforms/test_scale_intensityd.py index 88beece894..dd4cf73ecb 100644 --- a/tests/transforms/test_scale_intensityd.py +++ b/tests/transforms/test_scale_intensityd.py @@ -16,7 +16,7 @@ import numpy as np from monai.transforms import ScaleIntensityd -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestScaleIntensityd(NumpyImageTestCase2D): diff --git a/tests/transforms/test_shift_intensity.py b/tests/transforms/test_shift_intensity.py index 90aa0f9271..a6950f1def 100644 --- a/tests/transforms/test_shift_intensity.py +++ b/tests/transforms/test_shift_intensity.py @@ -16,7 +16,7 @@ import numpy as np from monai.transforms import ShiftIntensity -from tests.utils import NumpyImageTestCase2D +from tests.utils.utils import NumpyImageTestCase2D class TestShiftIntensity(NumpyImageTestCase2D): diff --git a/tests/transforms/test_shift_intensityd.py b/tests/transforms/test_shift_intensityd.py index 22336b4415..d0e957a80b 100644 --- a/tests/transforms/test_shift_intensityd.py +++ b/tests/transforms/test_shift_intensityd.py @@ -17,7 +17,7 @@ from monai.transforms import IntensityStatsd, ShiftIntensityd from monai.utils.enums import PostFix -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestShiftIntensityd(NumpyImageTestCase2D): diff --git a/tests/transforms/test_signal_fillempty.py b/tests/transforms/test_signal_fillempty.py index d972a8019c..97648dca14 100644 --- a/tests/transforms/test_signal_fillempty.py +++ b/tests/transforms/test_signal_fillempty.py @@ -20,7 +20,7 @@ from monai.transforms import SignalFillEmpty from monai.utils.type_conversion import convert_to_tensor -from tests.utils import SkipIfBeforePyTorchVersion +from tests.utils.utils import SkipIfBeforePyTorchVersion TESTS_PATH = Path(__file__).parents[1] TEST_SIGNAL = os.path.join(TESTS_PATH, "testing_data", "signal.npy") diff --git a/tests/transforms/test_signal_fillemptyd.py b/tests/transforms/test_signal_fillemptyd.py index f5a520a26e..6994338f5c 100644 --- a/tests/transforms/test_signal_fillemptyd.py +++ b/tests/transforms/test_signal_fillemptyd.py @@ -20,7 +20,7 @@ from monai.transforms import SignalFillEmptyd from monai.utils.type_conversion import convert_to_tensor -from tests.utils import SkipIfBeforePyTorchVersion +from tests.utils.utils import SkipIfBeforePyTorchVersion TESTS_PATH = Path(__file__).parents[1] TEST_SIGNAL = os.path.join(TESTS_PATH, "testing_data", "signal.npy") diff --git a/tests/transforms/test_signal_rand_add_squarepulse.py b/tests/transforms/test_signal_rand_add_squarepulse.py index 90a16235df..bf103d1663 100644 --- a/tests/transforms/test_signal_rand_add_squarepulse.py +++ b/tests/transforms/test_signal_rand_add_squarepulse.py @@ -22,7 +22,7 @@ from monai.transforms import SignalRandAddSquarePulse from monai.utils import optional_import from monai.utils.type_conversion import convert_to_tensor -from tests.utils import SkipIfBeforePyTorchVersion +from tests.utils.utils import SkipIfBeforePyTorchVersion _, has_scipy = optional_import("scipy") TESTS_PATH = Path(__file__).parents[1] diff --git a/tests/transforms/test_signal_rand_add_squarepulse_partial.py b/tests/transforms/test_signal_rand_add_squarepulse_partial.py index 9783e9e456..6c1b631ee5 100644 --- a/tests/transforms/test_signal_rand_add_squarepulse_partial.py +++ b/tests/transforms/test_signal_rand_add_squarepulse_partial.py @@ -22,7 +22,7 @@ from monai.transforms import SignalRandAddSquarePulsePartial from monai.utils import optional_import from monai.utils.type_conversion import convert_to_tensor -from tests.utils import SkipIfBeforePyTorchVersion +from tests.utils.utils import SkipIfBeforePyTorchVersion _, has_scipy = optional_import("scipy") TESTS_PATH = Path(__file__).parents[1] diff --git a/tests/transforms/test_smooth_field.py b/tests/transforms/test_smooth_field.py index ca010641c4..4e44ce1fb7 100644 --- a/tests/transforms/test_smooth_field.py +++ b/tests/transforms/test_smooth_field.py @@ -20,7 +20,7 @@ from monai.networks.utils import meshgrid_xy from monai.transforms import RandSmoothDeformd, RandSmoothFieldAdjustContrastd, RandSmoothFieldAdjustIntensityd -from tests.utils import TEST_NDARRAYS, assert_allclose, is_tf32_env +from tests.utils.utils import TEST_NDARRAYS, assert_allclose, is_tf32_env _rtol = 5e-3 if is_tf32_env() else 1e-4 diff --git a/tests/transforms/test_sobel_gradient.py b/tests/transforms/test_sobel_gradient.py index a0d7cf5a8b..2c795e7e18 100644 --- a/tests/transforms/test_sobel_gradient.py +++ b/tests/transforms/test_sobel_gradient.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import SobelGradients -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose IMAGE = torch.zeros(1, 16, 16, dtype=torch.float32) IMAGE[0, 8, :] = 1 diff --git a/tests/transforms/test_sobel_gradientd.py b/tests/transforms/test_sobel_gradientd.py index 03524823a5..521aa25a91 100644 --- a/tests/transforms/test_sobel_gradientd.py +++ b/tests/transforms/test_sobel_gradientd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import SobelGradientsd -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose IMAGE = torch.zeros(1, 16, 16, dtype=torch.float32) IMAGE[0, 8, :] = 1 diff --git a/tests/transforms/test_spacing.py b/tests/transforms/test_spacing.py index c9a6291c78..ec73d9fa5f 100644 --- a/tests/transforms/test_spacing.py +++ b/tests/transforms/test_spacing.py @@ -24,7 +24,7 @@ from monai.transforms import Spacing from monai.utils import fall_back_tuple from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_DEVICES, TEST_NDARRAYS_ALL, assert_allclose, skip_if_quick +from tests.utils.utils import TEST_DEVICES, TEST_NDARRAYS_ALL, assert_allclose, skip_if_quick TESTS: list[list] = [] for device in TEST_DEVICES: diff --git a/tests/transforms/test_spacingd.py b/tests/transforms/test_spacingd.py index 1cecaabced..a7c0d0b08b 100644 --- a/tests/transforms/test_spacingd.py +++ b/tests/transforms/test_spacingd.py @@ -23,7 +23,7 @@ from monai.transforms import Spacingd from monai.utils import ensure_tuple_rep from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_DEVICES, assert_allclose, skip_if_quick +from tests.utils.utils import TEST_DEVICES, assert_allclose, skip_if_quick TESTS: list[tuple] = [] for device in TEST_DEVICES: diff --git a/tests/transforms/test_spatial_resample.py b/tests/transforms/test_spatial_resample.py index e64b242128..5c4791ff41 100644 --- a/tests/transforms/test_spatial_resample.py +++ b/tests/transforms/test_spatial_resample.py @@ -24,7 +24,7 @@ from monai.transforms import SpatialResample from monai.utils import optional_import from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_DEVICES, TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_DEVICES, TEST_NDARRAYS_ALL, assert_allclose TESTS = [] diff --git a/tests/transforms/test_squeezedim.py b/tests/transforms/test_squeezedim.py index a295d20ef5..120b68d4b7 100644 --- a/tests/transforms/test_squeezedim.py +++ b/tests/transforms/test_squeezedim.py @@ -18,7 +18,7 @@ from monai.data import MetaTensor from monai.transforms import SqueezeDim -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS, TESTS_FAIL = [], [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_squeezedimd.py b/tests/transforms/test_squeezedimd.py index 934479563d..494bbe4828 100644 --- a/tests/transforms/test_squeezedimd.py +++ b/tests/transforms/test_squeezedimd.py @@ -18,7 +18,7 @@ from monai.data import MetaTensor from monai.transforms import SqueezeDimd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS, TESTS_FAIL = [], [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_std_shift_intensity.py b/tests/transforms/test_std_shift_intensity.py index b4dc1db568..ef09e44619 100644 --- a/tests/transforms/test_std_shift_intensity.py +++ b/tests/transforms/test_std_shift_intensity.py @@ -17,7 +17,7 @@ from monai.transforms import ShiftIntensity, StdShiftIntensity from monai.utils import dtype_numpy_to_torch -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestStdShiftIntensity(NumpyImageTestCase2D): diff --git a/tests/transforms/test_std_shift_intensityd.py b/tests/transforms/test_std_shift_intensityd.py index 73617ef4a3..42e002e071 100644 --- a/tests/transforms/test_std_shift_intensityd.py +++ b/tests/transforms/test_std_shift_intensityd.py @@ -17,7 +17,7 @@ from monai.transforms import ShiftIntensityd, StdShiftIntensityd from monai.utils import dtype_numpy_to_torch -from tests.utils import NumpyImageTestCase2D +from tests.utils.utils import NumpyImageTestCase2D class TestStdShiftIntensityd(NumpyImageTestCase2D): diff --git a/tests/transforms/test_threshold_intensity.py b/tests/transforms/test_threshold_intensity.py index 97c80eebcd..d09adb9c3c 100644 --- a/tests/transforms/test_threshold_intensity.py +++ b/tests/transforms/test_threshold_intensity.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import ThresholdIntensity -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_threshold_intensityd.py b/tests/transforms/test_threshold_intensityd.py index 867ebfe952..0e778bd9bc 100644 --- a/tests/transforms/test_threshold_intensityd.py +++ b/tests/transforms/test_threshold_intensityd.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import ThresholdIntensityd -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_to_contiguous.py b/tests/transforms/test_to_contiguous.py index 73a9ca27f6..15814515ef 100644 --- a/tests/transforms/test_to_contiguous.py +++ b/tests/transforms/test_to_contiguous.py @@ -17,7 +17,7 @@ import torch from monai.transforms import convert_to_contiguous -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose class TestToContiguous(unittest.TestCase): diff --git a/tests/transforms/test_to_cupy.py b/tests/transforms/test_to_cupy.py index 38400f0d3f..1959573a13 100644 --- a/tests/transforms/test_to_cupy.py +++ b/tests/transforms/test_to_cupy.py @@ -19,7 +19,7 @@ from monai.transforms import ToCupy from monai.utils import optional_import -from tests.utils import HAS_CUPY, skip_if_no_cuda +from tests.utils.utils import HAS_CUPY, skip_if_no_cuda cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_to_cupyd.py b/tests/transforms/test_to_cupyd.py index a07ab671e1..855de1bdb8 100644 --- a/tests/transforms/test_to_cupyd.py +++ b/tests/transforms/test_to_cupyd.py @@ -19,7 +19,7 @@ from monai.transforms import ToCupyd from monai.utils import optional_import -from tests.utils import HAS_CUPY, skip_if_no_cuda +from tests.utils.utils import HAS_CUPY, skip_if_no_cuda cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_to_device.py b/tests/transforms/test_to_device.py index 6a13ffca99..80340adbfc 100644 --- a/tests/transforms/test_to_device.py +++ b/tests/transforms/test_to_device.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import ToDevice -from tests.utils import assert_allclose, skip_if_no_cuda +from tests.utils.utils import assert_allclose, skip_if_no_cuda TEST_CASE_1 = ["cuda:0"] diff --git a/tests/transforms/test_to_deviced.py b/tests/transforms/test_to_deviced.py index 19c2d0761f..6ca3e788a7 100644 --- a/tests/transforms/test_to_deviced.py +++ b/tests/transforms/test_to_deviced.py @@ -17,7 +17,7 @@ from monai.data import CacheDataset, ThreadDataLoader from monai.transforms import ToDeviced -from tests.utils import assert_allclose, skip_if_no_cuda +from tests.utils.utils import assert_allclose, skip_if_no_cuda @skip_if_no_cuda diff --git a/tests/transforms/test_to_numpy.py b/tests/transforms/test_to_numpy.py index f4e5f80a29..d751cf98ca 100644 --- a/tests/transforms/test_to_numpy.py +++ b/tests/transforms/test_to_numpy.py @@ -19,7 +19,7 @@ from monai.transforms import ToNumpy from monai.utils import optional_import -from tests.utils import HAS_CUPY, assert_allclose, skip_if_no_cuda +from tests.utils.utils import HAS_CUPY, assert_allclose, skip_if_no_cuda cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_to_numpyd.py b/tests/transforms/test_to_numpyd.py index ae9b4c84b3..243f41dcec 100644 --- a/tests/transforms/test_to_numpyd.py +++ b/tests/transforms/test_to_numpyd.py @@ -19,7 +19,7 @@ from monai.transforms import ToNumpyd from monai.utils import optional_import -from tests.utils import HAS_CUPY, assert_allclose, skip_if_no_cuda +from tests.utils.utils import HAS_CUPY, assert_allclose, skip_if_no_cuda cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_to_pil.py b/tests/transforms/test_to_pil.py index 352e10bcc1..53696f9b1c 100644 --- a/tests/transforms/test_to_pil.py +++ b/tests/transforms/test_to_pil.py @@ -20,7 +20,7 @@ from monai.transforms import ToPIL from monai.utils import optional_import -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose if TYPE_CHECKING: from PIL.Image import Image as PILImageImage diff --git a/tests/transforms/test_to_pild.py b/tests/transforms/test_to_pild.py index 1a0232e134..9cf5528780 100644 --- a/tests/transforms/test_to_pild.py +++ b/tests/transforms/test_to_pild.py @@ -20,7 +20,7 @@ from monai.transforms import ToPILd from monai.utils import optional_import -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose if TYPE_CHECKING: from PIL.Image import Image as PILImageImage diff --git a/tests/transforms/test_to_tensor.py b/tests/transforms/test_to_tensor.py index 50df80128b..b64097e53c 100644 --- a/tests/transforms/test_to_tensor.py +++ b/tests/transforms/test_to_tensor.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import ToTensor -from tests.utils import HAS_CUPY, TEST_NDARRAYS, assert_allclose, optional_import +from tests.utils.utils import HAS_CUPY, TEST_NDARRAYS, assert_allclose, optional_import cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_to_tensord.py b/tests/transforms/test_to_tensord.py index 1eab7b9485..3408970cc4 100644 --- a/tests/transforms/test_to_tensord.py +++ b/tests/transforms/test_to_tensord.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import ToTensord -from tests.utils import HAS_CUPY, TEST_NDARRAYS, assert_allclose, optional_import +from tests.utils.utils import HAS_CUPY, TEST_NDARRAYS, assert_allclose, optional_import cp, _ = optional_import("cupy") diff --git a/tests/transforms/test_torchvision.py b/tests/transforms/test_torchvision.py index 2931b0c1a8..1aa8297a68 100644 --- a/tests/transforms/test_torchvision.py +++ b/tests/transforms/test_torchvision.py @@ -17,7 +17,7 @@ from monai.transforms import TorchVision from monai.utils import set_determinism -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_torchvisiond.py b/tests/transforms/test_torchvisiond.py index ec09692df9..70b5164002 100644 --- a/tests/transforms/test_torchvisiond.py +++ b/tests/transforms/test_torchvisiond.py @@ -18,7 +18,7 @@ from monai.transforms import TorchVisiond from monai.utils import set_determinism -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TEST_CASE_1 = [ {"keys": "img", "name": "ColorJitter"}, diff --git a/tests/transforms/test_transpose.py b/tests/transforms/test_transpose.py index 2f5ccd1235..6ef56e0e8e 100644 --- a/tests/transforms/test_transpose.py +++ b/tests/transforms/test_transpose.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms import Transpose -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_transposed.py b/tests/transforms/test_transposed.py index e7c6ecbe8a..655b1c8ec3 100644 --- a/tests/transforms/test_transposed.py +++ b/tests/transforms/test_transposed.py @@ -19,7 +19,7 @@ from parameterized import parameterized from monai.transforms import Transposed -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_ultrasound_confidence_map_transform.py b/tests/transforms/test_ultrasound_confidence_map_transform.py index 05f53ede50..9adf7793f5 100644 --- a/tests/transforms/test_ultrasound_confidence_map_transform.py +++ b/tests/transforms/test_ultrasound_confidence_map_transform.py @@ -22,7 +22,7 @@ from monai.transforms import UltrasoundConfidenceMapTransform from monai.utils import optional_import -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose _, has_scipy = optional_import("scipy") diff --git a/tests/transforms/test_utils_pytorch_numpy_unification.py b/tests/transforms/test_utils_pytorch_numpy_unification.py index 90c0401e46..b4e7c8d4c0 100644 --- a/tests/transforms/test_utils_pytorch_numpy_unification.py +++ b/tests/transforms/test_utils_pytorch_numpy_unification.py @@ -19,7 +19,7 @@ from monai.transforms.utils_pytorch_numpy_unification import max, min, mode, percentile from monai.utils import set_determinism -from tests.utils import TEST_NDARRAYS, assert_allclose, skip_if_quick +from tests.utils.utils import TEST_NDARRAYS, assert_allclose, skip_if_quick TEST_MODE = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_vote_ensemble.py b/tests/transforms/test_vote_ensemble.py index 4abdd0b050..a61a99cb20 100644 --- a/tests/transforms/test_vote_ensemble.py +++ b/tests/transforms/test_vote_ensemble.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import VoteEnsemble -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_vote_ensembled.py b/tests/transforms/test_vote_ensembled.py index 957133d7fc..d20f5818e2 100644 --- a/tests/transforms/test_vote_ensembled.py +++ b/tests/transforms/test_vote_ensembled.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms import VoteEnsembled -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/test_zoom.py b/tests/transforms/test_zoom.py index 2db2df4486..ed8bea4b92 100644 --- a/tests/transforms/test_zoom.py +++ b/tests/transforms/test_zoom.py @@ -21,7 +21,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import Zoom from monai.transforms.lazy.functional import apply_pending -from tests.utils import ( +from tests.utils.utils import ( DEFAULT_TEST_AFFINE, TEST_NDARRAYS_ALL, NumpyImageTestCase2D, diff --git a/tests/transforms/test_zoomd.py b/tests/transforms/test_zoomd.py index ad91f398ff..810a869e90 100644 --- a/tests/transforms/test_zoomd.py +++ b/tests/transforms/test_zoomd.py @@ -21,7 +21,7 @@ from monai.config import USE_COMPILED from monai.transforms import Zoomd from tests.lazy_transforms_utils import test_resampler_lazy -from tests.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion +from tests.utils.utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion VALID_CASES = [ (1.5, "nearest", False), diff --git a/tests/transforms/utility/test_identity.py b/tests/transforms/utility/test_identity.py index 4243a7f19a..d3fd0df3d6 100644 --- a/tests/transforms/utility/test_identity.py +++ b/tests/transforms/utility/test_identity.py @@ -14,7 +14,7 @@ import unittest from monai.transforms.utility.array import Identity -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestIdentity(NumpyImageTestCase2D): diff --git a/tests/transforms/utility/test_identityd.py b/tests/transforms/utility/test_identityd.py index 6b81ad9f16..7c9579924e 100644 --- a/tests/transforms/utility/test_identityd.py +++ b/tests/transforms/utility/test_identityd.py @@ -14,7 +14,7 @@ import unittest from monai.transforms.utility.dictionary import Identityd -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestIdentityd(NumpyImageTestCase2D): diff --git a/tests/transforms/utility/test_lambda.py b/tests/transforms/utility/test_lambda.py index e0a5cf84db..5348bab62f 100644 --- a/tests/transforms/utility/test_lambda.py +++ b/tests/transforms/utility/test_lambda.py @@ -19,7 +19,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms.utility.array import Lambda from monai.utils.type_conversion import convert_to_numpy, convert_to_tensor -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestLambda(NumpyImageTestCase2D): diff --git a/tests/transforms/utility/test_lambdad.py b/tests/transforms/utility/test_lambdad.py index fad5ebeee4..7da99b85dd 100644 --- a/tests/transforms/utility/test_lambdad.py +++ b/tests/transforms/utility/test_lambdad.py @@ -19,7 +19,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms.utility.dictionary import Lambdad from monai.utils.type_conversion import convert_to_numpy, convert_to_tensor -from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose class TestLambdad(NumpyImageTestCase2D): diff --git a/tests/transforms/utility/test_rand_lambda.py b/tests/transforms/utility/test_rand_lambda.py index 98a324aec5..e43794fc15 100644 --- a/tests/transforms/utility/test_rand_lambda.py +++ b/tests/transforms/utility/test_rand_lambda.py @@ -20,7 +20,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms.transform import Randomizable from monai.transforms.utility.array import RandLambda -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose class RandTest(Randomizable): diff --git a/tests/transforms/utility/test_rand_lambdad.py b/tests/transforms/utility/test_rand_lambdad.py index 5247d79843..3d014b2c76 100644 --- a/tests/transforms/utility/test_rand_lambdad.py +++ b/tests/transforms/utility/test_rand_lambdad.py @@ -20,7 +20,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms.transform import Randomizable from monai.transforms.utility.dictionary import RandLambdad -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose class RandTest(Randomizable): diff --git a/tests/transforms/utility/test_simulatedelay.py b/tests/transforms/utility/test_simulatedelay.py index 0a4f23450a..b3cbc3e567 100644 --- a/tests/transforms/utility/test_simulatedelay.py +++ b/tests/transforms/utility/test_simulatedelay.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms.utility.array import SimulateDelay -from tests.utils import NumpyImageTestCase2D +from tests.utils.utils import NumpyImageTestCase2D class TestSimulateDelay(NumpyImageTestCase2D): diff --git a/tests/transforms/utility/test_simulatedelayd.py b/tests/transforms/utility/test_simulatedelayd.py index 419e21f24d..42e8b3f7d0 100644 --- a/tests/transforms/utility/test_simulatedelayd.py +++ b/tests/transforms/utility/test_simulatedelayd.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms.utility.dictionary import SimulateDelayd -from tests.utils import NumpyImageTestCase2D +from tests.utils.utils import NumpyImageTestCase2D class TestSimulateDelay(NumpyImageTestCase2D): diff --git a/tests/transforms/utility/test_splitdim.py b/tests/transforms/utility/test_splitdim.py index f557f44142..6886672e55 100644 --- a/tests/transforms/utility/test_splitdim.py +++ b/tests/transforms/utility/test_splitdim.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms.utility.array import SplitDim -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/utility/test_splitdimd.py b/tests/transforms/utility/test_splitdimd.py index b01913269d..040ce2907a 100644 --- a/tests/transforms/utility/test_splitdimd.py +++ b/tests/transforms/utility/test_splitdimd.py @@ -21,7 +21,7 @@ from monai.data.meta_tensor import MetaTensor from monai.transforms import LoadImaged from monai.transforms.utility.dictionary import SplitDimd -from tests.utils import TEST_NDARRAYS, assert_allclose, make_nifti_image, make_rand_affine +from tests.utils.utils import TEST_NDARRAYS, assert_allclose, make_nifti_image, make_rand_affine TESTS = [] for p in TEST_NDARRAYS: diff --git a/tests/transforms/utils/test_correct_crop_centers.py b/tests/transforms/utils/test_correct_crop_centers.py index 82b0b93b53..4381338ed7 100644 --- a/tests/transforms/utils/test_correct_crop_centers.py +++ b/tests/transforms/utils/test_correct_crop_centers.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.transforms.utils import correct_crop_centers -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TESTS = [[[1, 5, 0], [2, 2, 2], [10, 10, 10]], [[4, 4, 4], [2, 2, 1], [10, 10, 10]]] diff --git a/tests/transforms/utils/test_get_unique_labels.py b/tests/transforms/utils/test_get_unique_labels.py index 0a88145489..9c2c518bcd 100644 --- a/tests/transforms/utils/test_get_unique_labels.py +++ b/tests/transforms/utils/test_get_unique_labels.py @@ -19,7 +19,7 @@ from monai.transforms.utils import get_unique_labels from monai.transforms.utils_pytorch_numpy_unification import moveaxis -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS grid_raw = [[0, 0, 0], [0, 0, 1], [2, 2, 3], [5, 5, 6], [3, 6, 2], [5, 6, 6]] grid = torch.Tensor(grid_raw).unsqueeze(0).to(torch.int64) diff --git a/tests/utils/enums/test_wsireader.py b/tests/utils/enums/test_wsireader.py index 9ce86f527c..a137c5a58a 100644 --- a/tests/utils/enums/test_wsireader.py +++ b/tests/utils/enums/test_wsireader.py @@ -27,7 +27,7 @@ from monai.transforms import Compose, LoadImaged, ToTensord from monai.utils import first, optional_import from monai.utils.enums import PostFix, WSIPatchKeys -from tests.utils import assert_allclose, download_url_or_skip_test, skip_if_no_cuda, testing_data_config +from tests.utils.utils import assert_allclose, download_url_or_skip_test, skip_if_no_cuda, testing_data_config cucim, has_cucim = optional_import("cucim") has_cucim = has_cucim and hasattr(cucim, "CuImage") diff --git a/tests/utils/misc/test_ensure_tuple.py b/tests/utils/misc/test_ensure_tuple.py index ec8c92785a..ef8f634da9 100644 --- a/tests/utils/misc/test_ensure_tuple.py +++ b/tests/utils/misc/test_ensure_tuple.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.utils.misc import ensure_tuple -from tests.utils import assert_allclose +from tests.utils.utils import assert_allclose TESTS = [ ["test", ("test",)], diff --git a/tests/utils/test_enum_bound_interp.py b/tests/utils/test_enum_bound_interp.py index cd3119f91c..75a2bce101 100644 --- a/tests/utils/test_enum_bound_interp.py +++ b/tests/utils/test_enum_bound_interp.py @@ -14,7 +14,7 @@ import unittest from monai.utils import optional_import -from tests.utils import skip_if_no_cpp_extension +from tests.utils.utils import skip_if_no_cpp_extension b, _ = optional_import("monai._C", name="BoundType") p, _ = optional_import("monai._C", name="InterpolationType") diff --git a/tests/utils/test_evenly_divisible_all_gather_dist.py b/tests/utils/test_evenly_divisible_all_gather_dist.py index f1d45ba48f..2d0f1de56f 100644 --- a/tests/utils/test_evenly_divisible_all_gather_dist.py +++ b/tests/utils/test_evenly_divisible_all_gather_dist.py @@ -17,7 +17,7 @@ import torch.distributed as dist from monai.utils import evenly_divisible_all_gather -from tests.utils import DistCall, DistTestCase, assert_allclose +from tests.utils.utils import DistCall, DistTestCase, assert_allclose class DistributedEvenlyDivisibleAllGather(DistTestCase): diff --git a/tests/utils/test_handler_logfile.py b/tests/utils/test_handler_logfile.py index 457aca2ebc..d1ae99cd36 100644 --- a/tests/utils/test_handler_logfile.py +++ b/tests/utils/test_handler_logfile.py @@ -18,7 +18,7 @@ import torch from monai.utils import optional_import -from tests.utils import SkipIfNoModule +from tests.utils.utils import SkipIfNoModule try: _, has_ignite = optional_import("ignite") diff --git a/tests/utils/test_handler_metric_logger.py b/tests/utils/test_handler_metric_logger.py index 06d50e97ff..3e5ec463f4 100644 --- a/tests/utils/test_handler_metric_logger.py +++ b/tests/utils/test_handler_metric_logger.py @@ -16,7 +16,7 @@ import torch from monai.utils import optional_import -from tests.utils import SkipIfNoModule +from tests.utils.utils import SkipIfNoModule try: _, has_ignite = optional_import("ignite") diff --git a/tests/utils/test_pad_mode.py b/tests/utils/test_pad_mode.py index 54ee2c6d75..012d13ccd0 100644 --- a/tests/utils/test_pad_mode.py +++ b/tests/utils/test_pad_mode.py @@ -18,7 +18,7 @@ from monai.transforms import CastToType, Pad from monai.utils import NumpyPadMode, PytorchPadMode -from tests.utils import SkipIfBeforePyTorchVersion +from tests.utils.utils import SkipIfBeforePyTorchVersion @SkipIfBeforePyTorchVersion((1, 10, 1)) diff --git a/tests/utils/test_profiling.py b/tests/utils/test_profiling.py index 649d980ebf..4fe3752bd1 100644 --- a/tests/utils/test_profiling.py +++ b/tests/utils/test_profiling.py @@ -23,7 +23,7 @@ from monai.utils import first, optional_import from monai.utils.enums import CommonKeys from monai.utils.profiling import ProfileHandler, ProfileResult, WorkflowProfiler -from tests.utils import SkipIfNoModule +from tests.utils.utils import SkipIfNoModule pd, _ = optional_import("pandas") diff --git a/tests/utils/test_rankfilter_dist.py b/tests/utils/test_rankfilter_dist.py index fd02e3bdc9..3aa48e3982 100644 --- a/tests/utils/test_rankfilter_dist.py +++ b/tests/utils/test_rankfilter_dist.py @@ -19,7 +19,7 @@ import torch.distributed as dist from monai.utils import RankFilter -from tests.utils import DistCall, DistTestCase +from tests.utils.utils import DistCall, DistTestCase class DistributedRankFilterTest(DistTestCase): diff --git a/tests/utils/test_sample_slices.py b/tests/utils/test_sample_slices.py index a183689970..c2b9c860cf 100644 --- a/tests/utils/test_sample_slices.py +++ b/tests/utils/test_sample_slices.py @@ -17,7 +17,7 @@ from parameterized import parameterized from monai.utils import sample_slices -from tests.utils import TEST_NDARRAYS, assert_allclose +from tests.utils.utils import TEST_NDARRAYS, assert_allclose # test data[:, [1, ], ...] TEST_CASE_1 = [torch.tensor([[[0, 2], [1, 0]]]), 1, True, (1,), torch.tensor([[[1, 0]]])] diff --git a/tests/utils/test_set_determinism.py b/tests/utils/test_set_determinism.py index 7d64aed244..dec03eba63 100644 --- a/tests/utils/test_set_determinism.py +++ b/tests/utils/test_set_determinism.py @@ -17,7 +17,7 @@ import torch from monai.utils import get_seed, set_determinism -from tests.utils import SkipIfBeforePyTorchVersion, skip_if_no_cuda +from tests.utils.utils import SkipIfBeforePyTorchVersion, skip_if_no_cuda class TestSetDeterminism(unittest.TestCase): diff --git a/tests/utils/type_conversion/test_convert_data_type.py b/tests/utils/type_conversion/test_convert_data_type.py index a27a05cf28..cb51e356b3 100644 --- a/tests/utils/type_conversion/test_convert_data_type.py +++ b/tests/utils/type_conversion/test_convert_data_type.py @@ -19,7 +19,7 @@ from monai.data import MetaTensor from monai.utils.type_conversion import convert_data_type, convert_to_dst_type, get_equivalent_dtype -from tests.utils import TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import TEST_NDARRAYS_ALL, assert_allclose TESTS: list[tuple] = [] for in_type in TEST_NDARRAYS_ALL + (int, float): diff --git a/tests/utils/type_conversion/test_get_equivalent_dtype.py b/tests/utils/type_conversion/test_get_equivalent_dtype.py index 2b4de1bc2a..3f6cc57412 100644 --- a/tests/utils/type_conversion/test_get_equivalent_dtype.py +++ b/tests/utils/type_conversion/test_get_equivalent_dtype.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.utils.type_conversion import get_equivalent_dtype, get_numpy_dtype_from_string, get_torch_dtype_from_string -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS DTYPES = [torch.float32, np.float32, np.dtype(np.float32)] diff --git a/tests/utils/type_conversion/test_safe_dtype_range.py b/tests/utils/type_conversion/test_safe_dtype_range.py index 61b55635ae..20bed45698 100644 --- a/tests/utils/type_conversion/test_safe_dtype_range.py +++ b/tests/utils/type_conversion/test_safe_dtype_range.py @@ -19,7 +19,7 @@ from monai.utils import optional_import from monai.utils.type_conversion import get_equivalent_dtype, safe_dtype_range -from tests.utils import HAS_CUPY, TEST_NDARRAYS_ALL, assert_allclose +from tests.utils.utils import HAS_CUPY, TEST_NDARRAYS_ALL, assert_allclose cp, _ = optional_import("cupy") diff --git a/tests/utils/utils.py b/tests/utils/utils.py new file mode 100644 index 0000000000..2a00af50e9 --- /dev/null +++ b/tests/utils/utils.py @@ -0,0 +1,867 @@ +# Copyright (c) MONAI Consortium +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import annotations + +import argparse +import copy +import datetime +import functools +import importlib +import json +import operator +import os +import queue +import ssl +import subprocess +import sys +import tempfile +import time +import traceback +import unittest +import warnings +from contextlib import contextmanager +from functools import partial, reduce +from subprocess import PIPE, Popen +from typing import Callable +from urllib.error import ContentTooShortError, HTTPError + +import numpy as np +import torch +import torch.distributed as dist + +from monai.apps.utils import download_url +from monai.config import NdarrayTensor +from monai.config.deviceconfig import USE_COMPILED +from monai.config.type_definitions import NdarrayOrTensor +from monai.data import create_test_image_2d, create_test_image_3d +from monai.data.meta_tensor import MetaTensor, get_track_meta +from monai.networks import convert_to_onnx, convert_to_torchscript +from monai.utils import optional_import +from monai.utils.misc import MONAIEnvVars +from monai.utils.module import compute_capabilities_after, pytorch_after +from monai.utils.tf32 import detect_default_tf32 +from monai.utils.type_conversion import convert_data_type + +nib, _ = optional_import("nibabel") +http_error, has_req = optional_import("requests", name="HTTPError") + +quick_test_var = "QUICKTEST" +_tf32_enabled = None +_test_data_config: dict = {} + + +def testing_data_config(*keys): + """get _test_data_config[keys0][keys1]...[keysN]""" + if not _test_data_config: + with open(os.path.join(os.path.dirname(__file__), "testing_data", "data_config.json")) as c: + _config = json.load(c) + for k, v in _config.items(): + _test_data_config[k] = v + return reduce(operator.getitem, keys, _test_data_config) + + +def get_testing_algo_template_path(): + """ + a local folder to the testing algorithm template or a url to the compressed template file. + Default to None, which effectively uses bundle_gen's ``default_algo_zip`` path. + + https://github.com/Project-MONAI/MONAI/blob/1.1.0/monai/apps/auto3dseg/bundle_gen.py#L380-L381 + """ + return MONAIEnvVars.testing_algo_template() + + +def clone(data: NdarrayTensor) -> NdarrayTensor: + """ + Clone data independent of type. + + Args: + data (NdarrayTensor): This can be a Pytorch Tensor or numpy array. + + Returns: + Any: Cloned data object + """ + return copy.deepcopy(data) + + +def assert_allclose( + actual: NdarrayOrTensor, + desired: NdarrayOrTensor, + type_test: bool | str = True, + device_test: bool = False, + *args, + **kwargs, +): + """ + Assert that types and all values of two data objects are close. + + Args: + actual: Pytorch Tensor or numpy array for comparison. + desired: Pytorch Tensor or numpy array to compare against. + type_test: whether to test that `actual` and `desired` are both numpy arrays or torch tensors. + if type_test == "tensor", it checks whether the `actual` is a torch.tensor or metatensor according to + `get_track_meta`. + device_test: whether to test the device property. + args: extra arguments to pass on to `np.testing.assert_allclose`. + kwargs: extra arguments to pass on to `np.testing.assert_allclose`. + + + """ + if isinstance(type_test, str) and type_test == "tensor": + if get_track_meta(): + np.testing.assert_equal(isinstance(actual, MetaTensor), True, "must be a MetaTensor") + else: + np.testing.assert_equal( + isinstance(actual, torch.Tensor) and not isinstance(actual, MetaTensor), True, "must be a torch.Tensor" + ) + elif type_test: + # check both actual and desired are of the same type + np.testing.assert_equal(isinstance(actual, np.ndarray), isinstance(desired, np.ndarray), "numpy type") + np.testing.assert_equal(isinstance(actual, torch.Tensor), isinstance(desired, torch.Tensor), "torch type") + + if isinstance(desired, torch.Tensor) or isinstance(actual, torch.Tensor): + if device_test: + np.testing.assert_equal(str(actual.device), str(desired.device), "torch device check") # type: ignore + actual = actual.detach().cpu().numpy() if isinstance(actual, torch.Tensor) else actual + desired = desired.detach().cpu().numpy() if isinstance(desired, torch.Tensor) else desired + np.testing.assert_allclose(actual, desired, *args, **kwargs) + + +@contextmanager +def skip_if_downloading_fails(): + try: + yield + except (ContentTooShortError, HTTPError, ConnectionError) + (http_error,) if has_req else () as e: # noqa: B030 + raise unittest.SkipTest(f"error while downloading: {e}") from e + except ssl.SSLError as ssl_e: + if "decryption failed" in str(ssl_e): + raise unittest.SkipTest(f"SSL error while downloading: {ssl_e}") from ssl_e + except (RuntimeError, OSError) as rt_e: + err_str = str(rt_e) + if any( + k in err_str + for k in ( + "unexpected EOF", # incomplete download + "network issue", + "gdown dependency", # gdown not installed + "md5 check", + "limit", # HTTP Error 503: Egress is over the account limit + "authenticate", + "timed out", # urlopen error [Errno 110] Connection timed out + "HTTPError", # HTTPError: 429 Client Error: Too Many Requests for huggingface hub + ) + ): + raise unittest.SkipTest(f"error while downloading: {rt_e}") from rt_e # incomplete download + + raise rt_e + + +def test_pretrained_networks(network, input_param, device): + with skip_if_downloading_fails(): + return network(**input_param).to(device) + + +def test_is_quick(): + return os.environ.get(quick_test_var, "").lower() == "true" + + +def is_tf32_env(): + """ + When we may be using TF32 mode, check the precision of matrix operation. + If the checking result is greater than the threshold 0.001, + set _tf32_enabled=True (and relax _rtol for tests). + """ + global _tf32_enabled + if _tf32_enabled is None: + _tf32_enabled = False + if torch.cuda.is_available() and (detect_default_tf32() or torch.backends.cuda.matmul.allow_tf32): + try: + # with TF32 enabled, the speed is ~8x faster, but the precision has ~2 digits less in the result + g_gpu = torch.Generator(device="cuda") + g_gpu.manual_seed(2147483647) + a_full = torch.randn(1024, 1024, dtype=torch.double, device="cuda", generator=g_gpu) + b_full = torch.randn(1024, 1024, dtype=torch.double, device="cuda", generator=g_gpu) + _tf32_enabled = (a_full.float() @ b_full.float() - a_full @ b_full).abs().max().item() > 0.001 # 0.1713 + except BaseException: + pass + print(f"tf32 enabled: {_tf32_enabled}") + return _tf32_enabled + + +def skip_if_quick(obj): + """ + Skip the unit tests if environment variable `quick_test_var=true`. + For example, the user can skip the relevant tests by setting ``export QUICKTEST=true``. + """ + is_quick = test_is_quick() + + return unittest.skipIf(is_quick, "Skipping slow tests")(obj) + + +class SkipIfNoModule: + """Decorator to be used if test should be skipped + when optional module is not present.""" + + def __init__(self, module_name): + self.module_name = module_name + self.module_missing = not optional_import(self.module_name)[1] + + def __call__(self, obj): + return unittest.skipIf(self.module_missing, f"optional module not present: {self.module_name}")(obj) + + +class SkipIfModule: + """Decorator to be used if test should be skipped + when optional module is present.""" + + def __init__(self, module_name): + self.module_name = module_name + self.module_avail = optional_import(self.module_name)[1] + + def __call__(self, obj): + return unittest.skipIf(self.module_avail, f"Skipping because optional module present: {self.module_name}")(obj) + + +def skip_if_no_cpp_extension(obj): + """ + Skip the unit tests if the cpp extension is not available. + """ + return unittest.skipUnless(USE_COMPILED, "Skipping cpp extension tests")(obj) + + +def skip_if_no_cuda(obj): + """ + Skip the unit tests if torch.cuda.is_available is False. + """ + return unittest.skipUnless(torch.cuda.is_available(), "Skipping CUDA-based tests")(obj) + + +def skip_if_windows(obj): + """ + Skip the unit tests if platform is win32. + """ + return unittest.skipIf(sys.platform == "win32", "Skipping tests on Windows")(obj) + + +def skip_if_darwin(obj): + """ + Skip the unit tests if platform is macOS (Darwin). + """ + return unittest.skipIf(sys.platform == "darwin", "Skipping tests on macOS/Darwin")(obj) + + +class SkipIfBeforePyTorchVersion: + """Decorator to be used if test should be skipped + with PyTorch versions older than that given.""" + + def __init__(self, pytorch_version_tuple): + self.min_version = pytorch_version_tuple + self.version_too_old = not pytorch_after(*pytorch_version_tuple) + + def __call__(self, obj): + return unittest.skipIf( + self.version_too_old, f"Skipping tests that fail on PyTorch versions before: {self.min_version}" + )(obj) + + +class SkipIfAtLeastPyTorchVersion: + """Decorator to be used if test should be skipped + with PyTorch versions newer than or equal to that given.""" + + def __init__(self, pytorch_version_tuple): + self.max_version = pytorch_version_tuple + self.version_too_new = pytorch_after(*pytorch_version_tuple) + + def __call__(self, obj): + return unittest.skipIf( + self.version_too_new, f"Skipping tests that fail on PyTorch versions at least: {self.max_version}" + )(obj) + + +class SkipIfBeforeComputeCapabilityVersion: + """Decorator to be used if test should be skipped + with Compute Capability older than that given.""" + + def __init__(self, compute_capability_tuple): + self.min_version = compute_capability_tuple + self.version_too_old = not compute_capabilities_after(*compute_capability_tuple) + + def __call__(self, obj): + return unittest.skipIf( + self.version_too_old, f"Skipping tests that fail on Compute Capability versions before: {self.min_version}" + )(obj) + + +def is_main_test_process(): + ps = torch.multiprocessing.current_process() + if not ps or not hasattr(ps, "name"): + return False + return ps.name.startswith("Main") + + +def has_cupy(): + """ + Returns True if the user has installed a version of cupy. + """ + cp, has_cp = optional_import("cupy") + if not is_main_test_process(): + return has_cp # skip the check if we are running in subprocess + if not has_cp: + return False + try: # test cupy installation with a basic example + x = cp.arange(6, dtype="f").reshape(2, 3) + y = cp.arange(3, dtype="f") + kernel = cp.ElementwiseKernel( + "float32 x, float32 y", "float32 z", """ if (x - 2 > y) { z = x * y; } else { z = x + y; } """, "my_kernel" + ) + flag = kernel(x, y)[0, 0] == 0 + del x, y, kernel + cp.get_default_memory_pool().free_all_blocks() + return flag + except Exception: + return False + + +HAS_CUPY = has_cupy() + + +def make_nifti_image( + array: NdarrayOrTensor, affine=None, dir=None, fname=None, suffix=".nii.gz", verbose=False, dtype=float +): + """ + Create a temporary nifti image on the disk and return the image name. + User is responsible for deleting the temporary file when done with it. + """ + if isinstance(array, torch.Tensor): + array, *_ = convert_data_type(array, np.ndarray) + if isinstance(affine, torch.Tensor): + affine, *_ = convert_data_type(affine, np.ndarray) + if affine is None: + affine = np.eye(4) + test_image = nib.Nifti1Image(array.astype(dtype), affine) # type: ignore + + # if dir not given, create random. Else, make sure it exists. + if dir is None: + dir = tempfile.mkdtemp() + else: + os.makedirs(dir, exist_ok=True) + + # If fname not given, get random one. Else, concat dir, fname and suffix. + if fname is None: + temp_f, fname = tempfile.mkstemp(suffix=suffix, dir=dir) + os.close(temp_f) + else: + fname = os.path.join(dir, fname + suffix) + + nib.save(test_image, fname) + if verbose: + print(f"File written: {fname}.") + return fname + + +def make_rand_affine(ndim: int = 3, random_state: np.random.RandomState | None = None): + """Create random affine transformation (with values == -1, 0 or 1).""" + rs = np.random.random.__self__ if random_state is None else random_state # type: ignore + + vals = rs.choice([-1, 1], size=ndim) + positions = rs.choice(range(ndim), size=ndim, replace=False) + af = np.zeros([ndim + 1, ndim + 1]) + af[ndim, ndim] = 1 + for i, (v, p) in enumerate(zip(vals, positions)): + af[i, p] = v + return af + + +def get_arange_img(size, dtype=np.float32, offset=0): + """ + Returns an image as a numpy array (complete with channel as dim 0) + with contents that iterate like an arange. + """ + n_elem = np.prod(size) + img = np.arange(offset, offset + n_elem, dtype=dtype).reshape(size) + return np.expand_dims(img, 0) + + +class DistTestCase(unittest.TestCase): + """ + testcase without _outcome, so that it's picklable. + """ + + def __getstate__(self): + self_dict = self.__dict__.copy() + del self_dict["_outcome"] + return self_dict + + def __setstate__(self, data_dict): + self.__dict__.update(data_dict) + + +class DistCall: + """ + Wrap a test case so that it will run in multiple processes on a single machine using `torch.distributed`. + It is designed to be used with `tests.utils.DistTestCase`. + + Usage: + + decorate a unittest testcase method with a `DistCall` instance:: + + class MyTests(unittest.TestCase): + @DistCall(nnodes=1, nproc_per_node=3, master_addr="localhost") + def test_compute(self): + ... + + the `test_compute` method should trigger different worker logic according to `dist.get_rank()`. + + Multi-node tests require a fixed master_addr:master_port, with node_rank set manually in multiple scripts + or from environment variable "NODE_RANK". + """ + + def __init__( + self, + nnodes: int = 1, + nproc_per_node: int = 1, + master_addr: str = "localhost", + master_port: int | None = None, + node_rank: int | None = None, + timeout=60, + init_method=None, + backend: str | None = None, + daemon: bool | None = None, + method: str | None = "spawn", + verbose: bool = False, + ): + """ + + Args: + nnodes: The number of nodes to use for distributed call. + nproc_per_node: The number of processes to call on each node. + master_addr: Master node (rank 0)'s address, should be either the IP address or the hostname of node 0. + master_port: Master node (rank 0)'s free port. + node_rank: The rank of the node, this could be set via environment variable "NODE_RANK". + timeout: Timeout for operations executed against the process group. + init_method: URL specifying how to initialize the process group. + Default is "env://" or "file:///d:/a_temp" (windows) if unspecified. + If ``"no_init"``, the `dist.init_process_group` must be called within the code to be tested. + backend: The backend to use. Depending on build-time configurations, + valid values include ``mpi``, ``gloo``, and ``nccl``. + daemon: the process’s daemon flag. + When daemon=None, the initial value is inherited from the creating process. + method: set the method which should be used to start a child process. + method can be 'fork', 'spawn' or 'forkserver'. + verbose: whether to print NCCL debug info. + """ + self.nnodes = int(nnodes) + self.nproc_per_node = int(nproc_per_node) + if self.nnodes < 1 or self.nproc_per_node < 1: + raise ValueError( + f"number of nodes and processes per node must be >= 1, got {self.nnodes} and {self.nproc_per_node}" + ) + self.node_rank = int(os.environ.get("NODE_RANK", "0")) if node_rank is None else int(node_rank) + self.master_addr = master_addr + self.master_port = np.random.randint(10000, 20000) if master_port is None else master_port + + if backend is None: + self.backend = "nccl" if torch.distributed.is_nccl_available() and torch.cuda.is_available() else "gloo" + else: + self.backend = backend + self.init_method = init_method + if self.init_method is None and sys.platform == "win32": + self.init_method = "file:///d:/a_temp" + self.timeout = datetime.timedelta(0, timeout) + self.daemon = daemon + self.method = method + self.verbose = verbose + + def run_process(self, func, local_rank, args, kwargs, results): + _env = os.environ.copy() # keep the original system env + try: + os.environ["MASTER_ADDR"] = self.master_addr + os.environ["MASTER_PORT"] = str(self.master_port) + os.environ["LOCAL_RANK"] = str(local_rank) + if self.verbose: + os.environ["NCCL_DEBUG"] = "INFO" + os.environ["NCCL_DEBUG_SUBSYS"] = "ALL" + os.environ["TORCH_NCCL_BLOCKING_WAIT"] = str(1) + os.environ["OMP_NUM_THREADS"] = str(1) + os.environ["WORLD_SIZE"] = str(self.nproc_per_node * self.nnodes) + os.environ["RANK"] = str(self.nproc_per_node * self.node_rank + local_rank) + + if torch.cuda.is_available(): + torch.cuda.set_device(int(local_rank)) # using device ids from CUDA_VISIBILE_DEVICES + + if self.init_method != "no_init": + dist.init_process_group( + backend=self.backend, + init_method=self.init_method, + timeout=self.timeout, + world_size=int(os.environ["WORLD_SIZE"]), + rank=int(os.environ["RANK"]), + ) + func(*args, **kwargs) + # the primary node lives longer to + # avoid _store_based_barrier, RuntimeError: Broken pipe + # as the TCP store daemon is on the rank 0 + if int(os.environ["RANK"]) == 0: + time.sleep(0.1) + results.put(True) + except Exception as e: + results.put(False) + raise e + finally: + os.environ.clear() + os.environ.update(_env) + try: + dist.destroy_process_group() + except RuntimeError as e: + warnings.warn(f"While closing process group: {e}.") + + def __call__(self, obj): + if not torch.distributed.is_available(): + return unittest.skipIf(True, "Skipping distributed tests because not torch.distributed.is_available()")(obj) + if torch.cuda.is_available() and torch.cuda.device_count() < self.nproc_per_node: + return unittest.skipIf( + True, + f"Skipping distributed tests because it requires {self.nnodes} devices " + f"but got {torch.cuda.device_count()}", + )(obj) + + _cache_original_func(obj) + + @functools.wraps(obj) + def _wrapper(*args, **kwargs): + tmp = torch.multiprocessing.get_context(self.method) + processes = [] + results = tmp.Queue() + func = _call_original_func + args = [obj.__name__, obj.__module__] + list(args) + for proc_rank in range(self.nproc_per_node): + p = tmp.Process( + target=self.run_process, args=(func, proc_rank, args, kwargs, results), daemon=self.daemon + ) + p.start() + processes.append(p) + for p in processes: + p.join() + assert results.get(), "Distributed call failed." + _del_original_func(obj) + + return _wrapper + + +class TimedCall: + """ + Wrap a test case so that it will run in a new process, raises a TimeoutError if the decorated method takes + more than `seconds` to finish. It is designed to be used with `tests.utils.DistTestCase`. + """ + + def __init__( + self, + seconds: float = 60.0, + daemon: bool | None = None, + method: str | None = "spawn", + force_quit: bool = True, + skip_timing=False, + ): + """ + + Args: + seconds: timeout seconds. + daemon: the process’s daemon flag. + When daemon=None, the initial value is inherited from the creating process. + method: set the method which should be used to start a child process. + method can be 'fork', 'spawn' or 'forkserver'. + force_quit: whether to terminate the child process when `seconds` elapsed. + skip_timing: whether to skip the timing constraint. + this is useful to include some system conditions such as + `torch.cuda.is_available()`. + """ + self.timeout_seconds = seconds + self.daemon = daemon + self.force_quit = force_quit + self.skip_timing = skip_timing + self.method = method + + @staticmethod + def run_process(func, args, kwargs, results): + try: + output = func(*args, **kwargs) + results.put(output) + except Exception as e: + e.traceback = traceback.format_exc() + results.put(e) + + def __call__(self, obj): + if self.skip_timing: + return obj + + _cache_original_func(obj) + + @functools.wraps(obj) + def _wrapper(*args, **kwargs): + tmp = torch.multiprocessing.get_context(self.method) + func = _call_original_func + args = [obj.__name__, obj.__module__] + list(args) + results = tmp.Queue() + p = tmp.Process(target=TimedCall.run_process, args=(func, args, kwargs, results), daemon=self.daemon) + p.start() + + p.join(timeout=self.timeout_seconds) + + timeout_error = None + try: + if p.is_alive(): + # create an Exception + timeout_error = torch.multiprocessing.TimeoutError( + f"'{obj.__name__}' in '{obj.__module__}' did not finish in {self.timeout_seconds}s." + ) + if self.force_quit: + p.terminate() + else: + warnings.warn( + f"TimedCall: deadline ({self.timeout_seconds}s) " + f"reached but waiting for {obj.__name__} to finish." + ) + finally: + p.join() + + _del_original_func(obj) + res = None + try: + res = results.get(block=False) + except queue.Empty: # no result returned, took too long + pass + if isinstance(res, Exception): # other errors from obj + if hasattr(res, "traceback"): + raise RuntimeError(res.traceback) from res + raise res + if timeout_error: # no force_quit finished + raise timeout_error + return res + + return _wrapper + + +_original_funcs = {} + + +def _cache_original_func(obj) -> None: + """cache the original function by name, so that the decorator doesn't shadow it.""" + _original_funcs[obj.__name__] = obj + + +def _del_original_func(obj): + """pop the original function from cache.""" + _original_funcs.pop(obj.__name__, None) + if torch.cuda.is_available(): # clean up the cached function + torch.cuda.synchronize() + torch.cuda.empty_cache() + + +def _call_original_func(name, module, *args, **kwargs): + if name not in _original_funcs: + _original_module = importlib.import_module(module) # reimport, refresh _original_funcs + if not hasattr(_original_module, name): + # refresh module doesn't work + raise RuntimeError(f"Could not recover the original {name} from {module}: {_original_funcs}.") + f = _original_funcs[name] + return f(*args, **kwargs) + + +class NumpyImageTestCase2D(unittest.TestCase): + im_shape = (128, 64) + input_channels = 1 + output_channels = 4 + num_classes = 3 + + def setUp(self): + im, msk = create_test_image_2d( + self.im_shape[0], self.im_shape[1], num_objs=4, rad_max=20, noise_max=0.0, num_seg_classes=self.num_classes + ) + + self.imt = im[None, None] + self.seg1 = (msk[None, None] > 0).astype(np.float32) + self.segn = msk[None, None] + + +class TorchImageTestCase2D(NumpyImageTestCase2D): + + def setUp(self): + NumpyImageTestCase2D.setUp(self) + self.imt = torch.tensor(self.imt) + self.seg1 = torch.tensor(self.seg1) + self.segn = torch.tensor(self.segn) + + +class NumpyImageTestCase3D(unittest.TestCase): + im_shape = (64, 48, 80) + input_channels = 1 + output_channels = 4 + num_classes = 3 + + def setUp(self): + im, msk = create_test_image_3d( + self.im_shape[0], + self.im_shape[1], + self.im_shape[2], + num_objs=4, + rad_max=20, + noise_max=0.0, + num_seg_classes=self.num_classes, + ) + + self.imt = im[None, None] + self.seg1 = (msk[None, None] > 0).astype(np.float32) + self.segn = msk[None, None] + + +class TorchImageTestCase3D(NumpyImageTestCase3D): + + def setUp(self): + NumpyImageTestCase3D.setUp(self) + self.imt = torch.tensor(self.imt) + self.seg1 = torch.tensor(self.seg1) + self.segn = torch.tensor(self.segn) + + +def test_script_save(net, *inputs, device=None, rtol=1e-4, atol=0.0): + """ + Test the ability to save `net` as a Torchscript object, reload it, and apply inference. The value `inputs` is + forward-passed through the original and loaded copy of the network and their results returned. + The forward pass for both is done without gradient accumulation. + + The test will be performed with CUDA if available, else CPU. + """ + # TODO: would be nice to use GPU if available, but it currently causes CI failures. + device = "cpu" + with tempfile.TemporaryDirectory() as tempdir: + convert_to_torchscript( + model=net, + filename_or_obj=os.path.join(tempdir, "model.ts"), + verify=True, + inputs=inputs, + device=device, + rtol=rtol, + atol=atol, + ) + + +def test_onnx_save(net, *inputs, device=None, rtol=1e-4, atol=0.0): + """ + Test the ability to save `net` in ONNX format, reload it and validate with runtime. + The value `inputs` is forward-passed through the `net` without gradient accumulation + to do onnx export and PyTorch inference. + PyTorch model inference is performed with CUDA if available, else CPU. + Saved ONNX model is validated with onnxruntime, if available, else ONNX native implementation. + """ + # TODO: would be nice to use GPU if available, but it currently causes CI failures. + device = "cpu" + _, has_onnxruntime = optional_import("onnxruntime") + with tempfile.TemporaryDirectory() as tempdir: + convert_to_onnx( + model=net, + filename=os.path.join(tempdir, "model.onnx"), + verify=True, + inputs=inputs, + device=device, + use_ort=has_onnxruntime, + rtol=rtol, + atol=atol, + ) + + +def download_url_or_skip_test(*args, **kwargs): + """``download_url`` and skip the tests if any downloading error occurs.""" + with skip_if_downloading_fails(): + download_url(*args, **kwargs) + + +def query_memory(n=2): + """ + Find best n idle devices and return a string of device ids using the `nvidia-smi` command. + """ + bash_string = "nvidia-smi --query-gpu=power.draw,temperature.gpu,memory.used --format=csv,noheader,nounits" + + try: + print(f"query memory with n={n}") + p1 = Popen(bash_string.split(), stdout=PIPE) + output, error = p1.communicate() + free_memory = [x.split(",") for x in output.decode("utf-8").split("\n")[:-1]] + free_memory = np.asarray(free_memory, dtype=float).T + free_memory[1] += free_memory[0] # combine 0/1 column measures + ids = np.lexsort(free_memory)[:n] + except (TypeError, ValueError, IndexError, OSError): + ids = range(n) if isinstance(n, int) else [] + return ",".join(f"{int(x)}" for x in ids) + + +def test_local_inversion(invertible_xform, to_invert, im, dict_key=None): + """test that invertible_xform can bring to_invert back to im""" + im_item = im if dict_key is None else im[dict_key] + if not isinstance(im_item, MetaTensor): + return + im_ref = copy.deepcopy(im) + im_inv = invertible_xform.inverse(to_invert) + if dict_key: + im_inv = im_inv[dict_key] + im_ref = im_ref[dict_key] + np.testing.assert_array_equal(im_inv.applied_operations, []) + assert_allclose(im_inv.shape, im_ref.shape) + assert_allclose(im_inv.affine, im_ref.affine, atol=1e-3, rtol=1e-3) + + +def command_line_tests(cmd, copy_env=True): + test_env = os.environ.copy() if copy_env else os.environ + print(f"CUDA_VISIBLE_DEVICES in {__file__}", test_env.get("CUDA_VISIBLE_DEVICES")) + try: + normal_out = subprocess.run(cmd, env=test_env, check=True, capture_output=True) + print(repr(normal_out).replace("\\n", "\n").replace("\\t", "\t")) + return repr(normal_out) + except subprocess.CalledProcessError as e: + output = repr(e.stdout).replace("\\n", "\n").replace("\\t", "\t") + errors = repr(e.stderr).replace("\\n", "\n").replace("\\t", "\t") + raise RuntimeError(f"subprocess call error {e.returncode}: {errors}, {output}") from e + + +def equal_state_dict(st_1, st_2): + """ + assert equal state_dict (for the shared keys between st_1 and st_2). + """ + for key_st_1, val_st_1 in st_1.items(): + if key_st_1 in st_2: + val_st_2 = st_2.get(key_st_1) + assert_allclose(val_st_1, val_st_2) + + +TEST_TORCH_TENSORS: tuple = (torch.as_tensor,) +if torch.cuda.is_available(): + gpu_tensor: Callable = partial(torch.as_tensor, device="cuda") + TEST_TORCH_TENSORS = TEST_TORCH_TENSORS + (gpu_tensor,) + +DEFAULT_TEST_AFFINE = torch.tensor( + [[2.0, 0.0, 0.0, 0.0], [0.0, 2.0, 0.0, 0.0], [0.0, 0.0, 2.0, 0.0], [0.0, 0.0, 0.0, 1.0]] +) +_metatensor_creator = partial(MetaTensor, meta={"a": "b", "affine": DEFAULT_TEST_AFFINE}) +TEST_NDARRAYS_NO_META_TENSOR: tuple[Callable] = (np.array,) + TEST_TORCH_TENSORS +TEST_NDARRAYS: tuple[Callable] = TEST_NDARRAYS_NO_META_TENSOR + (_metatensor_creator,) # type: ignore +TEST_TORCH_AND_META_TENSORS: tuple[Callable] = TEST_TORCH_TENSORS + (_metatensor_creator,) +# alias for branch tests +TEST_NDARRAYS_ALL = TEST_NDARRAYS + +TEST_DEVICES = [[torch.device("cpu")]] +if torch.cuda.is_available(): + TEST_DEVICES.append([torch.device("cuda")]) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(prog="util") + parser.add_argument("-c", "--count", default=2, help="max number of gpus") + args = parser.parse_args() + print("\n", query_memory(int(args.count)), sep="\n") # print to stdout + sys.exit(0) diff --git a/tests/visualize/test_plot_2d_or_3d_image.py b/tests/visualize/test_plot_2d_or_3d_image.py index 16241853b3..bbf5f613c7 100644 --- a/tests/visualize/test_plot_2d_or_3d_image.py +++ b/tests/visualize/test_plot_2d_or_3d_image.py @@ -20,7 +20,7 @@ from monai.utils import optional_import from monai.visualize import plot_2d_or_3d_image -from tests.utils import SkipIfBeforePyTorchVersion, SkipIfNoModule +from tests.utils.utils import SkipIfBeforePyTorchVersion, SkipIfNoModule SummaryWriter, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") diff --git a/tests/visualize/test_vis_gradcam.py b/tests/visualize/test_vis_gradcam.py index f77d916a5b..e6acfc0b07 100644 --- a/tests/visualize/test_vis_gradcam.py +++ b/tests/visualize/test_vis_gradcam.py @@ -20,7 +20,7 @@ from monai.networks.nets import DenseNet, DenseNet121, SEResNet50 from monai.visualize import GradCAM, GradCAMpp -from tests.utils import assert_allclose, skip_if_quick +from tests.utils.utils import assert_allclose, skip_if_quick class DenseNetAdjoint(DenseNet121): diff --git a/tests/visualize/utils/test_blend_images.py b/tests/visualize/utils/test_blend_images.py index 700ae1fe58..dcd1a5714d 100644 --- a/tests/visualize/utils/test_blend_images.py +++ b/tests/visualize/utils/test_blend_images.py @@ -22,7 +22,7 @@ from monai.transforms.utils_pytorch_numpy_unification import moveaxis from monai.utils.module import optional_import from monai.visualize.utils import blend_images -from tests.utils import TEST_NDARRAYS +from tests.utils.utils import TEST_NDARRAYS plt, has_matplotlib = optional_import("matplotlib.pyplot") diff --git a/tests/visualize/utils/test_matshow3d.py b/tests/visualize/utils/test_matshow3d.py index 230234d6dd..aca7c5ffd7 100644 --- a/tests/visualize/utils/test_matshow3d.py +++ b/tests/visualize/utils/test_matshow3d.py @@ -28,7 +28,7 @@ ) from monai.utils import optional_import from monai.visualize.utils import matshow3d -from tests.utils import SkipIfNoModule +from tests.utils.utils import SkipIfNoModule compare_images, _ = optional_import("matplotlib.testing.compare", name="compare_images") pyplot, has_pyplot = optional_import("matplotlib", name="pyplot")