diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-16 13:21:10 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-16 13:21:10 (GMT) |
commit | 049060c249a83b69c4841ed37b7f4303f9ad7dd7 (patch) | |
tree | 8a24db1c7f8d92d06f51f9f936c7c3d924acea20 /Lib/unittest | |
parent | d39d962cbd9c2ac74fc91d1c022e1430586c67ba (diff) | |
download | cpython-049060c249a83b69c4841ed37b7f4303f9ad7dd7.zip cpython-049060c249a83b69c4841ed37b7f4303f9ad7dd7.tar.gz cpython-049060c249a83b69c4841ed37b7f4303f9ad7dd7.tar.bz2 |
Reverted issue #24134 changes.
Diffstat (limited to 'Lib/unittest')
-rw-r--r-- | Lib/unittest/case.py | 12 | ||||
-rw-r--r-- | Lib/unittest/test/test_case.py | 5 |
2 files changed, 5 insertions, 12 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 6bbc55f..644fe5b 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -127,8 +127,6 @@ class _AssertRaisesContext(object): (expected_regexp.pattern, str(exc_value))) return True -def _sentinel(*args, **kwargs): - raise AssertionError('Should never be called') class TestCase(object): """A class whose instances are single test cases. @@ -445,7 +443,7 @@ class TestCase(object): return '%s : %s' % (safe_repr(standardMsg), safe_repr(msg)) - def assertRaises(self, excClass, callableObj=_sentinel, *args, **kwargs): + def assertRaises(self, excClass, callableObj=None, *args, **kwargs): """Fail unless an exception of class excClass is raised by callableObj when invoked with arguments args and keyword arguments kwargs. If a different type of exception is @@ -453,7 +451,7 @@ class TestCase(object): deemed to have suffered an error, exactly as for an unexpected exception. - If called with callableObj omitted, will return a + If called with callableObj omitted or None, will return a context object used like this:: with self.assertRaises(SomeException): @@ -469,7 +467,7 @@ class TestCase(object): self.assertEqual(the_exception.error_code, 3) """ context = _AssertRaisesContext(excClass, self) - if callableObj is _sentinel: + if callableObj is None: return context with context: callableObj(*args, **kwargs) @@ -975,7 +973,7 @@ class TestCase(object): self.fail(self._formatMessage(msg, standardMsg)) def assertRaisesRegexp(self, expected_exception, expected_regexp, - callable_obj=_sentinel, *args, **kwargs): + callable_obj=None, *args, **kwargs): """Asserts that the message in a raised exception matches a regexp. Args: @@ -989,7 +987,7 @@ class TestCase(object): if expected_regexp is not None: expected_regexp = re.compile(expected_regexp) context = _AssertRaisesContext(expected_exception, self, expected_regexp) - if callable_obj is _sentinel: + if callable_obj is None: return context with context: callable_obj(*args, **kwargs) diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index 4c2d1f9..7658189 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -967,9 +967,6 @@ test case # Failure when no exception is raised with self.assertRaises(self.failureException): self.assertRaises(ExceptionMock, lambda: 0) - # Failure when the function is None - with self.assertRaises(TypeError): - self.assertRaises(ExceptionMock, None) # Failure when another exception is raised with self.assertRaises(ExceptionMock): self.assertRaises(ValueError, Stub) @@ -1008,8 +1005,6 @@ test case self.assertRaisesRegexp(ExceptionMock, re.compile('expect$'), Stub) self.assertRaisesRegexp(ExceptionMock, 'expect$', Stub) self.assertRaisesRegexp(ExceptionMock, u'expect$', Stub) - with self.assertRaises(TypeError): - self.assertRaisesRegexp(ExceptionMock, 'expect$', None) def testAssertNotRaisesRegexp(self): self.assertRaisesRegexp( |