summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEclips4 <80244920+Eclips4@users.noreply.github.com>2023-01-30 19:49:06 (GMT)
committerGitHub <noreply@github.com>2023-01-30 19:49:06 (GMT)
commit28db978d7f134edf6c86f21c42e15003511e7e9b (patch)
tree39ec0935ed8f65b50372e008e9189657ac8657f9 /Lib/test
parent7a3752338a2bfea023fcb119c842750fe799262f (diff)
downloadcpython-28db978d7f134edf6c86f21c42e15003511e7e9b.zip
cpython-28db978d7f134edf6c86f21c42e15003511e7e9b.tar.gz
cpython-28db978d7f134edf6c86f21c42e15003511e7e9b.tar.bz2
gh-101229: Add tests for aliases of imported names (#101230)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_ast.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index c728d2b..98d9b60 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -408,6 +408,24 @@ class AST_Tests(unittest.TestCase):
self.assertEqual(alias.col_offset, 16)
self.assertEqual(alias.end_col_offset, 17)
+ im = ast.parse("from bar import y as z").body[0]
+ alias = im.names[0]
+ self.assertEqual(alias.name, "y")
+ self.assertEqual(alias.asname, "z")
+ self.assertEqual(alias.lineno, 1)
+ self.assertEqual(alias.end_lineno, 1)
+ self.assertEqual(alias.col_offset, 16)
+ self.assertEqual(alias.end_col_offset, 22)
+
+ im = ast.parse("import bar as foo").body[0]
+ alias = im.names[0]
+ self.assertEqual(alias.name, "bar")
+ self.assertEqual(alias.asname, "foo")
+ self.assertEqual(alias.lineno, 1)
+ self.assertEqual(alias.end_lineno, 1)
+ self.assertEqual(alias.col_offset, 7)
+ self.assertEqual(alias.end_col_offset, 17)
+
def test_base_classes(self):
self.assertTrue(issubclass(ast.For, ast.stmt))
self.assertTrue(issubclass(ast.Name, ast.expr))