Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed3a7d2

Browse files
committed
#10273: Rename assertRegexpMatches and assertRaisesRegexp to assertRegex and assertRaisesRegex.
1 parent f10c400 commit ed3a7d2

21 files changed

Lines changed: 203 additions & 186 deletions

Doc/library/unittest.rst

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ Test cases
835835
+-----------------------------------------+-----------------------------+---------------+
836836

837837
All the assert methods (except :meth:`assertRaises`,
838-
:meth:`assertRaisesRegexp`, :meth:`assertWarns`, :meth:`assertWarnsRegexp`)
838+
:meth:`assertRaisesRegex`, :meth:`assertWarns`, :meth:`assertWarnsRegex`)
839839
accept a *msg* argument that, if specified, is used as the error message on
840840
failure (see also :data:`longMessage`).
841841

@@ -919,14 +919,14 @@ Test cases
919919
| :meth:`assertRaises(exc, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises `exc` | |
920920
| <TestCase.assertRaises>` | | |
921921
+---------------------------------------------------------+--------------------------------------+------------+
922-
| :meth:`assertRaisesRegexp(exc, re, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises `exc` | 3.1 |
923-
| <TestCase.assertRaisesRegexp>` | and the message matches `re` | |
922+
| :meth:`assertRaisesRegex(exc, re, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises `exc` | 3.1 |
923+
| <TestCase.assertRaisesRegex>` | and the message matches `re` | |
924924
+---------------------------------------------------------+--------------------------------------+------------+
925925
| :meth:`assertWarns(warn, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises `warn` | 3.2 |
926926
| <TestCase.assertWarns>` | | |
927927
+---------------------------------------------------------+--------------------------------------+------------+
928-
| :meth:`assertWarnsRegexp(warn, re, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises `warn` | 3.2 |
929-
| <TestCase.assertWarnsRegexp>` | and the message matches `re` | |
928+
| :meth:`assertWarnsRegex(warn, re, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises `warn` | 3.2 |
929+
| <TestCase.assertWarnsRegex>` | and the message matches `re` | |
930930
+---------------------------------------------------------+--------------------------------------+------------+
931931

932932
.. method:: assertRaises(exception, callable, *args, **kwds)
@@ -962,23 +962,25 @@ Test cases
962962
Added the :attr:`exception` attribute.
963963

964964

965-
.. method:: assertRaisesRegexp(exception, regexp, callable, *args, **kwds)
966-
assertRaisesRegexp(exception, regexp)
965+
.. method:: assertRaisesRegex(exception, regex, callable, *args, **kwds)
966+
assertRaisesRegex(exception, regex)
967967

968-
Like :meth:`assertRaises` but also tests that *regexp* matches
969-
on the string representation of the raised exception. *regexp* may be
968+
Like :meth:`assertRaises` but also tests that *regex* matches
969+
on the string representation of the raised exception. *regex* may be
970970
a regular expression object or a string containing a regular expression
971971
suitable for use by :func:`re.search`. Examples::
972972

973-
self.assertRaisesRegexp(ValueError, 'invalid literal for.*XYZ$',
974-
int, 'XYZ')
973+
self.assertRaisesRegex(ValueError, 'invalid literal for.*XYZ$',
974+
int, 'XYZ')
975975

976976
or::
977977

978-
with self.assertRaisesRegexp(ValueError, 'literal'):
978+
with self.assertRaisesRegex(ValueError, 'literal'):
979979
int('XYZ')
980980

981-
.. versionadded:: 3.1
981+
.. versionadded:: 3.1 ``assertRaisesRegexp``
982+
.. versionchanged:: 3.2
983+
The method has been renamed to :meth:`assertRaisesRegex`
982984

983985

984986
.. method:: assertWarns(warning, callable, *args, **kwds)
@@ -1015,21 +1017,21 @@ Test cases
10151017
.. versionadded:: 3.2
10161018

10171019

1018-
.. method:: assertWarnsRegexp(warning, regexp, callable, *args, **kwds)
1019-
assertWarnsRegexp(warning, regexp)
1020+
.. method:: assertWarnsRegex(warning, regex, callable, *args, **kwds)
1021+
assertWarnsRegex(warning, regex)
10201022

