blob: 297a8aa90c96c9f7daa75e6fe0ceb7dac010b3f2 [file] [log] [blame]
Brett Cannone3944a52009-04-01 05:08:41 +00001import __future__
2import unittest
Pablo Galindoc5fc1562020-04-22 23:29:27 +01003import sys
Brett Cannone3944a52009-04-01 05:08:41 +00004
Pablo Galindoc5fc1562020-04-22 23:29:27 +01005
6@unittest.skipIf(sys.flags.use_peg, "Not supported by pegen yet")
Brett Cannone3944a52009-04-01 05:08:41 +00007class FLUFLTests(unittest.TestCase):
8
9 def test_barry_as_bdfl(self):
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030010 code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
Brett Cannone3944a52009-04-01 05:08:41 +000011 compile(code.format('<>'), '<BDFL test>', 'exec',
12 __future__.CO_FUTURE_BARRY_AS_BDFL)
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030013 with self.assertRaises(SyntaxError) as cm:
14 compile(code.format('!='), '<FLUFL test>', 'exec',
15 __future__.CO_FUTURE_BARRY_AS_BDFL)
16 self.assertRegex(str(cm.exception),
17 "with Barry as BDFL, use '<>' instead of '!='")
18 self.assertEqual(cm.exception.text, '2 != 3\n')
19 self.assertEqual(cm.exception.filename, '<FLUFL test>')
20 self.assertEqual(cm.exception.lineno, 2)
21 self.assertEqual(cm.exception.offset, 4)
Brett Cannone3944a52009-04-01 05:08:41 +000022
23 def test_guido_as_bdfl(self):
24 code = '2 {0} 3'
25 compile(code.format('!='), '<BDFL test>', 'exec')
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030026 with self.assertRaises(SyntaxError) as cm:
27 compile(code.format('<>'), '<FLUFL test>', 'exec')
28 self.assertRegex(str(cm.exception), "invalid syntax")
29 self.assertEqual(cm.exception.text, '2 <> 3\n')
30 self.assertEqual(cm.exception.filename, '<FLUFL test>')
31 self.assertEqual(cm.exception.lineno, 1)
32 self.assertEqual(cm.exception.offset, 4)
Brett Cannone3944a52009-04-01 05:08:41 +000033
34
Brett Cannone3944a52009-04-01 05:08:41 +000035if __name__ == '__main__':
Zachary Ware38c707e2015-04-13 15:00:43 -050036 unittest.main()