def test_masked_array_expected_values(self): wrapped_fn = biggus._dual_input_fn_wrapper('my_module.my_function', lambda a, b: a - b, lambda a, b: a + b, fn_name='identity') result = wrapped_fn(np.array([-5, 2]), np.array([-5, 2])) assert_array_equal(result.masked_array(), [-10, 4])
def test_masked_array_creates_elementwise(self): wrapped_fn = biggus._dual_input_fn_wrapper('my_module.my_function', lambda a, b: a + b, lambda a, b: a - b, fn_name='identity') result = wrapped_fn(np.array([-5, 2]), np.array([-5, 2])) self.assertIsInstance(result, biggus._Elementwise)
def test_masked_array_undefined(self): wrapped_fn = biggus._dual_input_fn_wrapper('my_module.my_function', lambda a, b: a + b, fn_name='identity') msg = 'No <lambda> operation defined for masked arrays.' result = wrapped_fn(np.array([-5, 2]), np.array([-5, 2])) with self.assertRaisesRegexp(TypeError, msg): assert_array_equal(result.masked_array(), [0, 4])
def test_docstring(self): wrapped_fn = biggus._dual_input_fn_wrapper('my_module.my_function', lambda a, b: a + b) doc = inspect.getdoc(wrapped_fn) expected = ('Return the elementwise evaluation of ' 'my_module.my_function(a, b) as another Array.') self.assertEqual(doc, expected)
def test_given_fn_name(self): wrapped_fn = biggus._dual_input_fn_wrapper('my_module.my_function', lambda a, b: a + b, fn_name='identity') self.assertEqual(wrapped_fn.__name__, 'identity')
def test_auto_fn_name(self): wrapped_fn = biggus._dual_input_fn_wrapper('my_module.my_function', lambda a, b: a + b) self.assertEqual(wrapped_fn.__name__, (lambda a, b: a + b).__name__)