1021-
Like :meth:`assertWarns` but also tests that *regexp* matches on the
1022-
message of the triggered warning. *regexp* may be a regular expression
1023+
Like :meth:`assertWarns` but also tests that *regex* matches on the
1024+
message of the triggered warning. *regex* may be a regular expression
10231025
object or a string containing a regular expression suitable for use
10241026
by :func:`re.search`. Example::
10251027

1026-
self.assertWarnsRegexp(DeprecationWarning,
1027-
r'legacy_function\(\) is deprecated',
1028-
legacy_function, 'XYZ')
1028+
self.assertWarnsRegex(DeprecationWarning,
1029+
r'legacy_function\(\) is deprecated',
1030+
legacy_function, 'XYZ')
10291031

10301032
or::
10311033

1032-
with self.assertWarnsRegexp(RuntimeWarning, 'unsafe frobnicating'):
1034+
with self.assertWarnsRegex(RuntimeWarning, 'unsafe frobnicating'):
10331035
frobnicate('/etc/passwd')
10341036

10351037
.. versionadded:: 3.2
@@ -1059,11 +1061,11 @@ Test cases
10591061
| :meth:`assertLessEqual(a, b) | ``a <= b`` | 3.1 |
10601062
| <TestCase.assertLessEqual>` | | |
10611063
+---------------------------------------+--------------------------------+--------------+
1062-
| :meth:`assertRegexpMatches(s, re) | ``regex.search(s)`` | 3.1 |
1063-
| <TestCase.assertRegexpMatches>` | | |
1064+
| :meth:`assertRegex(s, re) | ``regex.search(s)`` | 3.1 |
1065+
| <TestCase.assertRegex>` | | |
10641066
+---------------------------------------+--------------------------------+--------------+
1065-
| :meth:`assertNotRegexpMatches(s, re) | ``not regex.search(s)`` | 3.2 |
1066-
| <TestCase.assertNotRegexpMatches>` | | |
1067+
| :meth:`assertNotRegex(s, re) | ``not regex.search(s)`` | 3.2 |
1068+
| <TestCase.assertNotRegex>` | | |
10671069
+---------------------------------------+--------------------------------+--------------+
10681070
| :meth:`assertDictContainsSubset(a, b) | all the key/value pairs | 3.1 |
10691071
| <TestCase.assertDictContainsSubset>` | in `a` exist in `b` | |
@@ -1108,17 +1110,19 @@ Test cases
11081110
.. versionadded:: 3.1
11091111

11101112

1111-
.. method:: assertRegexpMatches(text, regexp, msg=None)
1112-
assertNotRegexpMatches(text, regexp, msg=None)
1113+
.. method:: assertRegex(text, regex, msg=None)
1114+
assertNotRegex(text, regex, msg=None)
11131115

1114-
Test that a *regexp* search matches (or does not match) *text*. In case
1116+
Test that a *regex* search matches (or does not match) *text*. In case
11151117
of failure, the error message will include the pattern and the *text* (or
1116-
the pattern and the part of *text* that unexpectedly matched). *regexp*
1118+
the pattern and the part of *text* that unexpectedly matched). *regex*
11171119
may be a regular expression object or a string containing a regular
11181120
expression suitable for use by :func:`re.search`.
11191121

1120-
.. versionadded:: 3.1 :meth:`~TestCase.assertRegexpMatches`
1121-
.. versionadded:: 3.2 :meth:`~TestCase.assertNotRegexpMatches`
1122+
.. versionadded:: 3.1 ``.assertRegexpMatches``
1123+
.. versionchanged:: 3.2
1124+
``.assertRegexpMatches`` has been renamed to :meth:`.assertRegex`
1125+
.. versionadded:: 3.2 :meth:`.assertNotRegex`
11221126

11231127

