From 8f56c90309db2353470a03650ee56cec5215ed44 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Thu, 16 Apr 2020 03:56:24 +0200 Subject: add depreciation.attribute_renamed --- test/unittest_deprecation.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test') diff --git a/test/unittest_deprecation.py b/test/unittest_deprecation.py index d82c2bc..7778325 100644 --- a/test/unittest_deprecation.py +++ b/test/unittest_deprecation.py @@ -71,6 +71,28 @@ class RawInputTC(TestCase): self.assertEqual(self.messages, ['The function "any_func" is deprecated', 'message']) + def test_attribute_renamed(self): + @deprecation.attribute_renamed(old_name="old", new_name="new") + class SomeClass: + def __init__(self): + self.new = 42 + + some_class = SomeClass() + self.assertEqual(some_class.old, some_class.new) + self.assertEqual(self.messages, + ['SomeClass.old has been renamed and is deprecated, use SomeClass.new ' + 'instead']) + + some_class.old = 43 + self.assertEqual(some_class.old, 43) + self.assertEqual(some_class.old, some_class.new) + + self.assertTrue(hasattr(some_class, "new")) + self.assertTrue(hasattr(some_class, "old")) + del some_class.old + self.assertFalse(hasattr(some_class, "new")) + self.assertFalse(hasattr(some_class, "old")) + def test_renamed(self): def any_func(): pass -- cgit v1.2.1