mirror of https://github.com/django/django.git
[1.8.x] Fixed #24903 -- Fixed assertRaisesMessage on Python 2.7.10.
A regression in Python 2.7.10 rc1 wasn't reverted in the final release: https://bugs.python.org/issue24134 Backport of two commits from master: *c2bc1cefdc
*e89c3a4603
This commit is contained in:
parent
b3f61f6e08
commit
8bc18ebf0f
|
@ -565,8 +565,7 @@ class SimpleTestCase(unittest.TestCase):
|
||||||
msg_prefix + "Template '%s' was used unexpectedly in rendering"
|
msg_prefix + "Template '%s' was used unexpectedly in rendering"
|
||||||
" the response" % template_name)
|
" the response" % template_name)
|
||||||
|
|
||||||
def assertRaisesMessage(self, expected_exception, expected_message,
|
def assertRaisesMessage(self, expected_exception, expected_message, *args, **kwargs):
|
||||||
callable_obj=None, *args, **kwargs):
|
|
||||||
"""
|
"""
|
||||||
Asserts that the message in a raised exception matches the passed
|
Asserts that the message in a raised exception matches the passed
|
||||||
value.
|
value.
|
||||||
|
@ -574,12 +573,17 @@ class SimpleTestCase(unittest.TestCase):
|
||||||
Args:
|
Args:
|
||||||
expected_exception: Exception class expected to be raised.
|
expected_exception: Exception class expected to be raised.
|
||||||
expected_message: expected error message string value.
|
expected_message: expected error message string value.
|
||||||
callable_obj: Function to be called.
|
args: Function to be called and extra positional args.
|
||||||
args: Extra args.
|
|
||||||
kwargs: Extra kwargs.
|
kwargs: Extra kwargs.
|
||||||
"""
|
"""
|
||||||
|
# callable_obj was a documented kwarg in older version of Django, but
|
||||||
|
# had to be removed due to a bad fix for http://bugs.python.org/issue24134
|
||||||
|
# inadvertently making its way into Python 2.7.10.
|
||||||
|
callable_obj = kwargs.pop('callable_obj', None)
|
||||||
|
if callable_obj:
|
||||||
|
args = (callable_obj,) + args
|
||||||
return six.assertRaisesRegex(self, expected_exception,
|
return six.assertRaisesRegex(self, expected_exception,
|
||||||
re.escape(expected_message), callable_obj, *args, **kwargs)
|
re.escape(expected_message), *args, **kwargs)
|
||||||
|
|
||||||
def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
|
def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
|
||||||
field_kwargs=None, empty_value=''):
|
field_kwargs=None, empty_value=''):
|
||||||
|
|
|
@ -8,3 +8,6 @@ Django 1.7.9 fixes several bugs in 1.7.8.
|
||||||
|
|
||||||
* Prevented the loss of ``null``/``not null`` column properties during field
|
* Prevented the loss of ``null``/``not null`` column properties during field
|
||||||
renaming of MySQL databases (:ticket:`24817`).
|
renaming of MySQL databases (:ticket:`24817`).
|
||||||
|
|
||||||
|
* Fixed ``SimpleTestCase.assertRaisesMessage()`` on Python 2.7.10
|
||||||
|
(:ticket:`24903`).
|
||||||
|
|
|
@ -59,3 +59,6 @@ Bugfixes
|
||||||
results (:ticket:`24924`).
|
results (:ticket:`24924`).
|
||||||
|
|
||||||
* Fixed usage of transforms in subqueries (:ticket:`24744`).
|
* Fixed usage of transforms in subqueries (:ticket:`24744`).
|
||||||
|
|
||||||
|
* Fixed ``SimpleTestCase.assertRaisesMessage()`` on Python 2.7.10
|
||||||
|
(:ticket:`24903`).
|
||||||
|
|
|
@ -752,6 +752,12 @@ class AssertRaisesMsgTest(SimpleTestCase):
|
||||||
raise ValueError("[.*x+]y?")
|
raise ValueError("[.*x+]y?")
|
||||||
self.assertRaisesMessage(ValueError, "[.*x+]y?", func1)
|
self.assertRaisesMessage(ValueError, "[.*x+]y?", func1)
|
||||||
|
|
||||||
|
def test_callable_obj_param(self):
|
||||||
|
# callable_obj was a documented kwarg in older version of Django.
|
||||||
|
def func1():
|
||||||
|
raise ValueError("[.*x+]y?")
|
||||||
|
self.assertRaisesMessage(ValueError, "[.*x+]y?", callable_obj=func1)
|
||||||
|
|
||||||
|
|
||||||
class AssertFieldOutputTests(SimpleTestCase):
|
class AssertFieldOutputTests(SimpleTestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue