Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions tests/transforms/test_inverse_collation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@
class TestInverseCollation(unittest.TestCase):
"""Test collation for of random transformations with prob == 0 and 1."""

def setUp(self):
@classmethod
def setUpClass(cls):
super().setUpClass()
if not has_nib:
self.skipTest("nibabel required for test_inverse")

raise unittest.SkipTest("nibabel required for test_inverse")
set_determinism(seed=0)

b_size = 11
im_fname, seg_fname = (make_nifti_image(i) for i in create_test_image_3d(101, 100, 107))
load_ims = Compose([LoadImaged(KEYS), EnsureChannelFirstd(KEYS, channel_dim="no_channel")])
self.data_3d = [load_ims({"image": im_fname, "label": seg_fname}) for _ in range(b_size)]

b_size = 8
im_fname, seg_fname = (make_nifti_image(i) for i in create_test_image_3d(101, 100, 107))
cls.base_3d = load_ims({"image": im_fname, "label": seg_fname})
im_fname, seg_fname = (make_nifti_image(i) for i in create_test_image_2d(62, 37, rad_max=10))
load_ims = Compose([LoadImaged(KEYS), EnsureChannelFirstd(KEYS, channel_dim="no_channel")])
self.data_2d = [load_ims({"image": im_fname, "label": seg_fname}) for _ in range(b_size)]
cls.base_2d = load_ims({"image": im_fname, "label": seg_fname})
Comment on lines +100 to +103

@coderabbitai coderabbitai Bot Aug 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Clean up the temporary NIfTI files.

Lines 100 and 102 create temporary files and directories, but the returned paths are discarded. make_nifti_image assigns deletion to the caller, so each run leaves four files and directories behind. (raw.githubusercontent.com)

Retain the files in one temporary directory or register class cleanup before creating the fixtures. Cover partial setup failures too.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/transforms/test_inverse_collation.py` around lines 100 - 103, Update
the fixture setup around make_nifti_image and the class initialization to retain
all generated NIfTI paths in a shared temporary directory and register
class-level cleanup before creating the fixtures. Ensure cleanup covers both
files and directories, including partial failures during base_3d or base_2d
setup, while preserving the existing load_ims inputs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of scope since this is pre-existing. Being tracked here now: #9041

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aymuos15 Acknowledged. The cleanup issue is tracked in #9041, so no change is required in this pull request.

You are interacting with an AI system.


def setUp(self):
set_determinism(seed=0)
self.data_3d = [dict(self.base_3d) for _ in range(11)]
self.data_2d = [dict(self.base_2d) for _ in range(8)]
self.batch_size = 7

def tearDown(self):
Expand Down
Loading