blob: b71442804c72baa5f96de3317427e9e0fc2ff4b2 [file] [log] [blame]
Brett Cannone3944a52009-04-01 05:08:41 +00001import __future__
2import unittest
Pablo Galindoc5fc1562020-04-22 23:29:27 +01003import sys
Victor Stinner1def7752020-04-23 03:03:24 +02004from test import support
Brett Cannone3944a52009-04-01 05:08:41 +00005
Pablo Galindoc5fc1562020-04-22 23:29:27 +01006
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 '!='")
Pablo Galindo2b74c832020-04-27 18:02:07 +010018 self.assertIn('2 != 3', cm.exception.text)
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030019 self.assertEqual(cm.exception.filename, '<FLUFL test>')
Pablo Galindo2b74c832020-04-27 18:02:07 +010020
21 self.assertTrue(cm.exception.lineno, 2)
22 # The old parser reports the end of the token and the new
23 # parser reports the start of the token
24 self.assertEqual(cm.exception.offset, 4 if support.use_old_parser() else 3)
Brett Cannone3944a52009-04-01 05:08:41 +000025
26 def test_guido_as_bdfl(self):
27 code = '2 {0} 3'
28 compile(code.format('!='), '<BDFL test>', 'exec')
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030029 with self.assertRaises(SyntaxError) as cm:
30 compile(code.format('<>'), '<FLUFL test>', 'exec')
31 self.assertRegex(str(cm.exception), "invalid syntax")
Pablo Galindo2b74c832020-04-27 18:02:07 +010032 self.assertIn('2 <> 3', cm.exception.text)
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030033 self.assertEqual(cm.exception.filename, '<FLUFL test>')
34 self.assertEqual(cm.exception.lineno, 1)
Pablo Galindo2b74c832020-04-27 18:02:07 +010035 # 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, 4 if support.use_old_parser() else 3)
Brett Cannone3944a52009-04-01 05:08:41 +000038
39
Brett Cannone3944a52009-04-01 05:08:41 +000040if __name__ == '__main__':
Zachary Ware38c707e2015-04-13 15:00:43 -050041 unittest.main()