summaryrefslogtreecommitdiff
path: root/tests/deprecation
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2022-02-03 20:24:19 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-07 20:37:05 +0100
commit9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch)
treef0506b668a013d0063e5fba3dbf4863b466713ba /tests/deprecation
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
downloaddjango-9c19aff7c7561e3a82978a272ecdaad40dda5c00.tar.gz
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/deprecation')
-rw-r--r--tests/deprecation/test_csrf_cookie_masked.py8
-rw-r--r--tests/deprecation/test_middleware_mixin.py26
-rw-r--r--tests/deprecation/test_use_l10n.py10
-rw-r--r--tests/deprecation/tests.py52
4 files changed, 54 insertions, 42 deletions
diff --git a/tests/deprecation/test_csrf_cookie_masked.py b/tests/deprecation/test_csrf_cookie_masked.py
index 74592fd0b7..d06feb9e47 100644
--- a/tests/deprecation/test_csrf_cookie_masked.py
+++ b/tests/deprecation/test_csrf_cookie_masked.py
@@ -15,15 +15,15 @@ class CsrfCookieMaskedDeprecationTests(SimpleTestCase):
pass
def test_settings_init_warning(self):
- settings_module = ModuleType('fake_settings_module')
+ settings_module = ModuleType("fake_settings_module")
settings_module.USE_TZ = False
settings_module.CSRF_COOKIE_MASKED = True
- sys.modules['fake_settings_module'] = settings_module
+ sys.modules["fake_settings_module"] = settings_module
try:
with self.assertRaisesMessage(RemovedInDjango50Warning, self.msg):
- Settings('fake_settings_module')
+ Settings("fake_settings_module")
finally:
- del sys.modules['fake_settings_module']
+ del sys.modules["fake_settings_module"]
def test_access(self):
# Warning is not raised on access.
diff --git a/tests/deprecation/test_middleware_mixin.py b/tests/deprecation/test_middleware_mixin.py
index cf9fbda35c..060c2f5f35 100644
--- a/tests/deprecation/test_middleware_mixin.py
+++ b/tests/deprecation/test_middleware_mixin.py
@@ -5,7 +5,8 @@ from asgiref.sync import async_to_sync
from django.contrib.admindocs.middleware import XViewMiddleware
from django.contrib.auth.middleware import (
- AuthenticationMiddleware, RemoteUserMiddleware,
+ AuthenticationMiddleware,
+ RemoteUserMiddleware,
)
from django.contrib.flatpages.middleware import FlatpageFallbackMiddleware
from django.contrib.messages.middleware import MessageMiddleware
@@ -16,12 +17,12 @@ from django.db import connection
from django.http.request import HttpRequest
from django.http.response import HttpResponse
from django.middleware.cache import (
- CacheMiddleware, FetchFromCacheMiddleware, UpdateCacheMiddleware,
+ CacheMiddleware,
+ FetchFromCacheMiddleware,
+ UpdateCacheMiddleware,
)
from django.middleware.clickjacking import XFrameOptionsMiddleware
-from django.middleware.common import (
- BrokenLinkEmailsMiddleware, CommonMiddleware,
-)
+from django.middleware.common import BrokenLinkEmailsMiddleware, CommonMiddleware
from django.middleware.csrf import CsrfViewMiddleware
from django.middleware.gzip import GZipMiddleware
from django.middleware.http import ConditionalGetMiddleware
@@ -64,25 +65,25 @@ class MiddlewareMixinTests(SimpleTestCase):
self.assertEqual(
repr(MiddlewareMixin(GetResponse())),
- '<MiddlewareMixin get_response=GetResponse>',
+ "<MiddlewareMixin get_response=GetResponse>",
)
self.assertEqual(
repr(MiddlewareMixin(get_response)),
- '<MiddlewareMixin get_response='
- 'MiddlewareMixinTests.test_repr.<locals>.get_response>',
+ "<MiddlewareMixin get_response="
+ "MiddlewareMixinTests.test_repr.<locals>.get_response>",
)
self.assertEqual(
repr(CsrfViewMiddleware(GetResponse())),
- '<CsrfViewMiddleware get_response=GetResponse>',
+ "<CsrfViewMiddleware get_response=GetResponse>",
)
self.assertEqual(
repr(CsrfViewMiddleware(get_response)),
- '<CsrfViewMiddleware get_response='
- 'MiddlewareMixinTests.test_repr.<locals>.get_response>',
+ "<CsrfViewMiddleware get_response="
+ "MiddlewareMixinTests.test_repr.<locals>.get_response>",
)
def test_passing_explicit_none(self):
- msg = 'get_response must be provided.'
+ msg = "get_response must be provided."
for middleware in self.middlewares:
with self.subTest(middleware=middleware):
with self.assertRaisesMessage(ValueError, msg):
@@ -112,6 +113,7 @@ class MiddlewareMixinTests(SimpleTestCase):
the sync_to_async thread_sensitive flag enabled, so that database
operations use the correct thread and connection.
"""
+
def request_lifecycle():
"""Fake request_started/request_finished."""
return (threading.get_ident(), id(connection))
diff --git a/tests/deprecation/test_use_l10n.py b/tests/deprecation/test_use_l10n.py
index 0744e34ea0..c654a0466a 100644
--- a/tests/deprecation/test_use_l10n.py
+++ b/tests/deprecation/test_use_l10n.py
@@ -17,16 +17,16 @@ class DeprecationTests(TestCase):
pass
def test_settings_init_warning(self):
- settings_module = ModuleType('fake_settings_module')
- settings_module.SECRET_KEY = 'foo'
+ settings_module = ModuleType("fake_settings_module")
+ settings_module.SECRET_KEY = "foo"
settings_module.USE_TZ = True
settings_module.USE_L10N = False
- sys.modules['fake_settings_module'] = settings_module
+ sys.modules["fake_settings_module"] = settings_module
try:
with self.assertRaisesMessage(RemovedInDjango50Warning, self.msg):
- Settings('fake_settings_module')
+ Settings("fake_settings_module")
finally:
- del sys.modules['fake_settings_module']
+ del sys.modules["fake_settings_module"]
def test_access_warning(self):
with self.assertRaisesMessage(RemovedInDjango50Warning, self.msg):
diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py
index 0d2ea298d3..eae217bfb3 100644
--- a/tests/deprecation/tests.py
+++ b/tests/deprecation/tests.py
@@ -2,14 +2,14 @@ import warnings
from django.test import SimpleTestCase
from django.utils.deprecation import (
- DeprecationInstanceCheck, RemovedInNextVersionWarning, RenameMethodsBase,
+ DeprecationInstanceCheck,
+ RemovedInNextVersionWarning,
+ RenameMethodsBase,
)
class RenameManagerMethods(RenameMethodsBase):
- renamed_methods = (
- ('old', 'new', DeprecationWarning),
- )
+ renamed_methods = (("old", "new", DeprecationWarning),)
class RenameMethodsTests(SimpleTestCase):
@@ -23,8 +23,9 @@ class RenameMethodsTests(SimpleTestCase):
Ensure a warning is raised upon class definition to suggest renaming
the faulty method.
"""
- msg = '`Manager.old` method should be renamed `new`.'
+ msg = "`Manager.old` method should be renamed `new`."
with self.assertWarnsMessage(DeprecationWarning, msg):
+
class Manager(metaclass=RenameManagerMethods):
def old(self):
pass
@@ -33,17 +34,19 @@ class RenameMethodsTests(SimpleTestCase):
"""
Ensure `old` complains and not `new` when only `new` is defined.
"""
+
class Manager(metaclass=RenameManagerMethods):
def new(self):
pass
+
manager = Manager()
with warnings.catch_warnings(record=True) as recorded:
- warnings.simplefilter('always')
+ warnings.simplefilter("always")
manager.new()
self.assertEqual(len(recorded), 0)
- msg = '`Manager.old` is deprecated, use `new` instead.'
+ msg = "`Manager.old` is deprecated, use `new` instead."
with self.assertWarnsMessage(DeprecationWarning, msg):
manager.old()
@@ -51,19 +54,21 @@ class RenameMethodsTests(SimpleTestCase):
"""
Ensure `old` complains when only `old` is defined.
"""
- msg = '`Manager.old` method should be renamed `new`.'
+ msg = "`Manager.old` method should be renamed `new`."
with self.assertWarnsMessage(DeprecationWarning, msg):
+
class Manager(metaclass=RenameManagerMethods):
def old(self):
pass
+
manager = Manager()
with warnings.catch_warnings(record=True) as recorded:
- warnings.simplefilter('always')
+ warnings.simplefilter("always")
manager.new()
self.assertEqual(len(recorded), 0)
- msg = '`Manager.old` is deprecated, use `new` instead.'
+ msg = "`Manager.old` is deprecated, use `new` instead."
with self.assertWarnsMessage(DeprecationWarning, msg):
manager.old()
@@ -72,23 +77,25 @@ class RenameMethodsTests(SimpleTestCase):
Ensure the correct warnings are raised when a class that didn't rename
`old` subclass one that did.
"""
+
class Renamed(metaclass=RenameManagerMethods):
def new(self):
pass
- msg = '`Deprecated.old` method should be renamed `new`.'
+ msg = "`Deprecated.old` method should be renamed `new`."
with self.assertWarnsMessage(DeprecationWarning, msg):
+
class Deprecated(Renamed):
def old(self):
super().old()
deprecated = Deprecated()
- msg = '`Renamed.old` is deprecated, use `new` instead.'
+ msg = "`Renamed.old` is deprecated, use `new` instead."
with self.assertWarnsMessage(DeprecationWarning, msg):
deprecated.new()
- msg = '`Deprecated.old` is deprecated, use `new` instead.'
+ msg = "`Deprecated.old` is deprecated, use `new` instead."
with self.assertWarnsMessage(DeprecationWarning, msg):
deprecated.old()
@@ -97,8 +104,9 @@ class RenameMethodsTests(SimpleTestCase):
Ensure the correct warnings are raised when a class that renamed
`old` subclass one that didn't.
"""
- msg = '`Deprecated.old` method should be renamed `new`.'
+ msg = "`Deprecated.old` method should be renamed `new`."
with self.assertWarnsMessage(DeprecationWarning, msg):
+
class Deprecated(metaclass=RenameManagerMethods):
def old(self):
pass
@@ -110,11 +118,11 @@ class RenameMethodsTests(SimpleTestCase):
renamed = Renamed()
with warnings.catch_warnings(record=True) as recorded:
- warnings.simplefilter('always')
+ warnings.simplefilter("always")
renamed.new()
self.assertEqual(len(recorded), 0)
- msg = '`Renamed.old` is deprecated, use `new` instead.'
+ msg = "`Renamed.old` is deprecated, use `new` instead."
with self.assertWarnsMessage(DeprecationWarning, msg):
renamed.old()
@@ -124,6 +132,7 @@ class RenameMethodsTests(SimpleTestCase):
class that renamed `old` and mixins that may or may not have renamed
`new`.
"""
+
class Renamed(metaclass=RenameManagerMethods):
def new(self):
pass
@@ -136,18 +145,19 @@ class RenameMethodsTests(SimpleTestCase):
def old(self):
super().old()
- msg = '`DeprecatedMixin.old` method should be renamed `new`.'
+ msg = "`DeprecatedMixin.old` method should be renamed `new`."
with self.assertWarnsMessage(DeprecationWarning, msg):
+
class Deprecated(DeprecatedMixin, RenamedMixin, Renamed):
pass
deprecated = Deprecated()
- msg = '`RenamedMixin.old` is deprecated, use `new` instead.'
+ msg = "`RenamedMixin.old` is deprecated, use `new` instead."
with self.assertWarnsMessage(DeprecationWarning, msg):
deprecated.new()
- msg = '`DeprecatedMixin.old` is deprecated, use `new` instead.'
+ msg = "`DeprecatedMixin.old` is deprecated, use `new` instead."
with self.assertWarnsMessage(DeprecationWarning, msg):
deprecated.old()
@@ -155,9 +165,9 @@ class RenameMethodsTests(SimpleTestCase):
class DeprecationInstanceCheckTest(SimpleTestCase):
def test_warning(self):
class Manager(metaclass=DeprecationInstanceCheck):
- alternative = 'fake.path.Foo'
+ alternative = "fake.path.Foo"
deprecation_warning = RemovedInNextVersionWarning
- msg = '`Manager` is deprecated, use `fake.path.Foo` instead.'
+ msg = "`Manager` is deprecated, use `fake.path.Foo` instead."
with self.assertWarnsMessage(RemovedInNextVersionWarning, msg):
isinstance(object, Manager)