summaryrefslogtreecommitdiff
path: root/tests/deprecation/tests.py
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/tests.py
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/deprecation/tests.py')
-rw-r--r--tests/deprecation/tests.py52
1 files changed, 31 insertions, 21 deletions
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)