diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-01-26 13:47:11 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-01-26 13:47:11 +0100 |
| commit | 55416e235d95b6168034236e5b1cdc581d544cc6 (patch) | |
| tree | b8916535102c084f4e6af0bc5038f7a7ea6f30a1 | |
| parent | cebbec9b6122579a32a019a0449d4995dcf2191d (diff) | |
Fixed #19589 -- assertRegexpMatches is deprecated in Python 3.3.
| -rw-r--r-- | django/utils/six.py | 6 | ||||
| -rw-r--r-- | docs/topics/python3.txt | 8 | ||||
| -rw-r--r-- | tests/modeltests/timezones/tests.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/admin_views/tests.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/i18n/commands/extraction.py | 3 | ||||
| -rw-r--r-- | tests/regressiontests/version/tests.py | 3 |
6 files changed, 19 insertions, 5 deletions
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"""<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): """ diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py index ef711ec1bb..ac8d8c1a09 100644 --- a/tests/regressiontests/i18n/commands/extraction.py +++ b/tests/regressiontests/i18n/commands/extraction.py @@ -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 diff --git a/tests/regressiontests/version/tests.py b/tests/regressiontests/version/tests.py index 9b849ee4ba..64621a5cb6 100644 --- a/tests/regressiontests/version/tests.py +++ b/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 @@ 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 = ( |
