• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import __future__
2import unittest
3
4
5class FLUFLTests(unittest.TestCase):
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
38if __name__ == '__main__':
39    unittest.main()
40