MCPcopy Index your code
hub / github.com/python/cpython / _check_error

Method _check_error

Lib/test/test_syntax.py:2948–2976  ·  view source on GitHub ↗

Check that compiling code raises SyntaxError with errtext. errtest is a regular expression that must be present in the text 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

2946class SyntaxErrorTestCase(unittest.TestCase):
2947
2948 def _check_error(self, code, errtext,
2949 filename="<testcase>", mode="exec", subclass=None,
2950 lineno=None, offset=None, end_lineno=None, end_offset=None):
2951 """Check that compiling code raises SyntaxError with errtext.
2952
2953 errtest is a regular expression that must be present in the
2954 text of the exception raised. If subclass is specified it
2955 is the expected subclass of SyntaxError (e.g. IndentationError).
2956 """
2957 try:
2958 compile(code, filename, mode)
2959 except SyntaxError as err:
2960 if subclass and not isinstance(err, subclass):
2961 self.fail("SyntaxError is not a %s" % subclass.__name__)
2962 mo = re.search(errtext, str(err))
2963 if mo is None:
2964 self.fail("SyntaxError did not contain %r" % (errtext,))
2965 self.assertEqual(err.filename, filename)
2966 if lineno is not None:
2967 self.assertEqual(err.lineno, lineno)
2968 if offset is not None:
2969 self.assertEqual(err.offset, offset)
2970 if end_lineno is not None:
2971 self.assertEqual(err.end_lineno, end_lineno)
2972 if end_offset is not None:
2973 self.assertEqual(err.end_offset, end_offset)
2974
2975 else:
2976 self.fail("compile() did not raise SyntaxError")
2977
2978 def test_expression_with_assignment(self):
2979 self._check_error(

Calls 5

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

Tested by

no test coverage detected