Skip to content

Commit

Permalink
Add test and remove try-error block
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloesch committed Oct 24, 2024
1 parent 8d5a951 commit 44fc090
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/torchio/transforms/augmentation/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ def __repr__(self) -> str:

def get_init_args(self) -> Dict:
init_args = super().get_init_args()
try:
# Remove parse_input as it is set to False in the __init__
if 'parse_input' in init_args:
init_args.pop('parse_input')
except KeyError:
pass
return init_args

def apply_transform(self, subject: Subject) -> Subject:
Expand Down Expand Up @@ -115,11 +112,8 @@ def __init__(self, transforms: TypeTransformsDict, **kwargs):

def get_init_args(self) -> Dict:
init_args = super().get_init_args()
try:
# Remove parse_input as it is set to False in the __init__
if 'parse_input' in init_args:
init_args.pop('parse_input')
except KeyError:
pass
return init_args

def apply_transform(self, subject: Subject) -> Subject:
Expand Down
24 changes: 24 additions & 0 deletions tests/transforms/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,27 @@ def test_bad_keys_type(self):
# From https://github.com/fepegar/torchio/issues/923
with self.assertRaises(ValueError):
tio.RandomAffine(include='t1')

def test_init_args(self):
transform = tio.Compose([tio.RandomNoise()])
init_args = transform.get_init_args()
assert 'parse_input' not in init_args

transform = tio.OneOf([tio.RandomNoise()])
init_args = transform.get_init_args()
assert 'parse_input' not in init_args

transform = tio.RandomNoise()
init_args = transform.get_init_args()
assert all(
arg in init_args
for arg in [
'p',
'copy',
'include',
'exclude',
'keep',
'parse_input',
'label_keys',
]
)

0 comments on commit 44fc090

Please sign in to comment.