mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
SF patch #1007189, multi-line imports, for instance:
"from blah import (foo, bar baz, bongo)"
This commit is contained in:
parent
876032e570
commit
1a4ddaecc7
14 changed files with 1394 additions and 1181 deletions
|
@ -211,6 +211,47 @@ if 1:
|
|||
self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'single')
|
||||
self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec')
|
||||
|
||||
def test_import(self):
|
||||
succeed = [
|
||||
'import sys',
|
||||
'import os, sys',
|
||||
'from __future__ import nested_scopes, generators',
|
||||
'from __future__ import (nested_scopes,\ngenerators)',
|
||||
'from __future__ import (nested_scopes,\ngenerators,)',
|
||||
'from sys import stdin, stderr, stdout',
|
||||
'from sys import (stdin, stderr,\nstdout)',
|
||||
'from sys import (stdin, stderr,\nstdout,)',
|
||||
'from sys import (stdin\n, stderr, stdout)',
|
||||
'from sys import (stdin\n, stderr, stdout,)',
|
||||
'from sys import stdin as si, stdout as so, stderr as se',
|
||||
'from sys import (stdin as si, stdout as so, stderr as se)',
|
||||
'from sys import (stdin as si, stdout as so, stderr as se,)',
|
||||
]
|
||||
fail = [
|
||||
'import (os, sys)',
|
||||
'import (os), (sys)',
|
||||
'import ((os), (sys))',
|
||||
'import (sys',
|
||||
'import sys)',
|
||||
'import (os,)',
|
||||
'from (sys) import stdin',
|
||||
'from __future__ import (nested_scopes',
|
||||
'from __future__ import nested_scopes)',
|
||||
'from __future__ import nested_scopes,\ngenerators',
|
||||
'from sys import (stdin',
|
||||
'from sys import stdin)',
|
||||
'from sys import stdin, stdout,\nstderr',
|
||||
'from sys import stdin si',
|
||||
'from sys import stdin,'
|
||||
'from sys import (*)',
|
||||
'from sys import (stdin,, stdout, stderr)',
|
||||
'from sys import (stdin, stdout),',
|
||||
]
|
||||
for stmt in succeed:
|
||||
compile(stmt, 'tmp', 'exec')
|
||||
for stmt in fail:
|
||||
self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec')
|
||||
|
||||
def test_main():
|
||||
test_support.run_unittest(TestSpecifics)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue