summaryrefslogtreecommitdiffstats
path: root/Lib/test
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
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')
-rw-r--r--Lib/test/output/test_grammar3
-rw-r--r--Lib/test/test_compile.py41
-rw-r--r--Lib/test/test_grammar.py6
-rw-r--r--Lib/test/test_parser.py14
4 files changed, 62 insertions, 2 deletions
diff --git a/Lib/test/output/test_grammar b/Lib/test/output/test_grammar
index 00fab49..6174e7a 100644
--- a/Lib/test/output/test_grammar
+++ b/Lib/test/output/test_grammar
@@ -35,7 +35,8 @@ continue + try/finally ok
testing continue and break in try/except in loop
return_stmt
raise_stmt
-import_stmt
+import_name
+import_from
global_stmt
exec_stmt
assert_stmt
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)
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index e0d5b74..7f5d10d 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -417,12 +417,16 @@ except RuntimeError: pass
try: raise KeyboardInterrupt
except KeyboardInterrupt: pass
-print 'import_stmt' # 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*)
+print 'import_name' # 'import' dotted_as_names
import sys
import time, sys
+print 'import_from' # 'from' dotted_name 'import' ('*' | '(' import_as_names ')' | import_as_names)
from time import time
+from time import (time)
from sys import *
from sys import path, argv
+from sys import (path, argv)
+from sys import (path, argv,)
print 'global_stmt' # 'global' NAME (',' NAME)*
def f():
diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py
index 978ce57..0f8c1d0 100644
--- a/Lib/test/test_parser.py
+++ b/Lib/test/test_parser.py
@@ -130,12 +130,26 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
def test_import_from_statement(self):
self.check_suite("from sys.path import *")
self.check_suite("from sys.path import dirname")
+ self.check_suite("from sys.path import (dirname)")
+ self.check_suite("from sys.path import (dirname,)")
self.check_suite("from sys.path import dirname as my_dirname")
+ self.check_suite("from sys.path import (dirname as my_dirname)")
+ self.check_suite("from sys.path import (dirname as my_dirname,)")
self.check_suite("from sys.path import dirname, basename")
+ self.check_suite("from sys.path import (dirname, basename)")
+ self.check_suite("from sys.path import (dirname, basename,)")
self.check_suite(
"from sys.path import dirname as my_dirname, basename")
self.check_suite(
+ "from sys.path import (dirname as my_dirname, basename)")
+ self.check_suite(
+ "from sys.path import (dirname as my_dirname, basename,)")
+ self.check_suite(
"from sys.path import dirname, basename as my_basename")
+ self.check_suite(
+ "from sys.path import (dirname, basename as my_basename)")
+ self.check_suite(
+ "from sys.path import (dirname, basename as my_basename,)")
def test_basic_import_statement(self):
self.check_suite("import sys")