Skip to content

Commit 973e6cf

Browse files
author
nnorwitz
committed
SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
git-svn-id: http://svn.python.org/projects/python/trunk@34908 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent b141561 commit 973e6cf

11 files changed

Lines changed: 101 additions & 47 deletions

Lib/test/badsyntax_future3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ def g(y):
77
return x + y
88
return g
99

10-
print f(2)(4)
10+
result = f(2)(4)

Lib/test/badsyntax_future4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ def g(y):
77
return x + y
88
return g
99

10-
print f(2)(4)
10+
result = f(2)(4)

Lib/test/badsyntax_future5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ def g(y):
99
return x + y
1010
return g
1111

12-
print f(2)(4)
12+
result = f(2)(4)

Lib/test/badsyntax_future6.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ def g(y):
77
return x + y
88
return g
99

10-
print f(2)(4)
10+
result = f(2)(4)

Lib/test/badsyntax_future7.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ def g(y):
88
return x + y
99
return g
1010

11-
print f(2)(4)
11+
result = f(2)(4)

Lib/test/badsyntax_future8.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""This is a test"""
2+
3+
from __future__ import *
4+
5+
def f(x):
6+
def g(y):
7+
return x + y
8+
return g
9+
10+
print f(2)(4)

Lib/test/badsyntax_future9.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""This is a test"""
2+
3+
from __future__ import nested_scopes, braces
4+
5+
def f(x):
6+
def g(y):
7+
return x + y
8+
return g
9+
10+
print f(2)(4)

Lib/test/output/test_future

Lines changed: 0 additions & 8 deletions
This file was deleted.

Lib/test/test_future.py

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,89 @@
11
# Test various flavors of legal and illegal future statements
22

3-
from test.test_support import unload
3+
import unittest
4+
from test import test_support
45
import re
56

67
rx = re.compile('\((\S+).py, line (\d+)')
78

8-
def check_error_location(msg):
9-
mo = rx.search(msg)
10-
print "SyntaxError %s %s" % mo.group(1, 2)
9+
def get_error_location(msg):
10+
mo = rx.search(str(msg))
11+
return mo.group(1, 2)
1112

12-
# The first two tests should work
13+
class FutureTest(unittest.TestCase):
1314

14-
unload('test_future1')
15-
from test import test_future1
15+
def test_future1(self):
16+
test_support.unload('test_future1')
17+
from test import test_future1
18+
self.assertEqual(test_future1.result, 6)
1619

17-
unload('test_future2')
18-
from test import test_future2
20+
def test_future2(self):
21+
test_support.unload('test_future2')
22+
from test import test_future2
23+
self.assertEqual(test_future2.result, 6)
1924

20-
unload('test_future3')
21-
from test import test_future3
25+
def test_future3(self):
26+
test_support.unload('test_future3')
27+
from test import test_future3
2228

23-
# The remaining tests should fail
24-
try:
25-
from test import badsyntax_future3
26-
except SyntaxError, msg:
27-
check_error_location(str(msg))
29+
def test_badfuture3(self):
30+
try:
31+
from test import badsyntax_future3
32+
except SyntaxError, msg:
33+
self.assertEqual(get_error_location(msg), ("badsyntax_future3", '3'))
34+
else:
35+
self.fail("expected exception didn't occur")
2836

29-
try:
30-
from test import badsyntax_future4
31-
except SyntaxError, msg:
32-
check_error_location(str(msg))
37+
def test_badfuture4(self):
38+
try:
39+
from test import badsyntax_future4
40+
except SyntaxError, msg:
41+
self.assertEqual(get_error_location(msg), ("badsyntax_future4", '3'))
42+
else:
43+
self.fail("expected exception didn't occur")
3344

34-
try:
35-
from test import badsyntax_future5
36-
except SyntaxError, msg:
37-
check_error_location(str(msg))
45+
def test_badfuture5(self):
46+
try:
47+
from test import badsyntax_future5
48+
except SyntaxError, msg:
49+
self.assertEqual(get_error_location(msg), ("badsyntax_future5", '4'))
50+
else:
51+
self.fail("expected exception didn't occur")
3852

39-
try:
40-
from test import badsyntax_future6
41-
except SyntaxError, msg:
42-
check_error_location(str(msg))
53+
def test_badfuture6(self):
54+
try:
55+
from test import badsyntax_future6
56+
except SyntaxError, msg:
57+
self.assertEqual(get_error_location(msg), ("badsyntax_future6", '3'))
58+
else:
59+
self.fail("expected exception didn't occur")
4360

44-
try:
45-
from test import badsyntax_future7
46-
except SyntaxError, msg:
47-
check_error_location(str(msg))
61+
def test_badfuture7(self):
62+
try:
63+
from test import badsyntax_future7
64+
except SyntaxError, msg:
65+
self.assertEqual(get_error_location(msg), ("badsyntax_future7", '3'))
66+
else:
67+
self.fail("expected exception didn't occur")
68+
69+
def test_badfuture8(self):
70+
try:
71+
from test import badsyntax_future8
72+
except SyntaxError, msg:
73+
self.assertEqual(get_error_location(msg), ("badsyntax_future8", '3'))
74+
else:
75+
self.fail("expected exception didn't occur")
76+
77+
def test_badfuture9(self):
78+
try:
79+
from test import badsyntax_future9
80+
except SyntaxError, msg:
81+
self.assertEqual(get_error_location(msg), ("badsyntax_future9", '3'))
82+
else:
83+
self.fail("expected exception didn't occur")
84+
85+
def test_main():
86+
test_support.run_unittest(FutureTest)
87+
88+
if __name__ == "__main__":
89+
test_main()

Lib/test/test_future1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ def g(y):
88
return x + y
99
return g
1010

11-
print f(2)(4)
11+
result = f(2)(4)

0 commit comments

Comments
 (0)