Skip to content

Commit

Permalink
Changing utils.py to test_utils.py (#8335)
Browse files Browse the repository at this point in the history
Related to #8185.

### Description

This changes the name of `tests/utils.py` to `tests/test_utils.py` to
conform to the changes introduced with the daily CICD tests. This is
done in #8231 but the change is being pre-merged now to get tests
working again while issues are sorted out there. This also includes
changes this PR made to that file, and changes anywhere else to
correctly import the module.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: Eric Kerfoot <[email protected]>
  • Loading branch information
ericspod authored Feb 11, 2025
1 parent 8dcb9dc commit aa5bd06
Show file tree
Hide file tree
Showing 529 changed files with 556 additions and 529 deletions.
2 changes: 1 addition & 1 deletion tests/croppers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import TEST_NDARRAYS_ALL, assert_allclose


class CropTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/hvd_evenly_divisible_all_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import assert_allclose

hvd, has_hvd = optional_import("horovod", name="torch")

Expand Down
2 changes: 1 addition & 1 deletion tests/lazy_transforms_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import assert_allclose

apply_transforms_kwargs = ("pending", "mode", "padding_mode", "dtype", "align_corners")

Expand Down
2 changes: 1 addition & 1 deletion tests/ngc_bundle_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import assert_allclose, skip_if_downloading_fails, skip_if_quick, skip_if_windows

TEST_CASE_NGC_1 = [
"spleen_ct_segmentation",
Expand Down
2 changes: 1 addition & 1 deletion tests/padders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import TEST_NDARRAYS_ALL, assert_allclose

MODES = []
# Test modes
Expand Down
2 changes: 1 addition & 1 deletion tests/test_activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import TEST_NDARRAYS, assert_allclose

TEST_CASES = []
for p in TEST_NDARRAYS:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_activationsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.transforms import Activationsd
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.test_utils import TEST_NDARRAYS, assert_allclose

TEST_CASES = []
for p in TEST_NDARRAYS:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_add_coordinate_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from parameterized import parameterized

from monai.transforms import AddCoordinateChannels
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.test_utils import TEST_NDARRAYS, assert_allclose

TESTS, TEST_CASES_ERROR_1, TEST_CASES_ERROR_2 = [], [], []
for p in TEST_NDARRAYS:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_add_coordinate_channelsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from parameterized import parameterized

from monai.transforms import AddCoordinateChannelsd
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.test_utils import TEST_NDARRAYS, assert_allclose

TESTS, TEST_CASES_ERROR_1, TEST_CASES_ERROR_2 = [], [], []
for p in TEST_NDARRAYS:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_add_extreme_points_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.transforms import AddExtremePointsChannel
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.test_utils import TEST_NDARRAYS, assert_allclose

IMG_CHANNEL = 3
TESTS = []
Expand Down
2 changes: 1 addition & 1 deletion tests/test_add_extreme_points_channeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.transforms import AddExtremePointsChanneld
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.test_utils import TEST_NDARRAYS, assert_allclose

IMG_CHANNEL = 3

Expand Down
2 changes: 1 addition & 1 deletion tests/test_adjust_contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.transforms import AdjustContrast
from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose
from tests.test_utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose

TESTS = []
for invert_image in (True, False):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_adjust_contrastd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.transforms import AdjustContrastd
from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose
from tests.test_utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose

TESTS = []
for invert_image in (True, False):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_adn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from parameterized import parameterized

from monai.networks.blocks import ADN
from tests.utils import TorchImageTestCase2D, TorchImageTestCase3D
from tests.test_utils import TorchImageTestCase2D, TorchImageTestCase3D

TEST_CASES_2D = [
[{"act": None}],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import TEST_NDARRAYS_ALL, assert_allclose, test_local_inversion

TESTS = []
for p in TEST_NDARRAYS_ALL:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_affine_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import TEST_NDARRAYS_ALL, assert_allclose, is_tf32_env

TESTS = []
for p in TEST_NDARRAYS_ALL:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_affine_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import is_tf32_env

_rtol = 1e-4 if not is_tf32_env() else 5e-3

Expand Down
2 changes: 1 addition & 1 deletion tests/test_affined.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import TEST_NDARRAYS_ALL, assert_allclose, test_local_inversion

TESTS = []
for p in TEST_NDARRAYS_ALL:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ahnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import skip_if_quick, test_pretrained_networks, test_script_save

device = "cuda" if torch.cuda.is_available() else "cpu"

Expand Down
2 changes: 1 addition & 1 deletion tests/test_anchor_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

_, has_torchvision = optional_import("torchvision")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import get_arange_img


def single_2d_transform_cases():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_as_channel_last.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.transforms import AsChannelLast
from tests.utils import TEST_NDARRAYS
from tests.test_utils import TEST_NDARRAYS

TESTS = []
for p in TEST_NDARRAYS:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_as_channel_lastd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.transforms import AsChannelLastd
from tests.utils import TEST_NDARRAYS
from tests.test_utils import TEST_NDARRAYS

TESTS = []
for p in TEST_NDARRAYS:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_as_discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from parameterized import parameterized

from monai.transforms import AsDiscrete
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.test_utils import TEST_NDARRAYS, assert_allclose

TEST_CASES = []
for p in TEST_NDARRAYS:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_as_discreted.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from parameterized import parameterized

from monai.transforms import AsDiscreted
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.test_utils import TEST_NDARRAYS, assert_allclose

TEST_CASES = []
for p in TEST_NDARRAYS:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_atss_box_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

TEST_CASES = [
[
Expand Down
2 changes: 1 addition & 1 deletion tests/test_attentionunet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import skip_if_no_cuda, skip_if_quick


def get_net_parameters(net: nn.Module) -> int:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auto3dseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
ToDeviced,
)
from monai.utils.enums import DataStatsKeys
from tests.utils import skip_if_no_cuda
from tests.test_utils import skip_if_no_cuda

device = "cpu"
n_workers = 2
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auto3dseg_bundlegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import (
SkipIfBeforePyTorchVersion,
get_testing_algo_template_path,
skip_if_downloading_fails,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auto3dseg_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import (
SkipIfBeforePyTorchVersion,
get_testing_algo_template_path,
skip_if_downloading_fails,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auto3dseg_hpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import (
SkipIfBeforePyTorchVersion,
get_testing_algo_template_path,
skip_if_downloading_fails,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import test_script_save

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_autoencoderkl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import SkipIfBeforePyTorchVersion, skip_if_downloading_fails, testing_data_config

tqdm, has_tqdm = optional_import("tqdm", name="tqdm")
_, has_einops = optional_import("einops")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_autoencoderkl_maisi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from monai.apps.generation.maisi.networks.autoencoderkl_maisi import AutoencoderKlMaisi
from monai.networks import eval_mode
from monai.utils import optional_import
from tests.utils import SkipIfBeforePyTorchVersion
from tests.test_utils import SkipIfBeforePyTorchVersion

tqdm, has_tqdm = optional_import("tqdm", name="tqdm")
_, has_einops = optional_import("einops")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_avg_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from torch.nn.functional import pad

from monai.inferers import AvgMerger
from tests.utils import assert_allclose
from tests.test_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()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_basic_unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import test_script_save

CASES_1D = []
for mode in ["pixelshuffle", "nontrainable", "deconv", None]:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_basic_unetplusplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import test_script_save

CASES_1D = []
for mode in ["pixelshuffle", "nontrainable", "deconv", None]:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bilateral_approx_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import skip_if_no_cpp_extension

TEST_CASES = [
[
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bilateral_approx_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import skip_if_no_cpp_extension, skip_if_no_cuda

TEST_CASES = [
[
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bilateral_precise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import skip_if_no_cpp_extension, skip_if_no_cuda, skip_if_quick

TEST_CASES = [
[
Expand Down
2 changes: 1 addition & 1 deletion tests/test_blend_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import TEST_NDARRAYS

plt, has_matplotlib = optional_import("matplotlib.pyplot")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_bounding_rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import monai
from monai.transforms import BoundingRect
from tests.utils import TEST_NDARRAYS
from tests.test_utils import TEST_NDARRAYS

TEST_CASE_1 = [(2, 3), [[0, 0], [1, 2]]]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_bounding_rectd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import monai
from monai.transforms import BoundingRectD
from tests.utils import TEST_NDARRAYS
from tests.test_utils import TEST_NDARRAYS

TEST_CASE_1 = [(2, 3), [[0, 0], [1, 2]]]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_box_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.test_utils import assert_allclose


class TestBoxTransform(unittest.TestCase):
Expand Down
Loading

0 comments on commit aa5bd06

Please sign in to comment.