SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
This commit is contained in:
parent
378f7b5dca
commit
328f338196
@ -7,4 +7,4 @@ def f(x):
|
|||||||
return x + y
|
return x + y
|
||||||
return g
|
return g
|
||||||
|
|
||||||
print f(2)(4)
|
result = f(2)(4)
|
||||||
|
@ -7,4 +7,4 @@ def f(x):
|
|||||||
return x + y
|
return x + y
|
||||||
return g
|
return g
|
||||||
|
|
||||||
print f(2)(4)
|
result = f(2)(4)
|
||||||
|
@ -9,4 +9,4 @@ def f(x):
|
|||||||
return x + y
|
return x + y
|
||||||
return g
|
return g
|
||||||
|
|
||||||
print f(2)(4)
|
result = f(2)(4)
|
||||||
|
@ -7,4 +7,4 @@ def f(x):
|
|||||||
return x + y
|
return x + y
|
||||||
return g
|
return g
|
||||||
|
|
||||||
print f(2)(4)
|
result = f(2)(4)
|
||||||
|
@ -8,4 +8,4 @@ def f(x):
|
|||||||
return x + y
|
return x + y
|
||||||
return g
|
return g
|
||||||
|
|
||||||
print f(2)(4)
|
result = f(2)(4)
|
||||||
|
10
Lib/test/badsyntax_future8.py
Normal file
10
Lib/test/badsyntax_future8.py
Normal file
@ -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)
|
10
Lib/test/badsyntax_future9.py
Normal file
10
Lib/test/badsyntax_future9.py
Normal file
@ -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)
|
@ -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
|
|
@ -1,47 +1,89 @@
|
|||||||
# Test various flavors of legal and illegal future statements
|
# Test various flavors of legal and illegal future statements
|
||||||
|
|
||||||
from test.test_support import unload
|
import unittest
|
||||||
|
from test import test_support
|
||||||
import re
|
import re
|
||||||
|
|
||||||
rx = re.compile('\((\S+).py, line (\d+)')
|
rx = re.compile('\((\S+).py, line (\d+)')
|
||||||
|
|
||||||
def check_error_location(msg):
|
def get_error_location(msg):
|
||||||
mo = rx.search(msg)
|
mo = rx.search(str(msg))
|
||||||
print "SyntaxError %s %s" % mo.group(1, 2)
|
return mo.group(1, 2)
|
||||||
|
|
||||||
# The first two tests should work
|
class FutureTest(unittest.TestCase):
|
||||||
|
|
||||||
unload('test_future1')
|
def test_future1(self):
|
||||||
from test import test_future1
|
test_support.unload('test_future1')
|
||||||
|
from test import test_future1
|
||||||
|
self.assertEqual(test_future1.result, 6)
|
||||||
|
|
||||||
unload('test_future2')
|
def test_future2(self):
|
||||||
from test import test_future2
|
test_support.unload('test_future2')
|
||||||
|
from test import test_future2
|
||||||
|
self.assertEqual(test_future2.result, 6)
|
||||||
|
|
||||||
unload('test_future3')
|
def test_future3(self):
|
||||||
from test import test_future3
|
test_support.unload('test_future3')
|
||||||
|
from test import test_future3
|
||||||
|
|
||||||
# The remaining tests should fail
|
def test_badfuture3(self):
|
||||||
try:
|
try:
|
||||||
from test import badsyntax_future3
|
from test import badsyntax_future3
|
||||||
except SyntaxError, msg:
|
except SyntaxError, msg:
|
||||||
check_error_location(str(msg))
|
self.assertEqual(get_error_location(msg), ("badsyntax_future3", '3'))
|
||||||
|
else:
|
||||||
|
self.fail("expected exception didn't occur")
|
||||||
|
|
||||||
try:
|
def test_badfuture4(self):
|
||||||
from test import badsyntax_future4
|
try:
|
||||||
except SyntaxError, msg:
|
from test import badsyntax_future4
|
||||||
check_error_location(str(msg))
|
except SyntaxError, msg:
|
||||||
|
self.assertEqual(get_error_location(msg), ("badsyntax_future4", '3'))
|
||||||
|
else:
|
||||||
|
self.fail("expected exception didn't occur")
|
||||||
|
|
||||||
try:
|
def test_badfuture5(self):
|
||||||
from test import badsyntax_future5
|
try:
|
||||||
except SyntaxError, msg:
|
from test import badsyntax_future5
|
||||||
check_error_location(str(msg))
|
except SyntaxError, msg:
|
||||||
|
self.assertEqual(get_error_location(msg), ("badsyntax_future5", '4'))
|
||||||
|
else:
|
||||||
|
self.fail("expected exception didn't occur")
|
||||||
|
|
||||||
try:
|
def test_badfuture6(self):
|
||||||
from test import badsyntax_future6
|
try:
|
||||||
except SyntaxError, msg:
|
from test import badsyntax_future6
|
||||||
check_error_location(str(msg))
|
except SyntaxError, msg:
|
||||||
|
self.assertEqual(get_error_location(msg), ("badsyntax_future6", '3'))
|
||||||
|
else:
|
||||||
|
self.fail("expected exception didn't occur")
|
||||||
|
|
||||||
try:
|
def test_badfuture7(self):
|
||||||
from test import badsyntax_future7
|
try:
|
||||||
except SyntaxError, msg:
|
from test import badsyntax_future7
|
||||||
check_error_location(str(msg))
|
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()
|
||||||
|
@ -8,4 +8,4 @@ def f(x):
|
|||||||
return x + y
|
return x + y
|
||||||
return g
|
return g
|
||||||
|
|
||||||
print f(2)(4)
|
result = f(2)(4)
|
||||||
|
@ -7,4 +7,4 @@ def f(x):
|
|||||||
return x + y
|
return x + y
|
||||||
return g
|
return g
|
||||||
|
|
||||||
print f(2)(4)
|
result = f(2)(4)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user