def test_find_transform_scalars(self): # Module with a function self.assertEqual(find_transform_scalars( function, None), function.transform_scalars) # Module with operator class func = find_transform_scalars(simple, None) self.assertTrue(isinstance(func.__self__, simple.SimpleOperator)) self.assertEqual(func.__func__.__name__, 'transform_scalars') self.assertTrue(func(None)) # Module with none with self.assertRaises(Exception): find_transform_scalars(unittest, None)
def test_find_transform_scalars(): # Module with a function found = find_transform_scalars(function, None) assert (found == function.transform_scalars) # Module with operator class func = find_transform_scalars(simple, None) assert isinstance(func.__self__, simple.SimpleOperator) assert func.__func__.__name__ == 'transform_scalars' assert func(None) # Module with none with pytest.raises(Exception): find_transform_scalars(unittest, None)
def _load_transform_functions(operators): transform_functions = [] for operator in operators: # Special case for tilt angles operator if operator['type'] == 'SetTiltAngles': # Just save the angles angles = {'angles': [float(a) for a in operator['angles']]} transform_functions.append((operator['type'], None, angles)) continue if 'script' not in operator: raise Exception( 'No script property found. C++ operator are not supported.') operator_script = operator['script'] operator_label = operator['label'] operator_module = _load_operator_module(operator_label, operator_script) transform_scalars = find_transform_scalars(operator_module) # partial apply the arguments arguments = {} if 'arguments' in operator: arguments = operator['arguments'] transform_functions.append( (operator_label, transform_scalars, arguments)) return transform_functions
def _load_transform_functions(operators): transform_functions = [] for operator in operators: if 'script' not in operator: raise Exception( 'No script property found. C++ operator are not supported.') operator_script = operator['script'] operator_label = operator['label'] operator_module = _load_operator_module(operator_label, operator_script) transform_scalars = find_transform_scalars(operator_module) # partial apply the arguments arguments = {} if 'arguments' in operator: arguments = operator['arguments'] transform_functions.append((operator_label, transform_scalars, arguments)) return transform_functions