annotate Lib/test/test_future.py @ 71285:8bc9dbc61ba6 3.2

Issue #12326: document the recommended idiom for checking sys.platform on Unix systems. Also, point to the various alternatives.
author Antoine Pitrou <solipsis@pitrou.net>
date Sat, 09 Jul 2011 15:54:23 +0200
parents 71acd4482e65
children 6a649a15cd14
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
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 40587
diff changeset
4 from test import 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):
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 40587
diff changeset
16 support.unload('test_future1')
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
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):
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 40587
diff changeset
21 support.unload('test_future2')
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
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):
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 40587
diff changeset
26 support.unload('test_future3')
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
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
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
32 except SyntaxError as msg:
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
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
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
40 except SyntaxError as msg:
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
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
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
48 except SyntaxError as msg:
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
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
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
56 except SyntaxError as msg:
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
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
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
64 except SyntaxError as msg:
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
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
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
72 except SyntaxError as msg:
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
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
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
80 except SyntaxError as msg:
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
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
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
85 def test_parserhack(self):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
86 # test that the parser.c::future_hack function works as expected
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
87 # Note: although this test must pass, it's not testing the original
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
88 # bug as of 2.6 since the with statement is not optional and
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
89 # the parser hack disabled. If a new keyword is introduced in
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
90 # 2.6, change this to refer to the new future import.
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
91 try:
49594
30c0b266af06 Merged revisions 67030-67031 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
92 exec("from __future__ import print_function; print 0")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
93 except SyntaxError:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
94 pass
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
95 else:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
96 self.fail("syntax error didn't occur")
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
97
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
98 try:
49594
30c0b266af06 Merged revisions 67030-67031 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
99 exec("from __future__ import (print_function); print 0")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
100 except SyntaxError:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
101 pass
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
102 else:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
103 self.fail("syntax error didn't occur")
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
104
49594
30c0b266af06 Merged revisions 67030-67031 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
105 def test_multiple_features(self):
30c0b266af06 Merged revisions 67030-67031 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
106 support.unload("test.test_future5")
30c0b266af06 Merged revisions 67030-67031 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
107 from test import test_future5
30c0b266af06 Merged revisions 67030-67031 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
108
49624
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49594
diff changeset
109 def test_unicode_literals_exec(self):
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49594
diff changeset
110 scope = {}
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49594
diff changeset
111 exec("from __future__ import unicode_literals; x = ''", {}, scope)
58473
71acd4482e65 Merged revisions 77727 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 49624
diff changeset
112 self.assertIsInstance(scope["x"], str)
49624
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49594
diff changeset
113
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 31184
diff changeset
114
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
115 def test_main():
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 40587
diff changeset
116 support.run_unittest(FutureTest)
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
117
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
118 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
119 test_main()