(root)/
Python-3.11.7/
Lib/
test/
test_flufl.py
       1  import __future__
       2  import unittest
       3  from test import support
       4  
       5  
       6  class ESC[4;38;5;81mFLUFLTests(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
       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.assertEqual(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, 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, 3)
      37  
      38  
      39  if __name__ == '__main__':
      40      unittest.main()