summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-11-07 19:49:18 +0200
committerGitHub <noreply@github.com>2021-11-07 19:49:18 +0200
commitb62f243b16b7f435c8be869577959e95a7927a91 (patch)
treec0bd0b1919741768bd8090ceaef565ff742a9455 /tests
parent62f3cfb18eb5e7d27f69f32c7412972d8bfff5fe (diff)
downloadastroid-git-b62f243b16b7f435c8be869577959e95a7927a91.tar.gz
Add typing and deprecation warnings to ``NodeNG.statement`` (#1217)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest_builder.py7
-rw-r--r--tests/unittest_nodes.py7
-rw-r--r--tests/unittest_scoped_nodes.py2
3 files changed, 15 insertions, 1 deletions
diff --git a/tests/unittest_builder.py b/tests/unittest_builder.py
index 300e4e92..11019e1b 100644
--- a/tests/unittest_builder.py
+++ b/tests/unittest_builder.py
@@ -38,6 +38,7 @@ from astroid.exceptions import (
AstroidSyntaxError,
AttributeInferenceError,
InferenceError,
+ StatementMissing,
)
from astroid.nodes.scoped_nodes import Module
@@ -614,7 +615,11 @@ class FileBuildTest(unittest.TestCase):
self.assertEqual(module.package, 0)
self.assertFalse(module.is_statement)
self.assertEqual(module.statement(), module)
- self.assertEqual(module.statement(), module)
+ with pytest.warns(DeprecationWarning) as records:
+ module.statement()
+ assert len(records) == 1
+ with self.assertRaises(StatementMissing):
+ module.statement(future=True)
def test_module_locals(self) -> None:
"""test the 'locals' dictionary of an astroid module"""
diff --git a/tests/unittest_nodes.py b/tests/unittest_nodes.py
index 73b4cecb..10607fe1 100644
--- a/tests/unittest_nodes.py
+++ b/tests/unittest_nodes.py
@@ -55,6 +55,7 @@ from astroid.exceptions import (
AstroidBuildingError,
AstroidSyntaxError,
AttributeInferenceError,
+ StatementMissing,
)
from astroid.nodes.node_classes import (
AssignAttr,
@@ -626,6 +627,12 @@ class ConstNodeTest(unittest.TestCase):
self.assertIs(node.value, value)
self.assertTrue(node._proxied.parent)
self.assertEqual(node._proxied.root().name, value.__class__.__module__)
+ with self.assertRaises(AttributeError):
+ with pytest.warns(DeprecationWarning) as records:
+ node.statement()
+ assert len(records) == 1
+ with self.assertRaises(StatementMissing):
+ node.statement(future=True)
def test_none(self) -> None:
self._test(None)
diff --git a/tests/unittest_scoped_nodes.py b/tests/unittest_scoped_nodes.py
index 2045e173..db673629 100644
--- a/tests/unittest_scoped_nodes.py
+++ b/tests/unittest_scoped_nodes.py
@@ -323,6 +323,7 @@ class FunctionNodeTest(ModuleLoader, unittest.TestCase):
def test_navigation(self) -> None:
function = self.module["global_access"]
self.assertEqual(function.statement(), function)
+ self.assertEqual(function.statement(future=True), function)
l_sibling = function.previous_sibling()
# check taking parent if child is not a stmt
self.assertIsInstance(l_sibling, nodes.Assign)
@@ -821,6 +822,7 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase):
def test_navigation(self) -> None:
klass = self.module["YO"]
self.assertEqual(klass.statement(), klass)
+ self.assertEqual(klass.statement(future=True), klass)
l_sibling = klass.previous_sibling()
self.assertTrue(isinstance(l_sibling, nodes.FunctionDef), l_sibling)
self.assertEqual(l_sibling.name, "global_access")