]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/test/test_future.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / test / test_future.py
CommitLineData
4710c53d 1# Test various flavors of legal and illegal future statements\r
2\r
3import unittest\r
4from test import test_support\r
5import re\r
6\r
7rx = re.compile('\((\S+).py, line (\d+)')\r
8\r
9def get_error_location(msg):\r
10 mo = rx.search(str(msg))\r
11 return mo.group(1, 2)\r
12\r
13class FutureTest(unittest.TestCase):\r
14\r
15 def test_future1(self):\r
16 test_support.unload('test_future1')\r
17 from test import test_future1\r
18 self.assertEqual(test_future1.result, 6)\r
19\r
20 def test_future2(self):\r
21 test_support.unload('test_future2')\r
22 from test import test_future2\r
23 self.assertEqual(test_future2.result, 6)\r
24\r
25 def test_future3(self):\r
26 test_support.unload('test_future3')\r
27 from test import test_future3\r
28\r
29 def test_badfuture3(self):\r
30 try:\r
31 from test import badsyntax_future3\r
32 except SyntaxError, msg:\r
33 self.assertEqual(get_error_location(msg), ("badsyntax_future3", '3'))\r
34 else:\r
35 self.fail("expected exception didn't occur")\r
36\r
37 def test_badfuture4(self):\r
38 try:\r
39 from test import badsyntax_future4\r
40 except SyntaxError, msg:\r
41 self.assertEqual(get_error_location(msg), ("badsyntax_future4", '3'))\r
42 else:\r
43 self.fail("expected exception didn't occur")\r
44\r
45 def test_badfuture5(self):\r
46 try:\r
47 from test import badsyntax_future5\r
48 except SyntaxError, msg:\r
49 self.assertEqual(get_error_location(msg), ("badsyntax_future5", '4'))\r
50 else:\r
51 self.fail("expected exception didn't occur")\r
52\r
53 def test_badfuture6(self):\r
54 try:\r
55 from test import badsyntax_future6\r
56 except SyntaxError, msg:\r
57 self.assertEqual(get_error_location(msg), ("badsyntax_future6", '3'))\r
58 else:\r
59 self.fail("expected exception didn't occur")\r
60\r
61 def test_badfuture7(self):\r
62 try:\r
63 from test import badsyntax_future7\r
64 except SyntaxError, msg:\r
65 self.assertEqual(get_error_location(msg), ("badsyntax_future7", '3'))\r
66 else:\r
67 self.fail("expected exception didn't occur")\r
68\r
69 def test_badfuture8(self):\r
70 try:\r
71 from test import badsyntax_future8\r
72 except SyntaxError, msg:\r
73 self.assertEqual(get_error_location(msg), ("badsyntax_future8", '3'))\r
74 else:\r
75 self.fail("expected exception didn't occur")\r
76\r
77 def test_badfuture9(self):\r
78 try:\r
79 from test import badsyntax_future9\r
80 except SyntaxError, msg:\r
81 self.assertEqual(get_error_location(msg), ("badsyntax_future9", '3'))\r
82 else:\r
83 self.fail("expected exception didn't occur")\r
84\r
85 def test_parserhack(self):\r
86 # test that the parser.c::future_hack function works as expected\r
87 # Note: although this test must pass, it's not testing the original\r
88 # bug as of 2.6 since the with statement is not optional and\r
89 # the parser hack disabled. If a new keyword is introduced in\r
90 # 2.6, change this to refer to the new future import.\r
91 try:\r
92 exec "from __future__ import print_function; print 0"\r
93 except SyntaxError:\r
94 pass\r
95 else:\r
96 self.fail("syntax error didn't occur")\r
97\r
98 try:\r
99 exec "from __future__ import (print_function); print 0"\r
100 except SyntaxError:\r
101 pass\r
102 else:\r
103 self.fail("syntax error didn't occur")\r
104\r
105 def test_multiple_features(self):\r
106 test_support.unload("test.test_future5")\r
107 from test import test_future5\r
108\r
109 def test_unicode_literals_exec(self):\r
110 scope = {}\r
111 exec "from __future__ import unicode_literals; x = ''" in scope\r
112 self.assertIsInstance(scope["x"], unicode)\r
113\r
114\r
115def test_main():\r
116 test_support.run_unittest(FutureTest)\r
117\r
118if __name__ == "__main__":\r
119 test_main()\r