|
4 | 4 | class FLUFLTests(unittest.TestCase): |
5 | 5 |
|
6 | 6 | def test_barry_as_bdfl(self): |
7 | | - code = "from __future__ import barry_as_FLUFL; 2 {0} 3" |
| 7 | + code = "from __future__ import barry_as_FLUFL\n2 {0} 3" |
8 | 8 | compile(code.format('<>'), '<BDFL test>', 'exec', |
9 | 9 | __future__.CO_FUTURE_BARRY_AS_BDFL) |
10 | | - self.assertRaises(SyntaxError, compile, code.format('!='), |
11 | | - '<FLUFL test>', 'exec', |
12 | | - __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) |
13 | 19 |
|
14 | 20 | def test_guido_as_bdfl(self): |
15 | 21 | code = '2 {0} 3' |
16 | 22 | compile(code.format('!='), '<BDFL test>', 'exec') |
17 | | - self.assertRaises(SyntaxError, compile, code.format('<>'), |
18 | | - '<FLUFL 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) |
19 | 30 |
|
20 | 31 |
|
21 | 32 | if __name__ == '__main__': |
|
0 commit comments