changeset: 96080:0c93868f202e branch: 2.7 parent: 96072:8875d7c6a99d user: Serhiy Storchaka date: Sat May 16 16:21:10 2015 +0300 files: Lib/unittest/case.py Lib/unittest/test/test_case.py Misc/NEWS description: Reverted issue #24134 changes. diff -r 8875d7c6a99d -r 0c93868f202e Lib/unittest/case.py --- a/Lib/unittest/case.py Fri May 15 23:55:15 2015 -0400 +++ b/Lib/unittest/case.py Sat May 16 16:21:10 2015 +0300 @@ -127,8 +127,6 @@ (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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 -r 8875d7c6a99d -r 0c93868f202e Lib/unittest/test/test_case.py --- a/Lib/unittest/test/test_case.py Fri May 15 23:55:15 2015 -0400 +++ b/Lib/unittest/test/test_case.py Sat May 16 16:21:10 2015 +0300 @@ -967,9 +967,6 @@ # 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 @@ 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( diff -r 8875d7c6a99d -r 0c93868f202e Misc/NEWS --- a/Misc/NEWS Fri May 15 23:55:15 2015 -0400 +++ b/Misc/NEWS Sat May 16 16:21:10 2015 +0300 @@ -13,6 +13,8 @@ Library ------- +- Issue #24134: Reverted issue #24134 changes. + What's New in Python 2.7.10 release candidate 1? ================================================