Esempio n. 1
0
 def test_masked_array_expected_values(self):
     wrapped_fn = biggus._unary_fn_wrapper('my_module.my_function',
                                           lambda a: a + 10,
                                           lambda a: a - 10,
                                           fn_name='identity')
     assert_array_equal(wrapped_fn(np.array([-5, 2])).masked_array(),
                        [-15, -8])
Esempio n. 2
0
 def test_masked_array_undefined(self):
     wrapped_fn = biggus._unary_fn_wrapper('my_module.my_function',
                                           lambda a: a + 10,
                                           fn_name='identity')
     msg = 'No <lambda> operation defined for masked arrays.'
     with self.assertRaisesRegex(TypeError, msg):
         assert_array_equal(wrapped_fn(np.array([-5, 2])).masked_array(),
                            [-15, -8])
Esempio n. 3
0
    def test_docstring(self):
        wrapped_fn = biggus._unary_fn_wrapper('my_module.my_function',
                                              lambda a: a)
        doc = inspect.getdoc(wrapped_fn)

        expected = ('Return the elementwise evaluation of '
                    'my_module.my_function(a) as another Array.')
        self.assertEqual(doc, expected)
Esempio n. 4
0
 def test_unexpected_n_arguments(self):
     wrapped_fn = biggus._unary_fn_wrapper('my_module.my_function',
                                           lambda a: a + 10,
                                           fn_name='identity')
     # TODO: It would be good if this were not called "wrapped_function".
     if sys.version_info[0] == 2:
         msg = 'wrapped_function\(\) takes exactly 1 argument \(2 given\)'
     else:
         msg = ('wrapped_function\(\) takes 1 positional argument but 2 '
                'were given')
     with self.assertRaisesRegex(TypeError, msg) as ex:
         wrapped_fn(np.array([-5, 2]), np.array([-5, 2]))
Esempio n. 5
0
 def test_masked_array_creates_elementwise(self):
     wrapped_fn = biggus._unary_fn_wrapper('my_module.my_function',
                                           lambda a: a + 10,
                                           lambda a: a - 10,
                                           fn_name='identity')
     self.assertIsInstance(wrapped_fn(np.array([1])), biggus._Elementwise)
Esempio n. 6
0
 def test_given_fn_name(self):
     wrapped_fn = biggus._unary_fn_wrapper('my_module.my_function',
                                           lambda a: a, fn_name='identity')
     self.assertEqual(wrapped_fn.__name__, 'identity')
Esempio n. 7
0
 def test_auto_fn_name(self):
     wrapped_fn = biggus._unary_fn_wrapper('my_module.my_function',
                                           lambda a: a)
     self.assertEqual(wrapped_fn.__name__, (lambda a: a).__name__)