Skip to content

Commit 1499607

Browse files
committed
Add test_flufl.py
1 parent 0dd14d0 commit 1499607

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lib/test/test_flufl.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import __future__
2+
import unittest
3+
4+
5+
class FLUFLTests(unittest.TestCase):
6+
7+
@unittest.expectedFailure # TODO: RUSTPYTHON
8+
def test_barry_as_bdfl(self):
9+
code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
10+
compile(code.format('<>'), '<BDFL test>', 'exec',
11+
__future__.CO_FUTURE_BARRY_AS_BDFL)
12+
with self.assertRaises(SyntaxError) as cm:
13+
compile(code.format('!='), '<FLUFL test>', 'exec',
14+
__future__.CO_FUTURE_BARRY_AS_BDFL)
15+
self.assertRegex(str(cm.exception),
16+
"with Barry as BDFL, use '<>' instead of '!='")
17+
self.assertIn('2 != 3', cm.exception.text)
18+
self.assertEqual(cm.exception.filename, '<FLUFL test>')
19+
20+
self.assertEqual(cm.exception.lineno, 2)
21+
# The old parser reports the end of the token and the new
22+
# parser reports the start of the token
23+
self.assertEqual(cm.exception.offset, 3)
24+
25+
@unittest.expectedFailure # TODO: RUSTPYTHON
26+
def test_guido_as_bdfl(self):
27+
code = '2 {0} 3'
28+
compile(code.format('!='), '<BDFL test>', 'exec')
29+
with self.assertRaises(SyntaxError) as cm:
30+
compile(code.format('<>'), '<FLUFL test>', 'exec')
31+
self.assertRegex(str(cm.exception), "invalid syntax")
32+
self.assertIn('2 <> 3', cm.exception.text)
33+
self.assertEqual(cm.exception.filename, '<FLUFL test>')
34+
self.assertEqual(cm.exception.lineno, 1)
35+
# The old parser reports the end of the token and the new
36+
# parser reports the start of the token
37+
self.assertEqual(cm.exception.offset, 3)
38+
39+
@unittest.expectedFailure # TODO: RUSTPYTHON
40+
def test_barry_as_bdfl_look_ma_with_no_compiler_flags(self):
41+
# Check that the future import is handled by the parser
42+
# even if the compiler flags are not passed.
43+
code = "from __future__ import barry_as_FLUFL;2 {0} 3"
44+
compile(code.format('<>'), '<BDFL test>', 'exec')
45+
with self.assertRaises(SyntaxError) as cm:
46+
compile(code.format('!='), '<FLUFL test>', 'exec')
47+
self.assertRegex(str(cm.exception), "with Barry as BDFL, use '<>' instead of '!='")
48+
self.assertIn('2 != 3', cm.exception.text)
49+
self.assertEqual(cm.exception.filename, '<FLUFL test>')
50+
self.assertEqual(cm.exception.lineno, 1)
51+
self.assertEqual(cm.exception.offset, len(code) - 4)
52+
53+
@unittest.expectedFailure # TODO: RUSTPYTHON
54+
def test_barry_as_bdfl_relative_import(self):
55+
code = "from .__future__ import barry_as_FLUFL;2 {0} 3"
56+
compile(code.format('!='), '<FLUFL test>', 'exec')
57+
with self.assertRaises(SyntaxError) as cm:
58+
compile(code.format('<>'), '<BDFL test>', 'exec')
59+
self.assertRegex(str(cm.exception), "<BDFL test>")
60+
self.assertIn('2 <> 3', cm.exception.text)
61+
self.assertEqual(cm.exception.filename, '<BDFL test>')
62+
self.assertEqual(cm.exception.lineno, 1)
63+
self.assertEqual(cm.exception.offset, len(code) - 4)
64+
65+
66+
67+
68+
if __name__ == '__main__':
69+
unittest.main()

0 commit comments

Comments
 (0)