cpython: ac13f0390866 (original) (raw)

--- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -129,37 +129,42 @@ class _BaseTestCaseContext: msg = self.test_case._formatMessage(self.msg, standardMsg) raise self.test_case.failureException(msg) -def _sentinel(*args, **kwargs):

- class _AssertRaisesBaseContext(_BaseTestCaseContext):

+

@@ -676,15 +681,15 @@ class TestCase(object): except UnicodeDecodeError: return '%s : %s' % (safe_repr(standardMsg), safe_repr(msg))

with self.assertRaises(SomeException): @@ -702,18 +707,18 @@ class TestCase(object): the_exception = cm.exception self.assertEqual(the_exception.error_code, 3) """

with self.assertWarns(SomeWarning): @@ -733,8 +738,8 @@ class TestCase(object): the_warning = cm.warning self.assertEqual(the_warning.some_attribute, 147) """

def assertLogs(self, logger=None, level=None): """Fail unless a log message of level level or higher is emitted @@ -1221,26 +1226,23 @@ class TestCase(object): self.fail(self._formatMessage(msg, standardMsg)) def assertRaisesRegex(self, expected_exception, expected_regex,

Args: expected_exception: Exception class expected to be raised. expected_regex: Regex (re pattern object or string) expected to be found in error message.

-

def assertWarnsRegex(self, expected_warning, expected_regex,

@@ -1250,15 +1252,13 @@ class TestCase(object): expected_warning: Warning class expected to be triggered. expected_regex: Regex (re pattern object or string) expected to be found in error message.

def assertRegex(self, text, expected_regex, msg=None): """Fail the test unless the text matches the regular expression."""

--- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -1146,7 +1146,7 @@ test case with self.assertRaises(self.failureException): self.assertRaises(ExceptionMock, lambda: 0) # Failure when the function is None

@@ -1172,6 +1172,15 @@ test case with self.assertRaises(self.failureException): with self.assertRaises(ExceptionMock): pass

@@ -1185,7 +1194,7 @@ test case self.assertRaisesRegex(ExceptionMock, re.compile('expect$'), Stub) self.assertRaisesRegex(ExceptionMock, 'expect$', Stub)

def testAssertNotRaisesRegex(self): @@ -1197,6 +1206,15 @@ test case self.failureException, '^Exception not raised by $', self.assertRaisesRegex, Exception, 'x', lambda: None)

def testAssertRaisesRegexInvalidRegex(self): # Issue 20145. @@ -1255,7 +1273,7 @@ test case with self.assertRaises(self.failureException): self.assertWarns(RuntimeWarning, lambda: 0) # Failure when the function is None

@@ -1295,6 +1313,15 @@ test case with self.assertRaises(self.failureException): with self.assertWarns(RuntimeWarning): pass

@@ -1319,7 +1346,7 @@ test case self.assertWarnsRegex(RuntimeWarning, "o+", lambda: 0) # Failure when the function is None

@@ -1357,6 +1384,15 @@ test case with self.assertRaises(self.failureException): with self.assertWarnsRegex(RuntimeWarning, "o+"): pass

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -76,7 +76,8 @@ Library usernames and passwords to UTF8.