test_flufl.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import __future__
  2. import unittest
  3. from test import support
  4. class FLUFLTests(unittest.TestCase):
  5. def test_barry_as_bdfl(self):
  6. code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
  7. compile(code.format('<>'), '<BDFL test>', 'exec',
  8. __future__.CO_FUTURE_BARRY_AS_BDFL)
  9. with self.assertRaises(SyntaxError) as cm:
  10. compile(code.format('!='), '<FLUFL test>', 'exec',
  11. __future__.CO_FUTURE_BARRY_AS_BDFL)
  12. self.assertRegex(str(cm.exception),
  13. "with Barry as BDFL, use '<>' instead of '!='")
  14. self.assertIn('2 != 3', cm.exception.text)
  15. self.assertEqual(cm.exception.filename, '<FLUFL test>')
  16. self.assertEqual(cm.exception.lineno, 2)
  17. # The old parser reports the end of the token and the new
  18. # parser reports the start of the token
  19. self.assertEqual(cm.exception.offset, 3)
  20. def test_guido_as_bdfl(self):
  21. code = '2 {0} 3'
  22. compile(code.format('!='), '<BDFL test>', 'exec')
  23. with self.assertRaises(SyntaxError) as cm:
  24. compile(code.format('<>'), '<FLUFL test>', 'exec')
  25. self.assertRegex(str(cm.exception), "invalid syntax")
  26. self.assertIn('2 <> 3', cm.exception.text)
  27. self.assertEqual(cm.exception.filename, '<FLUFL test>')
  28. self.assertEqual(cm.exception.lineno, 1)
  29. # The old parser reports the end of the token and the new
  30. # parser reports the start of the token
  31. self.assertEqual(cm.exception.offset, 3)
  32. if __name__ == '__main__':
  33. unittest.main()