1import __future__ 2import unittest 3from test import support 4 5 6class FLUFLTests(unittest.TestCase): 7 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.assertTrue(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, 4 if support.use_old_parser() else 3) 24 25 def test_guido_as_bdfl(self): 26 code = '2 {0} 3' 27 compile(code.format('!='), '<BDFL test>', 'exec') 28 with self.assertRaises(SyntaxError) as cm: 29 compile(code.format('<>'), '<FLUFL test>', 'exec') 30 self.assertRegex(str(cm.exception), "invalid syntax") 31 self.assertIn('2 <> 3', cm.exception.text) 32 self.assertEqual(cm.exception.filename, '<FLUFL test>') 33 self.assertEqual(cm.exception.lineno, 1) 34 # The old parser reports the end of the token and the new 35 # parser reports the start of the token 36 self.assertEqual(cm.exception.offset, 4 if support.use_old_parser() else 3) 37 38 39if __name__ == '__main__': 40 unittest.main() 41