Brett Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 1 | import __future__ |
| 2 | import unittest |
| 3 | |
| 4 | class FLUFLTests(unittest.TestCase): |
| 5 | |
| 6 | def test_barry_as_bdfl(self): |
Serhiy Storchaka | aba24ff | 2018-07-23 23:41:11 +0300 | [diff] [blame] | 7 | code = "from __future__ import barry_as_FLUFL\n2 {0} 3" |
Brett Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 8 | compile(code.format('<>'), '<BDFL test>', 'exec', |
| 9 | __future__.CO_FUTURE_BARRY_AS_BDFL) |
Serhiy Storchaka | aba24ff | 2018-07-23 23:41:11 +0300 | [diff] [blame] | 10 | with self.assertRaises(SyntaxError) as cm: |
| 11 | compile(code.format('!='), '<FLUFL test>', 'exec', |
| 12 | __future__.CO_FUTURE_BARRY_AS_BDFL) |
| 13 | self.assertRegex(str(cm.exception), |
| 14 | "with Barry as BDFL, use '<>' instead of '!='") |
| 15 | self.assertEqual(cm.exception.text, '2 != 3\n') |
| 16 | self.assertEqual(cm.exception.filename, '<FLUFL test>') |
| 17 | self.assertEqual(cm.exception.lineno, 2) |
| 18 | self.assertEqual(cm.exception.offset, 4) |
Brett Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 19 | |
| 20 | def test_guido_as_bdfl(self): |
| 21 | code = '2 {0} 3' |
| 22 | compile(code.format('!='), '<BDFL test>', 'exec') |
Serhiy Storchaka | aba24ff | 2018-07-23 23:41:11 +0300 | [diff] [blame] | 23 | with self.assertRaises(SyntaxError) as cm: |
| 24 | compile(code.format('<>'), '<FLUFL test>', 'exec') |
| 25 | self.assertRegex(str(cm.exception), "invalid syntax") |
| 26 | self.assertEqual(cm.exception.text, '2 <> 3\n') |
| 27 | self.assertEqual(cm.exception.filename, '<FLUFL test>') |
| 28 | self.assertEqual(cm.exception.lineno, 1) |
| 29 | self.assertEqual(cm.exception.offset, 4) |
Brett Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 30 | |
| 31 | |
Brett Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 32 | if __name__ == '__main__': |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame] | 33 | unittest.main() |