11241128
.. method:: assertDictContainsSubset(expected, actual, msg=None)
@@ -1420,13 +1424,17 @@ along with their deprecated aliases:
14201424
:meth:`.assertRaises` failUnlessRaises
14211425
:meth:`.assertAlmostEqual` failUnlessAlmostEqual assertAlmostEquals
14221426
:meth:`.assertNotAlmostEqual` failIfAlmostEqual assertNotAlmostEquals
1427+
:meth:`.assertRegex` assertRegexpMatches
1428+
:meth:`.assertRaisesRegex` assertRaisesRegexp
14231429
============================== ====================== ======================
14241430

14251431
.. deprecated-removed:: 3.1 3.3
14261432
the fail* aliases listed in the second column.
14271433
.. deprecated:: 3.2
14281434
the assert* aliases listed in the third column.
1429-
1435+
.. deprecated:: 3.2
1436+
``assertRegexpMatches`` and ``assertRaisesRegexp`` have been renamed to
1437+
:meth:`.assertRegex` and :meth:`.assertRaisesRegex`
14301438

14311439

14321440
.. _testsuite-objects:

Lib/test/test_abc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ class C(A):
192192
def test_register_non_class(self):
193193
class A(metaclass=abc.ABCMeta):
194194
pass
195-
self.assertRaisesRegexp(TypeError, "Can only register classes",
196-
A.register, 4)
195+
self.assertRaisesRegex(TypeError, "Can only register classes",
196+
A.register, 4)
197197

198198
def test_registration_transitiveness(self):
199199
class A(metaclass=abc.ABCMeta):

Lib/test/test_asyncore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ def test_issue_8594(self):
312312
d = asyncore.dispatcher(socket.socket())
313313
# make sure the error message no longer refers to the socket
314314
# object but the dispatcher instance instead
315-
self.assertRaisesRegexp(AttributeError, 'dispatcher instance',
316-
getattr, d, 'foo')
315+
self.assertRaisesRegex(AttributeError, 'dispatcher instance',
316+
getattr, d, 'foo')
317317
# cheap inheritance with the underlying socket is supposed
318318
# to still work but a DeprecationWarning is expected
319319
with warnings.catch_warnings(record=True) as w:

Lib/test/test_concurrent_futures.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -682,18 +682,18 @@ def fn(callback_future):
682682
self.assertTrue(was_cancelled)
683683

