| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,18 +4,29 @@ | |||
| 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__': | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -246,8 +246,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, | |||
| 246 | 246 | else if ((ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) && | |
| 247 | 247 | strcmp(str, "<>")) { | |
| 248 | 248 | PyObject_FREE(str); | |
| 249 | - err_ret->text = "with Barry as BDFL, use '<>' " | ||
| 250 | - "instead of '!='"; | ||
| 249 | + err_ret->expected = NOTEQUAL; | ||
| 251 | 250 | err_ret->error = E_SYNTAX; | |
| 252 | 251 | break; | |
| 253 | 252 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1337,6 +1337,10 @@ err_input(perrdetail *err) | |||
| 1337 | 1337 | msg = "unexpected indent"; | |
| 1338 | 1338 | else if (err->token == DEDENT) | |
| 1339 | 1339 | msg = "unexpected unindent"; | |
| 1340 | + else if (err->expected == NOTEQUAL) { | ||
| 1341 | + errtype = PyExc_SyntaxError; | ||
| 1342 | + msg = "with Barry as BDFL, use '<>' instead of '!='"; | ||
| 1343 | + } | ||
| 1340 | 1344 | else { | |
| 1341 | 1345 | errtype = PyExc_SyntaxError; | |
| 1342 | 1346 | msg = "invalid syntax"; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments