Skip to content

Commit b3e9908

Browse files
aymuos15ericspod
andauthored
tests: remove byte-identical duplicate test cases (#9051)
### Description Test-suite cleanup: removes parametrized test cases that are byte-identical duplicates of another case in the same file, so each was silently running the same test twice. Follows the earlier byte-identical-entry pass (#8942) with a focus on duplicates spread across differently-named `TEST_CASE_*` variables that feed the same `@parameterized.expand`. Changes, per file (duplicate → surviving twin): - `tests/transforms/test_load_image.py` — drop `TEST_CASE_2` (=1), `TEST_CASE_4` (=3), `TEST_CASE_7` (=6), `TEST_CASE_9` (=8); the two `test_*_reader` expand lists lose the corresponding slots (7 cases → 5 and 5 → 3). - `tests/transforms/spatial/test_grid_patch.py` / `test_grid_patchd.py` — drop the `TEST_CASE_4` that is byte-identical to `TEST_CASE_3` (`offset (0, 0)`), and its slot in the per-backend `TEST_NDARRAYS` expansion. - `tests/transforms/spatial/test_rand_grid_patch.py` / `test_rand_grid_patchd.py` — drop `TEST_CASE_3`, byte-identical to `TEST_CASE_0` (`min/max_offset 0`), and its slot. - `tests/fl/monai_algo/test_fl_monai_algo.py` — drop `TEST_TRAIN_3`, byte-identical to `TEST_TRAIN_1`; the train expand list goes from 4 cases to 3 (one full FL train round-trip no longer runs twice). - `tests/inferers/test_patch_inferer.py` — `TEST_CASE_ERROR_10` was byte-identical to `TEST_CASE_ERROR_7` **and** never referenced by any expand list (the error tests parametrize over `_0 .. _9` only). Dead code; removed. Test-only change: no production code touched, no behaviour altered — each removed case re-ran an identical parametrization. Collected test counts before → after (identical cases removed, coverage unchanged): | file | cases before | after | |---|---|---| | test_load_image.py | 51 | 47 | | grid_patch | 70 | 66 | | grid_patchd | 68 | 64 | | rand_grid_patch | 58 | 54 | | rand_grid_patchd | 56 | 52 | | fl_monai_algo | 10 | 9 | | patch_inferer | 46 | 46 (dead code only) | ### 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: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk> Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
1 parent 25847e7 commit b3e9908

6 files changed

Lines changed: 3 additions & 37 deletions

File tree

‎tests/fl/monai_algo/test_fl_monai_algo.py‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,6 @@
5757
"config_filters_filename": None,
5858
}
5959
]
60-
TEST_TRAIN_3 = [
61-
{
62-
"bundle_root": _data_dir,
63-
"train_workflow": ConfigWorkflow(
64-
config_file=os.path.join(_data_dir, "config_fl_train.json"),
65-
workflow_type="train",
66-
logging_file=_logging_file,
67-
),
68-
"config_evaluate_filename": None,
69-
"config_filters_filename": os.path.join(_data_dir, "config_fl_filters.json"),
70-
}
71-
]
7260

