]> granicus.if.org Git - python/commitdiff
SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
authorNeal Norwitz <nnorwitz@gmail.com>
Sat, 13 Dec 2003 22:43:34 +0000 (22:43 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sat, 13 Dec 2003 22:43:34 +0000 (22:43 +0000)
Lib/test/badsyntax_future3.py
Lib/test/badsyntax_future4.py
Lib/test/badsyntax_future5.py
Lib/test/badsyntax_future6.py
Lib/test/badsyntax_future7.py
Lib/test/badsyntax_future8.py [new file with mode: 0644]
Lib/test/badsyntax_future9.py [new file with mode: 0644]
Lib/test/output/test_future [deleted file]
Lib/test/test_future.py
Lib/test/test_future1.py
Lib/test/test_future2.py

index 166628cc494ee05c587a8778a14fb0a501751ae8..f1c8417edaa297388bf9b243d6556c738a30abc8 100644 (file)
@@ -7,4 +7,4 @@ def f(x):
         return x + y
     return g
 
-print f(2)(4)
+result = f(2)(4)
index 805263be8915e19a0d4c4f101847a2453deb98b7..b5f4c98e922ac229ddbdb23bdff85e2ebedfbd15 100644 (file)
@@ -7,4 +7,4 @@ def f(x):
         return x + y
     return g
 
-print f(2)(4)
+result = f(2)(4)
index 118620873b28c6915a49416c640223ed5fa74d3e..8a7e5fcb70ff2e5e237eb77b37583374daba541e 100644 (file)
@@ -9,4 +9,4 @@ def f(x):
         return x + y
     return g
 
-print f(2)(4)
+result = f(2)(4)
index 35c14558b8139dd1611315e8279191d19c570f30..5a8b55a02c41bf0dd8193ee17de9f57d96c71b60 100644 (file)
@@ -7,4 +7,4 @@ def f(x):
         return x + y
     return g
 
-print f(2)(4)
+result = f(2)(4)
index 370372d4596299d2ebc11a244a8f36b83dcb5754..131db2c2164cf27164b8a062a9379c87d29ed681 100644 (file)
@@ -8,4 +8,4 @@ def f(x):
         return x + y
     return g
 
-print f(2)(4)
+result = f(2)(4)
diff --git a/Lib/test/badsyntax_future8.py b/Lib/test/badsyntax_future8.py
new file mode 100644 (file)
index 0000000..c167b09
--- /dev/null
@@ -0,0 +1,10 @@
+"""This is a test"""
+
+from __future__ import *
+
+def f(x):
+    def g(y):
+        return x + y
+    return g
+
+print f(2)(4)
diff --git a/Lib/test/badsyntax_future9.py b/Lib/test/badsyntax_future9.py
new file mode 100644 (file)
index 0000000..cdce32a
--- /dev/null
@@ -0,0 +1,10 @@
+"""This is a test"""
+
+from __future__ import nested_scopes, braces
+
+def f(x):
+    def g(y):
+        return x + y
+    return g
+
+print f(2)(4)
diff --git a/Lib/test/output/test_future b/Lib/test/output/test_future
deleted file mode 100644 (file)
index 4631489..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-test_future
-6
-6
-SyntaxError badsyntax_future3 3
-SyntaxError badsyntax_future4 3
-SyntaxError badsyntax_future5 4
-SyntaxError badsyntax_future6 3
-SyntaxError badsyntax_future7 3
index 12813d4b446df6cd027b671f7f49447b2dd7ad6a..f5462e204d637c73541232226f89145c6f329871 100644 (file)
@@ -1,47 +1,89 @@
 # Test various flavors of legal and illegal future statements
 
-from test.test_support import unload
+import unittest
+from test import test_support
 import re
 
 rx = re.compile('\((\S+).py, line (\d+)')
 
-def check_error_location(msg):
-    mo = rx.search(msg)
-    print "SyntaxError %s %s" % mo.group(1, 2)
+def get_error_location(msg):
+    mo = rx.search(str(msg))
+    return mo.group(1, 2)
 
-# The first two tests should work
+class FutureTest(unittest.TestCase):
 
-unload('test_future1')
-from test import test_future1
+    def test_future1(self):
+        test_support.unload('test_future1')
+        from test import test_future1
+        self.assertEqual(test_future1.result, 6)
 
-unload('test_future2')
-from test import test_future2
+    def test_future2(self):
+        test_support.unload('test_future2')
+        from test import test_future2
+        self.assertEqual(test_future2.result, 6)
 
-unload('test_future3')
-from test import test_future3
+    def test_future3(self):
+        test_support.unload('test_future3')
+        from test import test_future3
 
-# The remaining tests should fail
-try:
-    from test import badsyntax_future3
-except SyntaxError, msg:
-    check_error_location(str(msg))
+    def test_badfuture3(self):
+        try:
+            from test import badsyntax_future3
+        except SyntaxError, msg:
+            self.assertEqual(get_error_location(msg), ("badsyntax_future3", '3'))
+        else:
+            self.fail("expected exception didn't occur")
 
-try:
-    from test import badsyntax_future4
-except SyntaxError, msg:
-    check_error_location(str(msg))
+    def test_badfuture4(self):
+        try:
+            from test import badsyntax_future4
+        except SyntaxError, msg:
+            self.assertEqual(get_error_location(msg), ("badsyntax_future4", '3'))
+        else:
+            self.fail("expected exception didn't occur")
 
-try:
-    from test import badsyntax_future5
-except SyntaxError, msg:
-    check_error_location(str(msg))
+    def test_badfuture5(self):
+        try:
+            from test import badsyntax_future5
+        except SyntaxError, msg:
+            self.assertEqual(get_error_location(msg), ("badsyntax_future5", '4'))
+        else:
+            self.fail("expected exception didn't occur")
 
-try:
-    from test import badsyntax_future6
-except SyntaxError, msg:
-    check_error_location(str(msg))
+    def test_badfuture6(self):
+        try:
+            from test import badsyntax_future6
+        except SyntaxError, msg:
+            self.assertEqual(get_error_location(msg), ("badsyntax_future6", '3'))
+        else:
+            self.fail("expected exception didn't occur")
 
-try:
-    from test import badsyntax_future7
-except SyntaxError, msg:
-    check_error_location(str(msg))
+    def test_badfuture7(self):
+        try:
+            from test import badsyntax_future7
+        except SyntaxError, msg:
+            self.assertEqual(get_error_location(msg), ("badsyntax_future7", '3'))
+        else:
+            self.fail("expected exception didn't occur")
+
+    def test_badfuture8(self):
+        try:
+            from test import badsyntax_future8
+        except SyntaxError, msg:
+            self.assertEqual(get_error_location(msg), ("badsyntax_future8", '3'))
+        else:
+            self.fail("expected exception didn't occur")
+
+    def test_badfuture9(self):
+        try:
+            from test import badsyntax_future9
+        except SyntaxError, msg:
+            self.assertEqual(get_error_location(msg), ("badsyntax_future9", '3'))
+        else:
+            self.fail("expected exception didn't occur")
+
+def test_main():
+    test_support.run_unittest(FutureTest)
+
+if __name__ == "__main__":
+    test_main()
index b0d2a5c12ea8e28bde64c86cb7ecac22efbf7610..297c2e087c2e8d93864e9700f03dd38de12f45c6 100644 (file)
@@ -8,4 +8,4 @@ def f(x):
         return x + y
     return g
 
-print f(2)(4)
+result = f(2)(4)
index e3df0a6d53a1106ff5790ccc154ba14b7b6a3baf..79eb73179de1ecc43d4cd4e365ce586d7668d1f1 100644 (file)
@@ -7,4 +7,4 @@ def f(x):
         return x + y
     return g
 
-print f(2)(4)
+result = f(2)(4)