diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-04-29 16:00:58 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-04-29 16:00:58 +0200 |
commit | db6dc8b08829bb6c8d1422869608588592f370b6 (patch) | |
tree | 0f36419bc76078d0c06e927adb90679119ff2921 /test | |
parent | 5a8aab5d447343480b28ee760bce44f03f30f3d5 (diff) | |
parent | fd1bd30b6d485980157dfeac09b06dfa0149a73f (diff) | |
download | logilab-common-db6dc8b08829bb6c8d1422869608588592f370b6.tar.gz |
backport stable
Diffstat (limited to 'test')
-rw-r--r-- | test/unittest_deprecation.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/unittest_deprecation.py b/test/unittest_deprecation.py index 7596317..ad268e8 100644 --- a/test/unittest_deprecation.py +++ b/test/unittest_deprecation.py @@ -78,5 +78,66 @@ class RawInputTC(TestCase): self.assertEqual(self.messages, ['object moving_target has been moved to module data.deprecation']) + def test_deprecated_manager(self): + deprecator = deprecation.DeprecationManager("module_name") + deprecator.compatibility('1.3') + # This warn should be printed. + deprecator.warn('1.1', "Major deprecation message.", 1) + deprecator.warn('1.1') + + @deprecator.deprecated('1.2', 'Major deprecation message.') + def any_func(): + pass + any_func() + + @deprecator.deprecated('1.2') + def other_func(): + pass + other_func() + + self.assertListEqual(self.messages, + ['[module_name 1.1] Major deprecation message.', + '[module_name 1.1] ', + '[module_name 1.2] Major deprecation message.', + '[module_name 1.2] The function "other_func" is deprecated']) + + def test_class_deprecated_manager(self): + deprecator = deprecation.DeprecationManager("module_name") + deprecator.compatibility('1.3') + class AnyClass: + __metaclass__ = deprecator.class_deprecated('1.2') + AnyClass() + self.assertEqual(self.messages, + ['[module_name 1.2] AnyClass is deprecated']) + + + def test_deprecated_manager_noprint(self): + deprecator = deprecation.DeprecationManager("module_name") + deprecator.compatibility('1.3') + # This warn should not be printed. + deprecator.warn('1.3', "Minor deprecation message.", 1) + + @deprecator.deprecated('1.3', 'Minor deprecation message.') + def any_func(): + pass + any_func() + + @deprecator.deprecated('1.20') + def other_func(): + pass + other_func() + + @deprecator.deprecated('1.4') + def other_func(): + pass + other_func() + + class AnyClass(object): + __metaclass__ = deprecator.class_deprecated((1,5)) + AnyClass() + + self.assertFalse(self.messages) + + if __name__ == '__main__': unittest_main() |