Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test__load_primitive_value_error(load_mock, gpp_mock):
load_mock.return_value = None
gpp_mock.return_value = ['a', 'b']
with pytest.raises(ValueError):
discovery.load_primitive('invalid.primitive')
load_mock.assert_called_once_with('invalid.primitive', ['a', 'b'])
def test__load_primitive_success(load_mock, gpp_mock):
gpp_mock.return_value = ['a', 'b']
primitive = discovery.load_primitive('valid.primitive')
load_mock.assert_called_once_with('valid.primitive', ['a', 'b'])
assert primitive == load_mock.return_value
def __init__(self, primitive, **kwargs):
if isinstance(primitive, str):
primitive = load_primitive(primitive)
self.metadata = primitive
self.name = primitive['name']
self.primitive = import_object(self.metadata['primitive'])
self._fit = self.metadata.get('fit', dict())
self.fit_args = self._fit.get('args', [])
self.fit_method = self._fit.get('method')
self._produce = self.metadata['produce']
self.produce_args = self._produce['args']
self.produce_output = self._produce['output']
self.produce_method = self._produce.get('method')
self._class = bool(self.produce_method)