summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_compile.py
diff options
context:
space:
mode:
authorAnthony Baxter <anthonybaxter@gmail.com>2004-08-31 10:07:13 (GMT)
committerAnthony Baxter <anthonybaxter@gmail.com>2004-08-31 10:07:13 (GMT)
commit1a4ddaecc732c207fa69890db87ac4b47da867b8 (patch)
tree3c0c9c3086bc1c5ac72554e8ce6a03773cdc8770 /Lib/test/test_compile.py
parent876032e5700f58cec44a357b6d3174be76b40278 (diff)
downloadcpython-1a4ddaecc732c207fa69890db87ac4b47da867b8.zip
cpython-1a4ddaecc732c207fa69890db87ac4b47da867b8.tar.gz
cpython-1a4ddaecc732c207fa69890db87ac4b47da867b8.tar.bz2
SF patch #1007189, multi-line imports, for instance:
"from blah import (foo, bar baz, bongo)"
Diffstat (limited to 'Lib/test/test_compile.py')
-rw-r--r--Lib/test/test_compile.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index b1644cb..5011d03 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -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)