summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhippo91 <guillaume.peillex@gmail.com>2019-02-09 11:03:57 +0100
committerhippo91 <guillaume.peillex@gmail.com>2019-02-09 11:03:57 +0100
commit2aaad9c3e94b2f9b4eb1898e3a0f9c5f68635e3e (patch)
tree487c48284d8cdf61eeba4958c466039a39f13ac0
parentb14c130a7b106ef9bb042b7d32ff520f71e6c764 (diff)
downloadastroid-git-2aaad9c3e94b2f9b4eb1898e3a0f9c5f68635e3e.tar.gz
Add a unittest checking that the call to numpy.array function is not inferred as a list or a tuple
-rw-r--r--astroid/tests/unittest_brain_numpy.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/astroid/tests/unittest_brain_numpy.py b/astroid/tests/unittest_brain_numpy.py
index 141e5335..862a1d57 100644
--- a/astroid/tests/unittest_brain_numpy.py
+++ b/astroid/tests/unittest_brain_numpy.py
@@ -17,6 +17,7 @@ except ImportError:
from astroid import builder
from astroid import nodes
+from astroid import node_classes
class SubTestWrapper(unittest.TestCase):
@@ -573,6 +574,76 @@ class NumpyBrainCoreNumericTypesTest(SubTestWrapper):
with self.subTest(attr=attr):
self.assertNotEqual(len(inferred.getattr(attr)), 0)
+ def test_number_types_have_unary_operators(self):
+ """
+ Test that number types have unary operators
+ """
+ unary_ops = ("__neg__",)
+
+ for type_ in (
+ "float64",
+ "float96",
+ "floating",
+ "int16",
+ "int32",
+ "int32",
+ "int64",
+ "int8",
+ "integer",
+ "number",
+ "signedinteger",
+ "uint16",
+ "uint32",
+ "uint32",
+ "uint64",
+ "uint8",
+ "unsignedinteger",
+ ):
+ with self.subTest(typ=type_):
+ inferred = self._inferred_numpy_attribute(type_)
+ for attr in unary_ops:
+ with self.subTest(attr=attr):
+ self.assertNotEqual(len(inferred.getattr(attr)), 0)
+
+ def test_array_types_have_unary_operators(self):
+ """
+ Test that array types have unary operators
+ """
+ unary_ops = ("__neg__", "__inv__", "__invert__")
+
+ for type_ in ("ndarray",):
+ with self.subTest(typ=type_):
+ inferred = self._inferred_numpy_attribute(type_)
+ for attr in unary_ops:
+ with self.subTest(attr=attr):
+ self.assertNotEqual(len(inferred.getattr(attr)), 0)
+
+
+@unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.")
+class NumpyBrainFunctionReturningArrayTest(SubTestWrapper):
+ """
+ Test that calls to numpy functions returning arrays are correctly inferred
+ """
+ def _inferred_numpy_func_call(self, func_name):
+ node = builder.extract_node(
+ """
+ import numpy as np
+ func = np.{:s}
+ func([1, 2])
+ """.format(func_name)
+ )
+ return node.infer()
+
+ def test_numpy_function_calls_not_inferred_as_list_tuple(self):
+ """
+ Test that some calls to numpy functions are not inferred as list nor tuple
+ """
+ for func_ in ("array",):
+ with self.subTest(typ=func_):
+ inferred = [res for res in self._inferred_numpy_func_call(func_)]
+ self.assertNotIn(node_classes.List, inferred)
+ self.assertNotIn(node_classes.Tuple, inferred)
+
if __name__ == "__main__":
unittest.main()