0001 # Test various flavors of legal and illegal future statements 0002 0003 import unittest 0004 from test import test_support 0005 import re 0006 0007 rx = re.compile('\((\S+).py, line (\d+)') 0008 0009 def get_error_location(msg): 0010 mo = rx.search(str(msg)) 0011 return mo.group(1, 2) 0012 0013 class FutureTest(unittest.TestCase): 0014 0015 def test_future1(self): 0016 test_support.unload('test_future1') 0017 from test import test_future1 0018 self.assertEqual(test_future1.result, 6) 0019 0020 def test_future2(self): 0021 test_support.unload('test_future2') 0022 from test import test_future2 0023 self.assertEqual(test_future2.result, 6) 0024 0025 def test_future3(self): 0026 test_support.unload('test_future3') 0027 from test import test_future3 0028 0029 def test_badfuture3(self): 0030 try: 0031 from test import badsyntax_future3 0032 except SyntaxError, msg: 0033 self.assertEqual(get_error_location(msg), ("badsyntax_future3", '3')) 0034 else: 0035 self.fail("expected exception didn't occur") 0036 0037 def test_badfuture4(self): 0038 try: 0039 from test import badsyntax_future4 0040 except SyntaxError, msg: 0041 self.assertEqual(get_error_location(msg), ("badsyntax_future4", '3')) 0042 else: 0043 self.fail("expected exception didn't occur") 0044 0045 def test_badfuture5(self): 0046 try: 0047 from test import badsyntax_future5 0048 except SyntaxError, msg: 0049 self.assertEqual(get_error_location(msg), ("badsyntax_future5", '4')) 0050 else: 0051 self.fail("expected exception didn't occur") 0052 0053 def test_badfuture6(self): 0054 try: 0055 from test import badsyntax_future6 0056 except SyntaxError, msg: 0057 self.assertEqual(get_error_location(msg), ("badsyntax_future6", '3')) 0058 else: 0059 self.fail("expected exception didn't occur") 0060 0061 def test_badfuture7(self): 0062 try: 0063 from test import badsyntax_future7 0064 except SyntaxError, msg: 0065 self.assertEqual(get_error_location(msg), ("badsyntax_future7", '3')) 0066 else: 0067 self.fail("expected exception didn't occur") 0068 0069 def test_badfuture8(self): 0070 try: 0071 from test import badsyntax_future8 0072 except SyntaxError, msg: 0073 self.assertEqual(get_error_location(msg), ("badsyntax_future8", '3')) 0074 else: 0075 self.fail("expected exception didn't occur") 0076 0077 def test_badfuture9(self): 0078 try: 0079 from test import badsyntax_future9 0080 except SyntaxError, msg: 0081 self.assertEqual(get_error_location(msg), ("badsyntax_future9", '3')) 0082 else: 0083 self.fail("expected exception didn't occur") 0084 0085 def test_main(): 0086 test_support.run_unittest(FutureTest) 0087 0088 if __name__ == "__main__": 0089 test_main() 0090
Generated by PyXR 0.9.4