blob: f5462e204d637c73541232226f89145c6f329871 [file] [log] [blame]
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +00001# Test various flavors of legal and illegal future statements
2
Neal Norwitz328f3382003-12-13 22:43:34 +00003import unittest
4from test import test_support
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +00005import re
6
7rx = re.compile('\((\S+).py, line (\d+)')
8
Neal Norwitz328f3382003-12-13 22:43:34 +00009def get_error_location(msg):
10 mo = rx.search(str(msg))
11 return mo.group(1, 2)
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +000012
Neal Norwitz328f3382003-12-13 22:43:34 +000013class FutureTest(unittest.TestCase):
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +000014
Neal Norwitz328f3382003-12-13 22:43:34 +000015 def test_future1(self):
16 test_support.unload('test_future1')
17 from test import test_future1
18 self.assertEqual(test_future1.result, 6)
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +000019
Neal Norwitz328f3382003-12-13 22:43:34 +000020 def test_future2(self):
21 test_support.unload('test_future2')
22 from test import test_future2
23 self.assertEqual(test_future2.result, 6)
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +000024
Neal Norwitz328f3382003-12-13 22:43:34 +000025 def test_future3(self):
26 test_support.unload('test_future3')
27 from test import test_future3
Jeremy Hylton8471a352001-08-20 20:33:42 +000028
Neal Norwitz328f3382003-12-13 22:43:34 +000029 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")
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +000036
Neal Norwitz328f3382003-12-13 22:43:34 +000037 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")
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +000044
Neal Norwitz328f3382003-12-13 22:43:34 +000045 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")
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +000052
Neal Norwitz328f3382003-12-13 22:43:34 +000053 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")
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +000060
Neal Norwitz328f3382003-12-13 22:43:34 +000061 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
85def test_main():
86 test_support.run_unittest(FutureTest)
87
88if __name__ == "__main__":
89 test_main()