Brett Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 1 | import __future__ |
| 2 | import unittest |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame^] | 3 | import sys |
Brett Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 4 | |
Pablo Galindo | c5fc156 | 2020-04-22 23:29:27 +0100 | [diff] [blame^] | 5 | |
| 6 | @unittest.skipIf(sys.flags.use_peg, "Not supported by pegen yet") |
Brett Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 7 | class FLUFLTests(unittest.TestCase): |
| 8 | |
| 9 | def test_barry_as_bdfl(self): |
Serhiy Storchaka | aba24ff | 2018-07-23 23:41:11 +0300 | [diff] [blame] | 10 | code = "from __future__ import barry_as_FLUFL\n2 {0} 3" |
Brett Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 11 | compile(code.format('<>'), '<BDFL test>', 'exec', |
| 12 | __future__.CO_FUTURE_BARRY_AS_BDFL) |
Serhiy Storchaka | aba24ff | 2018-07-23 23:41:11 +0300 | [diff] [blame] | 13 | 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 Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 22 | |
| 23 | def test_guido_as_bdfl(self): |
| 24 | code = '2 {0} 3' |
| 25 | compile(code.format('!='), '<BDFL test>', 'exec') |
Serhiy Storchaka | aba24ff | 2018-07-23 23:41:11 +0300 | [diff] [blame] | 26 | 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 Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 33 | |
| 34 | |
Brett Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 35 | if __name__ == '__main__': |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame] | 36 | unittest.main() |