def test_BaseInterface(): assert nib.BaseInterface.help() == None assert nib.BaseInterface._get_filecopy_info() == [] class InputSpec(nib.TraitedSpec): foo = nib.traits.Int(desc='a random int') goo = nib.traits.Int(desc='a random int', mandatory=True) moo = nib.traits.Int(desc='a random int', mandatory=False) hoo = nib.traits.Int(desc='a random int', usedefault=True) zoo = nib.File(desc='a file', copyfile=False) woo = nib.File(desc='a file', copyfile=True) class OutputSpec(nib.TraitedSpec): foo = nib.traits.Int(desc='a random int') class DerivedInterface(nib.BaseInterface): input_spec = InputSpec assert DerivedInterface.help() == None assert 'moo' in ''.join(DerivedInterface._inputs_help()) assert DerivedInterface()._outputs() == None assert DerivedInterface._get_filecopy_info()[0]['key'] == 'woo' assert DerivedInterface._get_filecopy_info()[0]['copy'] assert DerivedInterface._get_filecopy_info()[1]['key'] == 'zoo' assert not DerivedInterface._get_filecopy_info()[1]['copy'] assert DerivedInterface().inputs.foo == Undefined with pytest.raises(ValueError): DerivedInterface()._check_mandatory_inputs() assert DerivedInterface(goo=1)._check_mandatory_inputs() == None with pytest.raises(ValueError): DerivedInterface().run() with pytest.raises(NotImplementedError): DerivedInterface(goo=1).run() class DerivedInterface2(DerivedInterface): output_spec = OutputSpec def _run_interface(self, runtime): return runtime assert DerivedInterface2.help() == None assert DerivedInterface2()._outputs().foo == Undefined with pytest.raises(NotImplementedError): DerivedInterface2(goo=1).run() default_inpu_spec = nib.BaseInterface.input_spec nib.BaseInterface.input_spec = None with pytest.raises(Exception): nib.BaseInterface() nib.BaseInterface.input_spec = default_inpu_spec
def test_ImageFile(): x = nib.BaseInterface().inputs # setup traits x.add_trait('nifti', nib.ImageFile(types=['nifti1', 'dicom'])) x.add_trait('anytype', nib.ImageFile()) x.add_trait('newtype', nib.ImageFile(types=['nifti10'])) x.add_trait('nocompress', nib.ImageFile(types=['mgh'], allow_compressed=False)) with pytest.raises(nib.TraitError): x.nifti = 'test.mgz' x.nifti = 'test.nii' x.anytype = 'test.xml' with pytest.raises(AttributeError): x.newtype = 'test.nii' with pytest.raises(nib.TraitError): x.nocompress = 'test.nii.gz' x.nocompress = 'test.mgh'