2009-04-01 02:08:41 -03:00
|
|
|
import __future__
|
|
|
|
import unittest
|
2020-04-22 22:03:24 -03:00
|
|
|
from test import support
|
2009-04-01 02:08:41 -03:00
|
|
|
|
2020-04-22 19:29:27 -03:00
|
|
|
|
2009-04-01 02:08:41 -03:00
|
|
|
class FLUFLTests(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_barry_as_bdfl(self):
|
2018-07-23 17:41:11 -03:00
|
|
|
code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
|
2009-04-01 02:08:41 -03:00
|
|
|
compile(code.format('<>'), '<BDFL test>', 'exec',
|
|
|
|
__future__.CO_FUTURE_BARRY_AS_BDFL)
|
2018-07-23 17:41:11 -03:00
|
|
|
with self.assertRaises(SyntaxError) as cm:
|
|
|
|
compile(code.format('!='), '<FLUFL test>', 'exec',
|
|
|
|
__future__.CO_FUTURE_BARRY_AS_BDFL)
|
|
|
|
self.assertRegex(str(cm.exception),
|
|
|
|
"with Barry as BDFL, use '<>' instead of '!='")
|
2020-04-27 14:02:07 -03:00
|
|
|
self.assertIn('2 != 3', cm.exception.text)
|
2018-07-23 17:41:11 -03:00
|
|
|
self.assertEqual(cm.exception.filename, '<FLUFL test>')
|
2020-04-27 14:02:07 -03:00
|
|
|
|
2022-02-17 21:45:35 -04:00
|
|
|
self.assertEqual(cm.exception.lineno, 2)
|
2020-04-27 14:02:07 -03:00
|
|
|
# The old parser reports the end of the token and the new
|
|
|
|
# parser reports the start of the token
|
2020-06-11 13:30:46 -03:00
|
|
|
self.assertEqual(cm.exception.offset, 3)
|
2009-04-01 02:08:41 -03:00
|
|
|
|
|
|
|
def test_guido_as_bdfl(self):
|
|
|
|
code = '2 {0} 3'
|
|
|
|
compile(code.format('!='), '<BDFL test>', 'exec')
|
2018-07-23 17:41:11 -03:00
|
|
|
with self.assertRaises(SyntaxError) as cm:
|
|
|
|
compile(code.format('<>'), '<FLUFL test>', 'exec')
|
|
|
|
self.assertRegex(str(cm.exception), "invalid syntax")
|
2020-04-27 14:02:07 -03:00
|
|
|
self.assertIn('2 <> 3', cm.exception.text)
|
2018-07-23 17:41:11 -03:00
|
|
|
self.assertEqual(cm.exception.filename, '<FLUFL test>')
|
|
|
|
self.assertEqual(cm.exception.lineno, 1)
|
2020-04-27 14:02:07 -03:00
|
|
|
# The old parser reports the end of the token and the new
|
|
|
|
# parser reports the start of the token
|
2020-06-11 13:30:46 -03:00
|
|
|
self.assertEqual(cm.exception.offset, 3)
|
2009-04-01 02:08:41 -03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-04-13 17:00:43 -03:00
|
|
|
unittest.main()
|