From 441979fe07662714e2f0b7166d97f12353865c86 Mon Sep 17 00:00:00 2001 From: hippo91 Date: Sun, 8 Dec 2019 20:43:38 +0100 Subject: Adds unittest for ufunc objects returning pair of ndarray --- tests/unittest_brain_numpy_core_umath.py | 35 ++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/tests/unittest_brain_numpy_core_umath.py b/tests/unittest_brain_numpy_core_umath.py index b81baa04..40e478b5 100644 --- a/tests/unittest_brain_numpy_core_umath.py +++ b/tests/unittest_brain_numpy_core_umath.py @@ -37,14 +37,14 @@ class NumpyBrainCoreUmathTest(unittest.TestCase): #"exp2", "expm1", "fabs", - #"frexp", + "frexp", #"isfinite", #"isinf", "log", "log1p", "log2", "logical_not", - # "modf", + "modf", "negative", "rad2deg", "reciprocal", @@ -212,6 +212,37 @@ class NumpyBrainCoreUmathTest(unittest.TestCase): ), ) + def test_numpy_core_umath_functions_return_type_tuple(self): + """ + Test that functions which should return a pair of ndarray do return it + """ + ndarray_returning_func = ("frexp", "modf") + + for func_ in ndarray_returning_func: + with self.subTest(typ=func_): + inferred_values = list(self._inferred_numpy_func_call(func_)) + self.assertTrue( + len(inferred_values) == 1, + msg="Too much inferred values ({}) for {:s}".format(inferred_values, func_), + ) + self.assertTrue( + inferred_values[-1].pytype() == "builtins.tuple", + msg="Illicit type for {:s} ({})".format( + func_, inferred_values[-1].pytype() + ), + ) + self.assertTrue( + len(inferred_values[0].elts) == 2, + msg="{} should return a pair of values. That's not the case.".format(func_) + ) + for array in inferred_values[-1].elts: + effective_infer = [m.pytype() for m in array.inferred()] + self.assertTrue( + ".ndarray" in effective_infer, + msg = ('Each item in the return of {} ' + 'should be inferred as a ndarray and not as {}'.format(func_, effective_infer)) + ) + if __name__ == "__main__": unittest.main() -- cgit v1.2.1