684684
def test_repr(self):
685-
self.assertRegexpMatches(repr(PENDING_FUTURE),
686-
'<Future at 0x[0-9a-f]+ state=pending>')
687-
self.assertRegexpMatches(repr(RUNNING_FUTURE),
688-
'<Future at 0x[0-9a-f]+ state=running>')
689-
self.assertRegexpMatches(repr(CANCELLED_FUTURE),
690-
'<Future at 0x[0-9a-f]+ state=cancelled>')
691-
self.assertRegexpMatches(repr(CANCELLED_AND_NOTIFIED_FUTURE),
692-
'<Future at 0x[0-9a-f]+ state=cancelled>')
693-
self.assertRegexpMatches(
685+
self.assertRegex(repr(PENDING_FUTURE),
686+
'<Future at 0x[0-9a-f]+ state=pending>')
687+
self.assertRegex(repr(RUNNING_FUTURE),
688+
'<Future at 0x[0-9a-f]+ state=running>')
689+
self.assertRegex(repr(CANCELLED_FUTURE),
690+
'<Future at 0x[0-9a-f]+ state=cancelled>')
691+
self.assertRegex(repr(CANCELLED_AND_NOTIFIED_FUTURE),
692+
'<Future at 0x[0-9a-f]+ state=cancelled>')
693+
self.assertRegex(
694694
repr(EXCEPTION_FUTURE),
695695
'<Future at 0x[0-9a-f]+ state=finished raised IOError>')
696-
self.assertRegexpMatches(
696+
self.assertRegex(
697697
repr(SUCCESSFUL_FUTURE),
698698
'<Future at 0x[0-9a-f]+ state=finished returned int>')
699699

Lib/test/test_contextlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def test_contextdecorator(self):
231231
def test_contextdecorator_with_exception(self):
232232
context = mycontext()
233233

234-
with self.assertRaisesRegexp(NameError, 'foo'):
234+
with self.assertRaisesRegex(NameError, 'foo'):
235235
with context:
236236
raise NameError('foo')
237237
self.assertIsNotNone(context.exc)
@@ -265,7 +265,7 @@ def test():
265265
self.assertTrue(context.started)
266266
raise NameError('foo')
267267

268-
with self.assertRaisesRegexp(NameError, 'foo'):
268+
with self.assertRaisesRegex(NameError, 'foo'):
269269
test()
270270
self.assertIsNotNone(context.exc)
271271
self.assertIs(context.exc[0], NameError)

Lib/test/test_dis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,14 @@ class CodeInfoTests(unittest.TestCase):
354354
def test_code_info(self):
355355
self.maxDiff = 1000
356356
for x, expected in self.test_pairs:
357-
self.assertRegexpMatches(dis.code_info(x), expected)
357+
self.assertRegex(dis.code_info(x), expected)
358358

359359
def test_show_code(self):
360360
self.maxDiff = 1000
361361
for x, expected in self.test_pairs:
362362
with captured_stdout() as output:
363363
dis.show_code(x)
364-
self.assertRegexpMatches(output.getvalue(), expected+"\n")
364+
self.assertRegex(output.getvalue(), expected+"\n")
365365

366366
def test_main():
367367
run_unittest(DisTests, CodeInfoTests)

Lib/test/test_memoryview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class MyObject:
226226
self.assertTrue(wr() is None, wr())
227227

228228
def _check_released(self, m, tp):
229-
check = self.assertRaisesRegexp(ValueError, "released")
229+
check = self.assertRaisesRegex(ValueError, "released")
230230
with check: bytes(m)
231231
with check: m.tobytes()
232232
with check: m.tolist()

Lib/test/test_runpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def _check_script(self, script_name, expected_name, expected_file,
329329

330330
def _check_import_error(self, script_name, msg):
331331
msg = re.escape(msg)
332-
self.assertRaisesRegexp(ImportError, msg, run_path, script_name)
332+
self.assertRaisesRegex(ImportError, msg, run_path, script_name)
333333

334334
def test_basic_script(self):
335335
with temp_dir() as script_dir:
@@ -403,7 +403,7 @@ def test_main_recursion_error(self):
403403
script_name = self._make_test_script(script_dir, mod_name, source)
404404
zip_name, fname = make_zip_script(script_dir, 'test_zip', script_name)
405405
msg = "recursion depth exceeded"
406-
self.assertRaisesRegexp(RuntimeError, msg, run_path, zip_name)
406+
self.assertRaisesRegex(RuntimeError, msg, run_path, zip_name)
407407

408408

409409

Lib/test/test_smtplib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,12 @@ def testSendMessageWithAddresses(self):
319319
self.assertEqual(self.output.getvalue(), mexpect)
320320
debugout = smtpd.DEBUGSTREAM.getvalue()
321321
sender = re.compile("^sender: [email protected]$", re.MULTILINE)
322-
self.assertRegexpMatches(debugout, sender)
322+
self.assertRegex(debugout, sender)
323323
for addr in ('John', 'Sally', 'Fred', 'root@localhost',
324324
325325
to_addr = re.compile(r"^recips: .*'{}'.*$".format(addr),
326326
re.MULTILINE)
327-
self.assertRegexpMatches(debugout, to_addr)
327+
self.assertRegex(debugout, to_addr)
328328

329329
def testSendMessageWithSomeAddresses(self):
330330
# Make sure nothing breaks if not all of the three 'to' headers exist
@@ -347,11 +347,11 @@ def testSendMessageWithSomeAddresses(self):
347347
self.assertEqual(self.output.getvalue(), mexpect)
348348
debugout = smtpd.DEBUGSTREAM.getvalue()
349349
sender = re.compile("^sender: [email protected]$", re.MULTILINE)
350-
self.assertRegexpMatches(debugout, sender)
350+
self.assertRegex(debugout, sender)
351351
for addr in ('John', 'Dinsdale'):
352352
to_addr = re.compile(r"^recips: .*'{}'.*$".format(addr),
353353
re.MULTILINE)
354-
self.assertRegexpMatches(debugout, to_addr)
354+
self.assertRegex(debugout, to_addr)
355355

356356

357357
class NonConnectingTests(unittest.TestCase):

0 commit comments

Comments
 (0)