Skip to content

Commit

Permalink
[1.7.x] Fixed #24903 -- Fixed assertRaisesMessage on Python 2.7.10.
Browse files Browse the repository at this point in the history
A regression found in in Python 2.7.10 rc1 wasn't reverted for the final
release: https://bugs.python.org/issue24134

Backport of two commits from master:
* c2bc1ce
* e89c3a4
  • Loading branch information
timgraham committed Jun 9, 2015
1 parent 7ae53e7 commit 207da07
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 9 additions & 5 deletions django/test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,21 +558,25 @@ def assertTemplateNotUsed(self, response=None, template_name=None, msg_prefix=''
msg_prefix + "Template '%s' was used unexpectedly in rendering"
" the response" % template_name)

def assertRaisesMessage(self, expected_exception, expected_message,
callable_obj=None, *args, **kwargs):
def assertRaisesMessage(self, expected_exception, expected_message, *args, **kwargs):
"""
Asserts that the message in a raised exception matches the passed
value.
Args:
expected_exception: Exception class expected to be raised.
expected_message: expected error message string value.
callable_obj: Function to be called.
args: Extra args.
args: Function to be called and extra positional args.
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,
re.escape(expected_message), callable_obj, *args, **kwargs)
re.escape(expected_message), *args, **kwargs)

def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
field_kwargs=None, empty_value=''):
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/1.7.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
renaming of MySQL databases (:ticket:`24817`).

* Fixed ``SimpleTestCase.assertRaisesMessage()`` on Python 2.7.10
(:ticket:`24903`).
6 changes: 6 additions & 0 deletions tests/test_utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,12 @@ def func1():
raise ValueError("[.*x+]y?")
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):

Expand Down

0 comments on commit 207da07

Please sign in to comment.