From faf8068dd01c8eee7f6ea3f9e608126bf2034dc1 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Mon, 30 Jan 2023 12:21:18 -0800 Subject: [PATCH] gh-101229: Add tests for aliases of imported names (GH-101230) (cherry picked from commit 28db978d7f134edf6c86f21c42e15003511e7e9b) Co-authored-by: Eclips4 <80244920+Eclips4@users.noreply.github.com> --- Lib/test/test_ast.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index c33c0ae22379ce..b4ec1fef5ade05 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -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))