• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import __future__
2import unittest
3
4class FLUFLTests(unittest.TestCase):
5
6    def test_barry_as_bdfl(self):
7        code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
8        compile(code.format('<>'), '<BDFL test>', 'exec',
9                __future__.CO_FUTURE_BARRY_AS_BDFL)
10        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)
19
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.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)
30
31
32if __name__ == '__main__':
33    unittest.main()
34