Skip to content

Commit

Permalink
pythongh-101229: Add tests for aliases of imported names (python#101230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eclips4 authored and mdboom committed Jan 31, 2023
1 parent 322ee96 commit 315aed1
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 @@ -408,6 +408,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 315aed1

Please sign in to comment.