annotate Lib/test/test_future.py @ 49258:25f809123df6 legacy-trunk

Issue #3925: Ignores shutil.rmtree error on cygwin too. Reviewed by Benjamin Peterson.
author Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
date Sun, 21 Sep 2008 20:48:41 +0000
parents 25bcdf3cd194
children e80d9e6e26bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16839
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1 # Test various flavors of legal and illegal future statements
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
3 import unittest
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
4 from test import test_support
16839
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
5 import re
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
6
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
7 rx = re.compile('\((\S+).py, line (\d+)')
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
8
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
9 def get_error_location(msg):
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
10 mo = rx.search(str(msg))
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
11 return mo.group(1, 2)
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
12
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
13 class FutureTest(unittest.TestCase):
16839
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
14
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
15 def test_future1(self):
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
16 test_support.unload('test_future1')
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
17 from test import test_future1
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
18 self.assertEqual(test_future1.result, 6)
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
19
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
20 def test_future2(self):
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
21 test_support.unload('test_future2')
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
22 from test import test_future2
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
23 self.assertEqual(test_future2.result, 6)
16839
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
24
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
25 def test_future3(self):
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
26 test_support.unload('test_future3')
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
27 from test import test_future3
16839
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
28
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
29 def test_badfuture3(self):
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
30 try:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
31 from test import badsyntax_future3
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
32 except SyntaxError, msg:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
33 self.assertEqual(get_error_location(msg), ("badsyntax_future3", '3'))
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
34 else:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
35 self.fail("expected exception didn't occur")
16839
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
36
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
37 def test_badfuture4(self):
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
38 try:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
39 from test import badsyntax_future4
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
40 except SyntaxError, msg:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
41 self.assertEqual(get_error_location(msg), ("badsyntax_future4", '3'))
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
42 else:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
43 self.fail("expected exception didn't occur")
19408
7e5e974b3d37 Fix SF bug [ #450245 ] Error in parsing future stmts
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17558
diff changeset
44
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
45 def test_badfuture5(self):
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
46 try:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
47 from test import badsyntax_future5
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
48 except SyntaxError, msg:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
49 self.assertEqual(get_error_location(msg), ("badsyntax_future5", '4'))
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
50 else:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
51 self.fail("expected exception didn't occur")
16839
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
52
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
53 def test_badfuture6(self):
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
54 try:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
55 from test import badsyntax_future6
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
56 except SyntaxError, msg:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
57 self.assertEqual(get_error_location(msg), ("badsyntax_future6", '3'))
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
58 else:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
59 self.fail("expected exception didn't occur")
16839
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
60
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
61 def test_badfuture7(self):
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
62 try:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
63 from test import badsyntax_future7
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
64 except SyntaxError, msg:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
65 self.assertEqual(get_error_location(msg), ("badsyntax_future7", '3'))
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
66 else:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
67 self.fail("expected exception didn't occur")
16839
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
68
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
69 def test_badfuture8(self):
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
70 try:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
71 from test import badsyntax_future8
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
72 except SyntaxError, msg:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
73 self.assertEqual(get_error_location(msg), ("badsyntax_future8", '3'))
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
74 else:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
75 self.fail("expected exception didn't occur")
16839
e1b1e68cbd8c Add regression test for future statements. This adds eight files, but
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
76
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
77 def test_badfuture9(self):
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
78 try:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
79 from test import badsyntax_future9
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
80 except SyntaxError, msg:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
81 self.assertEqual(get_error_location(msg), ("badsyntax_future9", '3'))
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
82 else:
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
83 self.fail("expected exception didn't occur")
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
84
39881
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
85 def test_parserhack(self):
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
86 # test that the parser.c::future_hack function works as expected
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
87 # Note: although this test must pass, it's not testing the original
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
88 # bug as of 2.6 since the with statement is not optional and
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
89 # the parser hack disabled. If a new keyword is introduced in
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
90 # 2.6, change this to refer to the new future import.
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
91 try:
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
92 exec "from __future__ import division, with_statement; with = 0"
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
93 except SyntaxError:
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
94 pass
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
95 else:
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
96 self.fail("syntax error didn't occur")
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
97
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
98 try:
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
99 exec "from __future__ import (with_statement, division); with = 0"
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
100 except SyntaxError:
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
101 pass
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
102 else:
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
103 self.fail("syntax error didn't occur")
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
104
25bcdf3cd194 Fix a bug in the parser's future statement handling that led to "with"
Georg Brandl <georg@python.org>
parents: 31184
diff changeset
105
31184
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
106 def test_main():
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
107 test_support.run_unittest(FutureTest)
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
108
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
109 if __name__ == "__main__":
47eaa38b29cb SF #736962, port test_future to unittest, add a bit more coverage, by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents: 24442
diff changeset
110 test_main()