summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorhippo91 <guillaume.peillex@gmail.com>2021-09-25 13:26:38 +0200
committerGitHub <noreply@github.com>2021-09-25 13:26:38 +0200
commit05445e23fe1292eda236f8d15674aa2fea811720 (patch)
tree5bcf15be7573345f81465d44e51964fbb9e9ac11 /tests
parent4ffdf1108a6084b85e282b5835427c1d747bb22c (diff)
downloadastroid-git-05445e23fe1292eda236f8d15674aa2fea811720.tar.gz
Bug pylint 4960 (#1176)
* Revert modifications of PR 1148. While it is probably still a good idea to prevent nodes that are dynamically imported to be inferred through an astroid's brain, the way it was done in builder.py was incorrect. The way it was done, lead to prevent the use of astroid legetimate brains even for node that was not dynamically loaded. * Adds a brain to infer the numpy.ma.masked_where function Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest_brain_numpy_ma.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unittest_brain_numpy_ma.py b/tests/unittest_brain_numpy_ma.py
new file mode 100644
index 00000000..96dddd28
--- /dev/null
+++ b/tests/unittest_brain_numpy_ma.py
@@ -0,0 +1,53 @@
+# Copyright (c) 2021 hippo91 <guillaume.peillex@gmail.com>
+
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
+import pytest
+
+try:
+ import numpy # pylint: disable=unused-import
+
+ HAS_NUMPY = True
+except ImportError:
+ HAS_NUMPY = False
+
+from astroid import builder
+
+
+@pytest.mark.skipif(HAS_NUMPY is False, reason="This test requires the numpy library.")
+class TestBrainNumpyMa:
+ """
+ Test the numpy ma brain module
+ """
+
+ @staticmethod
+ def test_numpy_ma_masked_where_returns_maskedarray():
+ """
+ Test that calls to numpy ma masked_where returns a MaskedArray object.
+
+ The "masked_where" node is an Attribute
+ """
+ src = """
+ import numpy as np
+ data = np.ndarray((1,2))
+ np.ma.masked_where([1, 0, 0], data)
+ """
+ node = builder.extract_node(src)
+ cls_node = node.inferred()[0]
+ assert cls_node.pytype() == "numpy.ma.core.MaskedArray"
+
+ @staticmethod
+ def test_numpy_ma_masked_where_returns_maskedarray_bis():
+ """
+ Test that calls to numpy ma masked_where returns a MaskedArray object
+
+ The "masked_where" node is a Name
+ """
+ src = """
+ from numpy.ma import masked_where
+ data = np.ndarray((1,2))
+ masked_where([1, 0, 0], data)
+ """
+ node = builder.extract_node(src)
+ cls_node = node.inferred()[0]
+ assert cls_node.pytype() == "numpy.ma.core.MaskedArray"