diff --git a/django/utils/six.py b/django/utils/six.py index 73846358a1..b93dc5b164 100644 --- a/django/utils/six.py +++ b/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")) diff --git a/docs/topics/python3.txt b/docs/topics/python3.txt index b44c180d7f..b1f3fa3277 100644 --- a/docs/topics/python3.txt +++ b/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 diff --git a/tests/modeltests/timezones/tests.py b/tests/modeltests/timezones/tests.py index 29a490e3fb..4ae6bbd6a8 100644 --- a/tests/modeltests/timezones/tests.py +++ b/tests/modeltests/timezones/tests.py @@ -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): diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index e886078ae5..d7d01e6a92 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -1263,7 +1263,7 @@ class AdminViewDeletedObjectsTest(TestCase): """ pattern = re.compile(br"""
  • Plot: World Domination\s*