[Python-checkins] python/dist/src/Lib/test test_compile.py, 1.22, 1.23 test_grammar.py, 1.50, 1.51 test_parser.py, 1.19, 1.20

anthonybaxter at users.sourceforge.net anthonybaxter at users.sourceforge.net
Tue Aug 31 12:07:42 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21410/Lib/test

Modified Files:
	test_compile.py test_grammar.py test_parser.py 
Log Message:
SF patch #1007189, multi-line imports, for instance:
"from blah import (foo, bar
baz, bongo)"


Index: test_compile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_compile.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- test_compile.py	2 Aug 2004 08:30:07 -0000	1.22
+++ test_compile.py	31 Aug 2004 10:07:09 -0000	1.23
@@ -211,6 +211,47 @@
             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)
 

Index: test_grammar.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_grammar.py,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- test_grammar.py	19 May 2004 08:20:09 -0000	1.50
+++ test_grammar.py	31 Aug 2004 10:07:09 -0000	1.51
@@ -417,12 +417,16 @@
 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():

Index: test_parser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_parser.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- test_parser.py	2 Aug 2004 06:09:54 -0000	1.19
+++ test_parser.py	31 Aug 2004 10:07:09 -0000	1.20
@@ -130,12 +130,26 @@
     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")



More information about the Python-checkins mailing list