mirror of
https://github.com/python/cpython.git
synced 2025-08-11 20:40:27 +00:00
Issue #9130: Fix validation of relative imports in parser module.
This commit is contained in:
parent
a7ee59b3d3
commit
75b44b3437
3 changed files with 26 additions and 3 deletions
|
@ -221,6 +221,12 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
|
|||
self.check_suite("import sys as system, math")
|
||||
self.check_suite("import sys, math as my_math")
|
||||
|
||||
def test_relative_imports(self):
|
||||
self.check_suite("from . import name")
|
||||
self.check_suite("from .. import name")
|
||||
self.check_suite("from .pkg import name")
|
||||
self.check_suite("from ..pkg import name")
|
||||
|
||||
def test_pep263(self):
|
||||
self.check_suite("# -*- coding: iso-8859-1 -*-\n"
|
||||
"pass\n")
|
||||
|
@ -519,6 +525,20 @@ class IllegalSyntaxTestCase(unittest.TestCase):
|
|||
(0, ''))
|
||||
self.check_bad_tree(tree, "malformed global ast")
|
||||
|
||||
def test_missing_import_source(self):
|
||||
# from import a
|
||||
tree = \
|
||||
(257,
|
||||
(267,
|
||||
(268,
|
||||
(269,
|
||||
(281,
|
||||
(283, (1, 'from'), (1, 'import'),
|
||||
(286, (284, (1, 'fred')))))),
|
||||
(4, ''))),
|
||||
(4, ''), (0, ''))
|
||||
self.check_bad_tree(tree, "from import a")
|
||||
|
||||
|
||||
class CompileTestCase(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue