From 232181d1c5307d9af5fc292682661e91439a9289 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 22 Mar 2014 21:08:59 +0100 Subject: [PATCH] Advanced deprecation warnings for 1.8. --- django/test/utils.py | 8 ++++---- django/utils/deprecation.py | 10 +++++----- tests/cache/tests.py | 4 ++-- tests/generic_inline_admin/tests.py | 3 ++- tests/queries/tests.py | 3 ++- tests/runtests.py | 4 ++-- tests/utils_tests/test_datastructures.py | 6 +++--- tests/utils_tests/test_module_loading.py | 4 ++-- tests/utils_tests/test_tzinfo.py | 4 ++-- 9 files changed, 24 insertions(+), 22 deletions(-) diff --git a/django/test/utils.py b/django/test/utils.py index c8d9aa1dba..48524244cc 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -18,7 +18,7 @@ from django.template import Template, loader, TemplateDoesNotExist from django.template.loaders import cached from django.test.signals import template_rendered, setting_changed from django.utils import six -from django.utils.deprecation import RemovedInDjango18Warning, RemovedInDjango19Warning +from django.utils.deprecation import RemovedInDjango19Warning, RemovedInDjango20Warning from django.utils.encoding import force_str from django.utils.translation import deactivate @@ -458,7 +458,7 @@ class CaptureQueriesContext(object): class IgnoreDeprecationWarningsMixin(object): - warning_classes = [RemovedInDjango18Warning] + warning_classes = [RemovedInDjango19Warning] def setUp(self): super(IgnoreDeprecationWarningsMixin, self).setUp() @@ -473,11 +473,11 @@ class IgnoreDeprecationWarningsMixin(object): class IgnorePendingDeprecationWarningsMixin(IgnoreDeprecationWarningsMixin): - warning_classes = [RemovedInDjango19Warning] + warning_classes = [RemovedInDjango20Warning] class IgnoreAllDeprecationWarningsMixin(IgnoreDeprecationWarningsMixin): - warning_classes = [RemovedInDjango19Warning, RemovedInDjango18Warning] + warning_classes = [RemovedInDjango20Warning, RemovedInDjango19Warning] @contextmanager diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py index a9a1dcfbe2..69f991c3d1 100644 --- a/django/utils/deprecation.py +++ b/django/utils/deprecation.py @@ -2,15 +2,15 @@ import inspect import warnings +class RemovedInDjango20Warning(DeprecationWarning): + pass + + class RemovedInDjango19Warning(PendingDeprecationWarning): pass -class RemovedInDjango18Warning(DeprecationWarning): - pass - - -RemovedInNextVersionWarning = RemovedInDjango18Warning +RemovedInNextVersionWarning = RemovedInDjango19Warning class warn_about_renamed_method(object): diff --git a/tests/cache/tests.py b/tests/cache/tests.py index a5a10c68cf..e6bde06842 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -26,7 +26,7 @@ from django.middleware.cache import (FetchFromCacheMiddleware, from django.template import Template from django.template.response import TemplateResponse from django.test import TestCase, TransactionTestCase, RequestFactory, override_settings -from django.test.utils import IgnorePendingDeprecationWarningsMixin +from django.test.utils import IgnoreDeprecationWarningsMixin from django.utils import six from django.utils import timezone from django.utils import translation @@ -1176,7 +1176,7 @@ class CustomCacheKeyValidationTests(TestCase): } } ) -class GetCacheTests(IgnorePendingDeprecationWarningsMixin, TestCase): +class GetCacheTests(IgnoreDeprecationWarningsMixin, TestCase): def test_simple(self): from django.core.cache import caches, get_cache diff --git a/tests/generic_inline_admin/tests.py b/tests/generic_inline_admin/tests.py index b223c98298..3dcc4db768 100644 --- a/tests/generic_inline_admin/tests.py +++ b/tests/generic_inline_admin/tests.py @@ -9,6 +9,7 @@ from django.contrib.contenttypes.forms import generic_inlineformset_factory from django.forms.formsets import DEFAULT_MAX_NUM from django.forms.models import ModelForm from django.test import TestCase, override_settings +from django.utils.deprecation import RemovedInDjango19Warning # local test models from .admin import MediaInline, MediaPermanentInline @@ -376,7 +377,7 @@ class GenericInlineModelAdminTest(TestCase): # Verify that the deprecation warning was triggered when get_formsets was called # This verifies that we called that method. self.assertEqual(len(w), 1) - self.assertTrue(issubclass(w[0].category, PendingDeprecationWarning)) + self.assertTrue(issubclass(w[0].category, RemovedInDjango19Warning)) class EpisodeAdmin(admin.ModelAdmin): inlines = [ diff --git a/tests/queries/tests.py b/tests/queries/tests.py index a21b19a100..ddf2febc42 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -14,6 +14,7 @@ from django.db.models.sql.where import WhereNode, EverythingNode, NothingNode from django.db.models.sql.datastructures import EmptyResultSet from django.test import TestCase, skipUnlessDBFeature from django.test.utils import str_prefix, CaptureQueriesContext +from django.utils.deprecation import RemovedInDjango19Warning from django.utils import six from .models import ( @@ -1149,7 +1150,7 @@ class Queries1Tests(BaseQuerysetTest): ['', '', '', '', ''] ) self.assertEqual(len(w), 1) - self.assertTrue(issubclass(w[0].category, PendingDeprecationWarning)) + self.assertTrue(issubclass(w[0].category, RemovedInDjango19Warning)) class Queries2Tests(TestCase): diff --git a/tests/runtests.py b/tests/runtests.py index 9d313d5de8..e852346fc1 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -11,13 +11,13 @@ import warnings import django from django import contrib -from django.utils.deprecation import RemovedInDjango18Warning, RemovedInDjango19Warning +from django.utils.deprecation import RemovedInDjango19Warning, RemovedInDjango20Warning from django.utils._os import upath from django.utils import six warnings.simplefilter("default", RemovedInDjango19Warning) -warnings.simplefilter("default", RemovedInDjango18Warning) +warnings.simplefilter("default", RemovedInDjango20Warning) CONTRIB_MODULE_PATH = 'django.contrib' diff --git a/tests/utils_tests/test_datastructures.py b/tests/utils_tests/test_datastructures.py index 212e96034e..295b3650d6 100644 --- a/tests/utils_tests/test_datastructures.py +++ b/tests/utils_tests/test_datastructures.py @@ -6,13 +6,13 @@ import copy import pickle from django.test import SimpleTestCase -from django.test.utils import IgnorePendingDeprecationWarningsMixin +from django.test.utils import IgnoreDeprecationWarningsMixin from django.utils.datastructures import (DictWrapper, ImmutableList, MultiValueDict, MultiValueDictKeyError, MergeDict, SortedDict) from django.utils import six -class SortedDictTests(IgnorePendingDeprecationWarningsMixin, SimpleTestCase): +class SortedDictTests(IgnoreDeprecationWarningsMixin, SimpleTestCase): def setUp(self): super(SortedDictTests, self).setUp() self.d1 = SortedDict() @@ -136,7 +136,7 @@ class SortedDictTests(IgnorePendingDeprecationWarningsMixin, SimpleTestCase): self.assertEqual(list(reversed(self.d2)), [7, 0, 9, 1]) -class MergeDictTests(IgnorePendingDeprecationWarningsMixin, SimpleTestCase): +class MergeDictTests(IgnoreDeprecationWarningsMixin, SimpleTestCase): def test_simple_mergedict(self): d1 = {'chris': 'cool', 'camri': 'cute', 'cotton': 'adorable', diff --git a/tests/utils_tests/test_module_loading.py b/tests/utils_tests/test_module_loading.py index 48ba9c15ff..9cdaf8df09 100644 --- a/tests/utils_tests/test_module_loading.py +++ b/tests/utils_tests/test_module_loading.py @@ -8,7 +8,7 @@ from zipimport import zipimporter from django.core.exceptions import ImproperlyConfigured from django.test import SimpleTestCase, modify_settings -from django.test.utils import IgnorePendingDeprecationWarningsMixin, extend_sys_path +from django.test.utils import IgnoreDeprecationWarningsMixin, extend_sys_path from django.utils import six from django.utils.deprecation import RemovedInDjango19Warning from django.utils.module_loading import (autodiscover_modules, import_by_path, import_string, @@ -110,7 +110,7 @@ class EggLoader(unittest.TestCase): self.assertRaises(ImportError, import_module, 'egg_module.sub1.sub2.no_such_module') -class ModuleImportTestCase(IgnorePendingDeprecationWarningsMixin, unittest.TestCase): +class ModuleImportTestCase(IgnoreDeprecationWarningsMixin, unittest.TestCase): def test_import_by_path(self): cls = import_by_path('django.utils.module_loading.import_by_path') self.assertEqual(cls, import_by_path) diff --git a/tests/utils_tests/test_tzinfo.py b/tests/utils_tests/test_tzinfo.py index 820667eba4..1b007f5f76 100644 --- a/tests/utils_tests/test_tzinfo.py +++ b/tests/utils_tests/test_tzinfo.py @@ -6,7 +6,7 @@ import time import unittest import warnings -from django.test.utils import IgnorePendingDeprecationWarningsMixin +from django.test.utils import IgnoreDeprecationWarningsMixin from django.utils.deprecation import RemovedInDjango19Warning @@ -16,7 +16,7 @@ with warnings.catch_warnings(): from django.utils.tzinfo import FixedOffset, LocalTimezone -class TzinfoTests(IgnorePendingDeprecationWarningsMixin, unittest.TestCase): +class TzinfoTests(IgnoreDeprecationWarningsMixin, unittest.TestCase): @classmethod def setUpClass(cls):