|
14 | 14 | from ....interfaces import fsl
|
15 | 15 | from ...utility.wrappers import Function
|
16 | 16 | from ....pipeline import Node
|
17 |
| - |
| 17 | +from ..specs import get_filecopy_info |
18 | 18 |
|
19 | 19 | standard_library.install_aliases()
|
20 | 20 |
|
@@ -55,8 +55,8 @@ def test_TraitedSpec_tab_completion():
|
55 | 55 | bet_nd = Node(fsl.BET(), name='bet')
|
56 | 56 | bet_interface = fsl.BET()
|
57 | 57 | bet_inputs = bet_nd.inputs.class_editable_traits()
|
58 |
| - bet_outputs = bet_nd.outputs.class_editable_traits() |
59 |
| - |
| 58 | + bet_outputs = bet_nd.outputs.class_editable_traits() |
| 59 | + |
60 | 60 | # Check __all__ for bet node and interface inputs
|
61 | 61 | assert set(bet_nd.inputs.__all__) == set(bet_inputs)
|
62 | 62 | assert set(bet_interface.inputs.__all__) == set(bet_inputs)
|
@@ -433,3 +433,45 @@ def test_ImageFile():
|
433 | 433 | with pytest.raises(nib.TraitError):
|
434 | 434 | x.nocompress = 'test.nii.gz'
|
435 | 435 | x.nocompress = 'test.mgh'
|
| 436 | + |
| 437 | + |
| 438 | +def test_filecopy_info(): |
| 439 | + class InputSpec(nib.TraitedSpec): |
| 440 | + foo = nib.traits.Int(desc='a random int') |
| 441 | + goo = nib.traits.Int(desc='a random int', mandatory=True) |
| 442 | + moo = nib.traits.Int(desc='a random int', mandatory=False) |
| 443 | + hoo = nib.traits.Int(desc='a random int', usedefault=True) |
| 444 | + zoo = nib.File(desc='a file', copyfile=False) |
| 445 | + woo = nib.File(desc='a file', copyfile=True) |
| 446 | + |
| 447 | + class DerivedInterface(nib.BaseInterface): |
| 448 | + input_spec = InputSpec |
| 449 | + resource_monitor = False |
| 450 | + |
| 451 | + def normalize_filenames(self): |
| 452 | + """A mock normalize_filenames for freesurfer interfaces that have one""" |
| 453 | + self.inputs.zoo = 'normalized_filename.ext' |
| 454 | + |
| 455 | + assert get_filecopy_info(nib.BaseInterface) == [] |
| 456 | + |
| 457 | + # Test on interface class, not instantiated |
| 458 | + info = get_filecopy_info(DerivedInterface) |
| 459 | + assert info[0]['key'] == 'woo' |
| 460 | + assert info[0]['copy'] |
| 461 | + assert info[1]['key'] == 'zoo' |
| 462 | + assert not info[1]['copy'] |
| 463 | + info = None |
| 464 | + |
| 465 | + # Test with instantiated interface |
| 466 | + derived = DerivedInterface() |
| 467 | + # First check that zoo is not defined |
| 468 | + assert derived.inputs.zoo == Undefined |
| 469 | + # After the first call to get_filecopy_info zoo is defined |
| 470 | + info = get_filecopy_info(derived) |
| 471 | + # Ensure that normalize_filenames was called |
| 472 | + assert derived.inputs.zoo == 'normalized_filename.ext' |
| 473 | + # Check the results are consistent |
| 474 | + assert info[0]['key'] == 'woo' |
| 475 | + assert info[0]['copy'] |
| 476 | + assert info[1]['key'] == 'zoo' |
| 477 | + assert not info[1]['copy'] |
0 commit comments