def test_expose_ports_top_level_override(self): """ Verify that exposing a sub process in top level correctly overrides the parent's namespace properties with that of the exposed process, but that any valid property passed in the namespace_options will be the end-all-be-all """ def validator_function(input, port): pass # Define child process with all mutable properties of the inputs PortNamespace to a non-default value # This way we can check if the defaults of the ParentProcessSpec will be properly overridden ChildProcessSpec = ProcessSpec() ChildProcessSpec.input('a', valid_type=int) ChildProcessSpec.input('b', valid_type=str) ChildProcessSpec.inputs.validator = validator_function ChildProcessSpec.inputs.valid_type = bool ChildProcessSpec.inputs.required = False ChildProcessSpec.inputs.dynamic = True ChildProcessSpec.inputs.default = True ChildProcessSpec.inputs.help = 'testing' ParentProcessSpec = ProcessSpec() ParentProcessSpec.input('c', valid_type=float) ParentProcessSpec._expose_ports( process_class=None, source=ChildProcessSpec.inputs, destination=ParentProcessSpec.inputs, expose_memory=ParentProcessSpec._exposed_inputs, namespace=None, exclude=(), include=None, namespace_options={ 'validator': None, 'valid_type': None, 'required': True, 'dynamic': False, 'default': None, 'help': None, }) # Verify that all the ports are there self.assertIn('a', ParentProcessSpec.inputs) self.assertIn('b', ParentProcessSpec.inputs) self.assertIn('c', ParentProcessSpec.inputs) # Verify that all the port namespace attributes correspond to the values passed in the namespace_options self.assertEqual(ParentProcessSpec.inputs.validator, None) self.assertEqual(ParentProcessSpec.inputs.valid_type, None) self.assertEqual(ParentProcessSpec.inputs.required, True) self.assertEqual(ParentProcessSpec.inputs.dynamic, False) self.assertEqual(ParentProcessSpec.inputs.default, None) self.assertEqual(ParentProcessSpec.inputs.help, None)
def test_expose_ports_namespace(self): """ Verify that exposing a sub process in a namespace correctly overrides the defaults of the new namespace with the properties of the exposed port namespace """ def validator_function(input, port): pass # Define child process with all mutable properties of the inputs PortNamespace to a non-default value # This way we can check if the defaults of the ParentProcessSpec will be properly overridden ChildProcessSpec = ProcessSpec() ChildProcessSpec.input('a', valid_type=int) ChildProcessSpec.input('b', valid_type=str) ChildProcessSpec.inputs.validator = validator_function ChildProcessSpec.inputs.valid_type = bool ChildProcessSpec.inputs.required = False ChildProcessSpec.inputs.dynamic = True ChildProcessSpec.inputs.default = True ChildProcessSpec.inputs.help = 'testing' ParentProcessSpec = ProcessSpec() ParentProcessSpec.input('c', valid_type=float) ParentProcessSpec._expose_ports( process_class=None, source=ChildProcessSpec.inputs, destination=ParentProcessSpec.inputs, expose_memory=ParentProcessSpec._exposed_inputs, namespace='namespace', exclude=(), include=None, namespace_options={}) # Verify that all the ports are there self.assertIn('a', ParentProcessSpec.inputs['namespace']) self.assertIn('b', ParentProcessSpec.inputs['namespace']) self.assertIn('c', ParentProcessSpec.inputs) # Verify that all the port namespace attributes are copied over self.assertEqual(ParentProcessSpec.inputs['namespace'].validator, validator_function) self.assertEqual(ParentProcessSpec.inputs['namespace'].valid_type, bool) self.assertEqual(ParentProcessSpec.inputs['namespace'].required, False) self.assertEqual(ParentProcessSpec.inputs['namespace'].dynamic, True) self.assertEqual(ParentProcessSpec.inputs['namespace'].default, True) self.assertEqual(ParentProcessSpec.inputs['namespace'].help, 'testing')
def test_expose_ports_namespace_options_non_existent(self): """ Verify that passing non-supported PortNamespace mutable properties in namespace_options will raise a ValueError """ ChildProcessSpec = ProcessSpec() ParentProcessSpec = ProcessSpec() with self.assertRaises(ValueError): ParentProcessSpec._expose_ports( process_class=None, source=ChildProcessSpec.inputs, destination=ParentProcessSpec.inputs, expose_memory=ParentProcessSpec._exposed_inputs, namespace=None, exclude=(), include=None, namespace_options={ 'non_existent': None, })