diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-02-19 06:30:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-19 06:30:15 (GMT) |
commit | e7a4bb554edb72fc6619d23241d59162d06f249a (patch) | |
tree | ba74116b687307c63725d6bed28fce0e46cade90 /Doc/library/test.rst | |
parent | ee0f927bd8dba805a04963dbec1ad49fe830b842 (diff) | |
download | cpython-e7a4bb554edb72fc6619d23241d59162d06f249a.zip cpython-e7a4bb554edb72fc6619d23241d59162d06f249a.tar.gz cpython-e7a4bb554edb72fc6619d23241d59162d06f249a.tar.bz2 |
bpo-35798: Add test.support.check_syntax_warning(). (#11895)
It checks that a SyntaxWarning is raised when compile specified
statement, that it is raised only once, that it is converted to
a SyntaxError when raised as exception, and that both warning and
exception objects have corresponding attributes.
Diffstat (limited to 'Doc/library/test.rst')
-rw-r--r-- | Doc/library/test.rst | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 6a10bab..b5057c0 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -936,9 +936,24 @@ The :mod:`test.support` module defines the following functions: Test for syntax errors in *statement* by attempting to compile *statement*. *testcase* is the :mod:`unittest` instance for the test. *errtext* is the - text of the error raised by :exc:`SyntaxError`. If *lineno* is not None, - compares to the line of the :exc:`SyntaxError`. If *offset* is not None, - compares to the offset of the :exc:`SyntaxError`. + regular expression which should match the string representation of the + raised :exc:`SyntaxError`. If *lineno* is not ``None``, compares to + the line of the exception. If *offset* is not ``None``, compares to + the offset of the exception. + + +.. function:: check_syntax_warning(testcase, statement, errtext='', *, lineno=1, offset=None) + + Test for syntax warning in *statement* by attempting to compile *statement*. + Test also that the :exc:`SyntaxWarning` is emitted only once, and that it + will be converted to a :exc:`SyntaxError` when turned into error. + *testcase* is the :mod:`unittest` instance for the test. *errtext* is the + regular expression which should match the string representation of the + emitted :exc:`SyntaxWarning` and raised :exc:`SyntaxError`. If *lineno* + is not ``None``, compares to the line of the warning and exception. + If *offset* is not ``None``, compares to the offset of the exception. + + .. versionadded:: 3.8 .. function:: open_urlresource(url, *args, **kw) |