(root)/
Python-3.12.0/
Lib/
test/
test_flufl.py
       1  import __future__
       2  import unittest
       3  
       4  
       5  class ESC[4;38;5;81mFLUFLTests(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
       6  
       7      def test_barry_as_bdfl(self):
       8          code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
       9          compile(code.format('<>'), '<BDFL test>', 'exec',
      10                  __future__.CO_FUTURE_BARRY_AS_BDFL)
      11          with self.assertRaises(SyntaxError) as cm:
      12              compile(code.format('!='), '<FLUFL test>', 'exec',
      13                      __future__.CO_FUTURE_BARRY_AS_BDFL)
      14          self.assertRegex(str(cm.exception),
      15                           "with Barry as BDFL, use '<>' instead of '!='")
      16          self.assertIn('2 != 3', cm.exception.text)
      17          self.assertEqual(cm.exception.filename, '<FLUFL test>')
      18  
      19          self.assertEqual(cm.exception.lineno, 2)
      20          # The old parser reports the end of the token and the new
      21          # parser reports the start of the token
      22          self.assertEqual(cm.exception.offset, 3)
      23  
      24      def test_guido_as_bdfl(self):
      25          code = '2 {0} 3'
      26          compile(code.format('!='), '<BDFL test>', 'exec')
      27          with self.assertRaises(SyntaxError) as cm:
      28              compile(code.format('<>'), '<FLUFL test>', 'exec')
      29          self.assertRegex(str(cm.exception), "invalid syntax")
      30          self.assertIn('2 <> 3', cm.exception.text)
      31          self.assertEqual(cm.exception.filename, '<FLUFL test>')
      32          self.assertEqual(cm.exception.lineno, 1)
      33          # The old parser reports the end of the token and the new
      34          # parser reports the start of the token
      35          self.assertEqual(cm.exception.offset, 3)
      36  
      37  
      38  if __name__ == '__main__':
      39      unittest.main()