Skip to content

Commit

Permalink
pythongh-101229: Add tests for aliases of imported names (pythonGH-10…
Browse files Browse the repository at this point in the history
…1230)

(cherry picked from commit 28db978)

Co-authored-by: Eclips4 <80244920+Eclips4@users.noreply.github.com>
  • Loading branch information
miss-islington and Eclips4 authored Jan 30, 2023
1 parent 6ec9f2d commit faf8068
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Lib/test/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,24 @@ def test_alias(self):
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))
Expand Down

0 comments on commit faf8068

Please sign in to comment.