7361
TEST_TRAIN_4 = [
7462
{
@@ -218,7 +206,7 @@ def _dispose_sqlite_engines():
218206
@SkipIfNoModule("ignite")
219207
@SkipIfNoModule("mlflow")
220208
class TestFLMonaiAlgo(unittest.TestCase):
221-
@parameterized.expand([TEST_TRAIN_1, TEST_TRAIN_2, TEST_TRAIN_3, TEST_TRAIN_4])
209+
@parameterized.expand([TEST_TRAIN_1, TEST_TRAIN_2, TEST_TRAIN_4])
222210
def test_train(self, input_params):
223211
# initialize algo
224212
algo = MonaiAlgo(**input_params)

‎tests/transforms/spatial/test_grid_patch.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
TEST_CASE_1 = [{"patch_size": (2, 2), "num_patches": 3}, A, [A11, A12, A21]]
3232
TEST_CASE_2 = [{"patch_size": (2, 2), "num_patches": 5}, A, [A11, A12, A21, A22, np.zeros((3, 2, 2))]]
3333
TEST_CASE_3 = [{"patch_size": (2, 2), "offset": (0, 0)}, A, [A11, A12, A21, A22]]
34-
TEST_CASE_4 = [{"patch_size": (2, 2), "offset": (0, 0)}, A, [A11, A12, A21, A22]]
3534
TEST_CASE_5 = [{"patch_size": (2, 2), "offset": (2, 2)}, A, [A22]]
3635
TEST_CASE_6 = [{"patch_size": (2, 2), "offset": (0, 2)}, A, [A12, A22]]
3736
TEST_CASE_7 = [{"patch_size": (2, 2), "offset": (2, 0)}, A, [A21, A22]]
@@ -81,7 +80,6 @@
8180
TEST_CASES.append([p, *TEST_CASE_1])
8281
TEST_CASES.append([p, *TEST_CASE_2])
8382
TEST_CASES.append([p, *TEST_CASE_3])
84-
TEST_CASES.append([p, *TEST_CASE_4])
8583
TEST_CASES.append([p, *TEST_CASE_5])
8684
TEST_CASES.append([p, *TEST_CASE_6])
8785
TEST_CASES.append([p, *TEST_CASE_7])

‎tests/transforms/spatial/test_grid_patchd.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
TEST_CASE_1 = [{"patch_size": (2, 2), "num_patches": 3}, {"image": A}, [A11, A12, A21]]
3131
TEST_CASE_2 = [{"patch_size": (2, 2), "num_patches": 5}, {"image": A}, [A11, A12, A21, A22, np.zeros((3, 2, 2))]]
3232
TEST_CASE_3 = [{"patch_size": (2, 2), "offset": (0, 0)}, {"image": A}, [A11, A12, A21, A22]]
33-
TEST_CASE_4 = [{"patch_size": (2, 2), "offset": (0, 0)}, {"image": A}, [A11, A12, A21, A22]]
3433
TEST_CASE_5 = [{"patch_size": (2, 2), "offset": (2, 2)}, {"image": A}, [A22]]
3534
TEST_CASE_6 = [{"patch_size": (2, 2), "offset": (0, 2)}, {"image": A}, [A12, A22]]
3635
TEST_CASE_7 = [{"patch_size": (2, 2), "offset": (2, 0)}, {"image": A}, [A21, A22]]
@@ -61,7 +60,6 @@
6160
TEST_SINGLE.append([p, *TEST_CASE_1])
6261
TEST_SINGLE.append([p, *TEST_CASE_2])
6362
TEST_SINGLE.append([p, *TEST_CASE_3])
64-
TEST_SINGLE.append([p, *TEST_CASE_4])
6563
TEST_SINGLE.append([p, *TEST_CASE_5])
6664
TEST_SINGLE.append([p, *TEST_CASE_6])
6765
TEST_SINGLE.append([p, *TEST_CASE_7])

‎tests/transforms/spatial/test_rand_grid_patch.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
A,
3636
[A11, A12, A21, A22, np.zeros((3, 2, 2))],
3737
]
38-
TEST_CASE_3 = [{"patch_size": (2, 2), "min_offset": 0, "max_offset": 0}, A, [A11, A12, A21, A22]]
3938
TEST_CASE_4 = [{"patch_size": (2, 2)}, A, [A11, A12, A21, A22]]
4039
TEST_CASE_5 = [{"patch_size": (2, 2), "min_offset": 2, "max_offset": 2}, A, [A22]]
4140
TEST_CASE_6 = [{"patch_size": (2, 2), "min_offset": (0, 2), "max_offset": (0, 2)}, A, [A12, A22]]
@@ -91,7 +90,6 @@
9190
TEST_SINGLE.append([p, *TEST_CASE_0])
9291
TEST_SINGLE.append([p, *TEST_CASE_1])
9392
TEST_SINGLE.append([p, *TEST_CASE_2])
94-
TEST_SINGLE.append([p, *TEST_CASE_3])
9593
TEST_SINGLE.append([p, *TEST_CASE_4])
9694
TEST_SINGLE.append([p, *TEST_CASE_5])
9795
TEST_SINGLE.append([p, *TEST_CASE_6])

‎tests/transforms/spatial/test_rand_grid_patchd.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
{"image": A},
3535
[A11, A12, A21, A22, np.zeros((3, 2, 2))],
3636
]
37-
TEST_CASE_3 = [{"patch_size": (2, 2), "min_offset": 0, "max_offset": 0}, {"image": A}, [A11, A12, A21, A22]]
3837
TEST_CASE_4 = [{"patch_size": (2, 2)}, {"image": A}, [A11, A12, A21, A22]]
3938
TEST_CASE_5 = [{"patch_size": (2, 2), "min_offset": 2, "max_offset": 2}, {"image": A}, [A22]]
4039
TEST_CASE_6 = [{"patch_size": (2, 2), "min_offset": (0, 2), "max_offset": (0, 2)}, {"image": A}, [A12, A22]]
@@ -71,7 +70,6 @@
7170
TEST_SINGLE.append([p, *TEST_CASE_0])
7271
TEST_SINGLE.append([p, *TEST_CASE_1])
7372
TEST_SINGLE.append([p, *TEST_CASE_2])
74-
TEST_SINGLE.append([p, *TEST_CASE_3])
7573
TEST_SINGLE.append([p, *TEST_CASE_4])
7674
TEST_SINGLE.append([p, *TEST_CASE_5])
7775
TEST_SINGLE.append([p, *TEST_CASE_6])

