Fixed #19589 -- assertRegexpMatches is deprecated in Python 3.3.

This commit is contained in:
Aymeric Augustin 2013-01-26 13:47:11 +01:00
parent cebbec9b61
commit 55416e235d
6 changed files with 19 additions and 5 deletions

View File

@ -393,9 +393,11 @@ def with_metaclass(meta, base=object):
if PY3:
_iterlists = "lists"
_assertRaisesRegex = "assertRaisesRegex"
_assertRegex = "assertRegex"
else:
_iterlists = "iterlists"
_assertRaisesRegex = "assertRaisesRegexp"
_assertRegex = "assertRegexpMatches"
def iterlists(d):
@ -407,5 +409,9 @@ def assertRaisesRegex(self, *args, **kwargs):
return getattr(self, _assertRaisesRegex)(*args, **kwargs)
def assertRegex(self, *args, **kwargs):
return getattr(self, _assertRegex)(*args, **kwargs)
add_move(MovedModule("_dummy_thread", "dummy_thread"))
add_move(MovedModule("_thread", "thread"))

View File

@ -402,7 +402,13 @@ The version of six bundled with Django includes one extra function:
This replaces ``testcase.assertRaisesRegexp`` on Python 2, and
``testcase.assertRaisesRegex`` on Python 3. ``assertRaisesRegexp`` still
exists in current Python3 versions, but issues a warning.
exists in current Python 3 versions, but issues a warning.
.. function:: assertRegex(testcase, *args, **kwargs)
This replaces ``testcase.assertRegexpMatches`` on Python 2, and
``testcase.assertRegex`` on Python 3. ``assertRegexpMatches`` still
exists in current Python 3 versions, but issues a warning.
In addition to six' defaults moves, Django's version provides ``thread`` as

View File

@ -506,7 +506,7 @@ class SerializationTests(TestCase):
def assert_yaml_contains_datetime(self, yaml, dt):
# Depending on the yaml dumper, '!timestamp' might be absent
self.assertRegexpMatches(yaml,
six.assertRegex(self, yaml,
r"- fields: {dt: !(!timestamp)? '%s'}" % re.escape(dt))
def test_naive_datetime(self):

View File

@ -1263,7 +1263,7 @@ class AdminViewDeletedObjectsTest(TestCase):
"""
pattern = re.compile(br"""<li>Plot: <a href=".+/admin_views/plot/1/">World Domination</a>\s*<ul>\s*<li>Plot details: <a href=".+/admin_views/plotdetails/1/">almost finished</a>""")
response = self.client.get('/test_admin/admin/admin_views/villain/%s/delete/' % quote(1))
self.assertRegexpMatches(response.content, pattern)
six.assertRegex(self, response.content, pattern)
def test_cyclic(self):
"""

View File

@ -9,6 +9,7 @@ from django.core import management
from django.test import SimpleTestCase
from django.utils.encoding import force_text
from django.utils._os import upath
from django.utils import six
from django.utils.six import StringIO
@ -112,7 +113,7 @@ class BasicExtractorTests(ExtractorTests):
self.assertRaises(SyntaxError, management.call_command, 'makemessages', locale=LOCALE, extensions=['tpl'], verbosity=0)
with self.assertRaises(SyntaxError) as context_manager:
management.call_command('makemessages', locale=LOCALE, extensions=['tpl'], verbosity=0)
self.assertRegexpMatches(str(context_manager.exception),
six.assertRegex(self, str(context_manager.exception),
r'Translation blocks must not include other block tags: blocktrans \(file templates[/\\]template_with_error\.tpl, line 3\)'
)
# Check that the temporary file was cleaned up

View File

@ -1,6 +1,7 @@
import re
from django import get_version
from django.utils import six
from django.utils.unittest import TestCase
class VersionTests(TestCase):
@ -10,7 +11,7 @@ class VersionTests(TestCase):
# This will return a different result when it's run within or outside
# of a git clone: 1.4.devYYYYMMDDHHMMSS or 1.4.
ver_string = get_version(ver_tuple)
self.assertRegexpMatches(ver_string, r'1\.4(\.dev\d+)?')
six.assertRegex(self, ver_string, r'1\.4(\.dev\d+)?')
def test_releases(self):
tuples_to_strings = (