MCPcopy Index your code
hub / github.com/RustPython/RustPython / _check_error

Method _check_error

Lib/test/test_syntax.py:2258–2286  ·  view source on GitHub ↗

Check that compiling code raises SyntaxError with errtext. errtest is a regular expression that must be present in the test of the exception raised. If subclass is specified it is the expected subclass of SyntaxError (e.g. IndentationError).

(self, code, errtext,
                     filename="<testcase>", mode="exec", subclass=None,
                     lineno=None, offset=None, end_lineno=None, end_offset=None)

Source from the content-addressed store, hash-verified

2256class SyntaxTestCase(unittest.TestCase):
2257
2258 def _check_error(self, code, errtext,
2259 filename="<testcase>", mode="exec", subclass=None,
2260 lineno=None, offset=None, end_lineno=None, end_offset=None):
2261 """Check that compiling code raises SyntaxError with errtext.
2262
2263 errtest is a regular expression that must be present in the
2264 test of the exception raised. If subclass is specified it
2265 is the expected subclass of SyntaxError (e.g. IndentationError).
2266 """
2267 try:
2268 compile(code, filename, mode)
2269 except SyntaxError as err:
2270 if subclass and not isinstance(err, subclass):
2271 self.fail("SyntaxError is not a %s" % subclass.__name__)
2272 mo = re.search(errtext, str(err))
2273 if mo is None:
2274 self.fail("SyntaxError did not contain %r" % (errtext,))
2275 self.assertEqual(err.filename, filename)
2276 if lineno is not None:
2277 self.assertEqual(err.lineno, lineno)
2278 if offset is not None:
2279 self.assertEqual(err.offset, offset)
2280 if end_lineno is not None:
2281 self.assertEqual(err.end_lineno, end_lineno)
2282 if end_offset is not None:
2283 self.assertEqual(err.end_offset, end_offset)
2284
2285 else:
2286 self.fail("compile() did not raise SyntaxError")
2287
2288 @unittest.expectedFailure # TODO: RUSTPYTHON
2289 def test_expression_with_assignment(self):

Calls 6

isinstanceFunction · 0.85
strFunction · 0.85
compileFunction · 0.50
failMethod · 0.45
searchMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected