Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 55416e235d95b6168034236e5b1cdc581d544cc6 1 parent cebbec9
@aaugustin aaugustin authored
View
6 django/utils/six.py
@@ -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
8 docs/topics/python3.txt
@@ -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
2  tests/modeltests/timezones/tests.py
@@ -506,7 +506,7 @@ def assert_xml_contains_datetime(self, xml, dt):
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
2  tests/regressiontests/admin_views/tests.py
@@ -1263,7 +1263,7 @@ def test_nesting(self):
"""
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
3  tests/regressiontests/i18n/commands/extraction.py
@@ -9,6 +9,7 @@
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 @@ def test_extraction_error(self):
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
3  tests/regressiontests/version/tests.py
@@ -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 @@ def test_development(self):
# 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 = (
Please sign in to comment.
Something went wrong with that request. Please try again.