bpo-34084: Fix setting an error message for the "Barry as BDFL" easte… · python/cpython@220afff
@@ -4,18 +4,29 @@
44class FLUFLTests(unittest.TestCase):
5566def 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"
88compile(code.format('<>'), '<BDFL test>', 'exec',
99__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)
13191420def test_guido_as_bdfl(self):
1521code = '2 {0} 3'
1622compile(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)
193020312132if __name__ == '__main__':