‎tests/transforms/test_load_image.py‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ def get_data(self, _img):
8888

8989
TEST_CASE_1 = [{}, ["test_image.nii.gz"], (128, 128, 128)]
9090

91-
TEST_CASE_2 = [{}, ["test_image.nii.gz"], (128, 128, 128)]
92-
9391
TEST_CASE_3 = [{}, ["test_image.nii.gz", "test_image2.nii.gz", "test_image3.nii.gz"], (3, 128, 128, 128)]
9492

9593
TEST_CASE_3_1 = [ # .mgz format
@@ -98,8 +96,6 @@ def get_data(self, _img):
9896
(3, 128, 128, 128),
9997
]
10098

101-
TEST_CASE_4 = [{}, ["test_image.nii.gz", "test_image2.nii.gz", "test_image3.nii.gz"], (3, 128, 128, 128)]
102-
10399
TEST_CASE_4_1 = [ # additional parameter
104100
{"mmap": False},
105101
["test_image.nii.gz", "test_image2.nii.gz", "test_image3.nii.gz"],
@@ -126,8 +122,6 @@ def get_data(self, _img):
126122

127123
TEST_CASE_6 = [{"reader": ITKReader() if has_itk else "itkreader"}, ["test_image.nii.gz"], (128, 128, 128)]
128124

129-
TEST_CASE_7 = [{"reader": ITKReader() if has_itk else "itkreader"}, ["test_image.nii.gz"], (128, 128, 128)]
130-
131125
TEST_CASE_8 = [
132126
{"reader": ITKReader() if has_itk else "itkreader"},
133127
["test_image.nii.gz", "test_image2.nii.gz", "test_image3.nii.gz"],
@@ -140,12 +134,6 @@ def get_data(self, _img):
140134
(384, 128, 128),
141135
]
142136

143-
TEST_CASE_9 = [
144-
{"reader": ITKReader() if has_itk else "itkreader"},
145-
["test_image.nii.gz", "test_image2.nii.gz", "test_image3.nii.gz"],
146-
(3, 128, 128, 128),
147-
]
148-
149137
TEST_CASE_10 = [
150138
{"reader": ITKReader(pixel_type=itk_uc) if has_itk else "itkreader"},
151139
"tests/testing_data/CT_DICOM",
@@ -258,9 +246,7 @@ def tearDownClass(cls):
258246
shutil.rmtree(cls.tmpdir)
259247
super().tearDownClass()
260248

261-
@parameterized.expand(
262-
[TEST_CASE_1, TEST_CASE_2, TEST_CASE_3, TEST_CASE_3_1, TEST_CASE_4, TEST_CASE_4_1, TEST_CASE_5]
263-
)
249+
@parameterized.expand([TEST_CASE_1, TEST_CASE_3, TEST_CASE_3_1, TEST_CASE_4_1, TEST_CASE_5])
264250
def test_nibabel_reader(self, input_param, filenames, expected_shape):
265251
test_image = np.random.rand(128, 128, 128)
266252
with tempfile.TemporaryDirectory() as tempdir:
@@ -302,7 +288,7 @@ def test_nibabel_reader_gpu(self, input_param, filenames, expected_shape):
302288
result_cpu = LoadImage(image_only=True, **input_param_cpu)(filenames)
303289
assert_allclose(result_cpu, result.cpu(), atol=1e-6)
304290

305-
@parameterized.expand([TEST_CASE_6, TEST_CASE_7, TEST_CASE_8, TEST_CASE_8_1, TEST_CASE_9])
291+
@parameterized.expand([TEST_CASE_6, TEST_CASE_8, TEST_CASE_8_1])
306292
def test_itk_reader(self, input_param, filenames, expected_shape):
307293
test_image = torch.randint(0, 256, (128, 128, 128), dtype=torch.uint8).numpy()
308294
print("Test image value range:", test_image.min(), test_image.max())

0 commit comments

Comments
 (0)