Commit 55416e23 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

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

parent cebbec9b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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"))
+7 −1
Original line number Diff line number Diff line
@@ -404,6 +404,12 @@ The version of six bundled with Django includes one extra function:
    ``testcase.assertRaisesRegex`` on Python 3. ``assertRaisesRegexp`` still
    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
``_thread`` and ``dummy_thread`` as ``_dummy_thread``.
+1 −1
Original line number Diff line number Diff line
@@ -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):
+1 −1
Original line number Diff line number Diff line
@@ -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):
        """
+2 −1
Original line number Diff line number Diff line
@@ -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
Loading