blob: 33e52e609a761a6bacf6499bb82802c304590a42 [file] [log] [blame]
Brett Cannone3944a52009-04-01 05:08:41 +00001import __future__
2import unittest
3
4class FLUFLTests(unittest.TestCase):
5
6 def test_barry_as_bdfl(self):
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +03007 code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
Brett Cannone3944a52009-04-01 05:08:41 +00008 compile(code.format('<>'), '<BDFL test>', 'exec',
9 __future__.CO_FUTURE_BARRY_AS_BDFL)
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030010 with self.assertRaises(SyntaxError) as cm:
11 compile(code.format('!='), '<FLUFL test>', 'exec',
12 __future__.CO_FUTURE_BARRY_AS_BDFL)
13 self.assertRegex(str(cm.exception),
14 "with Barry as BDFL, use '<>' instead of '!='")
15 self.assertEqual(cm.exception.text, '2 != 3\n')
16 self.assertEqual(cm.exception.filename, '<FLUFL test>')
17 self.assertEqual(cm.exception.lineno, 2)
18 self.assertEqual(cm.exception.offset, 4)
Brett Cannone3944a52009-04-01 05:08:41 +000019
20 def test_guido_as_bdfl(self):
21 code = '2 {0} 3'
22 compile(code.format('!='), '<BDFL test>', 'exec')
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030023 with self.assertRaises(SyntaxError) as cm:
24 compile(code.format('<>'), '<FLUFL test>', 'exec')
25 self.assertRegex(str(cm.exception), "invalid syntax")
26 self.assertEqual(cm.exception.text, '2 <> 3\n')
27 self.assertEqual(cm.exception.filename, '<FLUFL test>')
28 self.assertEqual(cm.exception.lineno, 1)
29 self.assertEqual(cm.exception.offset, 4)
Brett Cannone3944a52009-04-01 05:08:41 +000030
31
Brett Cannone3944a52009-04-01 05:08:41 +000032if __name__ == '__main__':
Zachary Ware38c707e2015-04-13 15:00:43 -050033 unittest.main()