summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2012-11-30 11:26:36 +0100
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2012-11-30 11:26:36 +0100
commita268e0b064fbef6f45a6fa3cc73b52fd38891f41 (patch)
tree3425ff6a33ef23dbaae1bd3bc805da519183e8b2
parent154e16348a2833fc5a0647caedac51644f80e5d4 (diff)
downloadlogilab-common-a268e0b064fbef6f45a6fa3cc73b52fd38891f41.tar.gz
[test, deprecation] update tests so we actually test something
-rw-r--r--deprecation.py2
-rw-r--r--test/unittest_deprecation.py22
2 files changed, 19 insertions, 5 deletions
diff --git a/deprecation.py b/deprecation.py
index c14bd2a..5e2f813 100644
--- a/deprecation.py
+++ b/deprecation.py
@@ -1,4 +1,4 @@
-# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of logilab-common.
diff --git a/test/unittest_deprecation.py b/test/unittest_deprecation.py
index d697250..7596317 100644
--- a/test/unittest_deprecation.py
+++ b/test/unittest_deprecation.py
@@ -1,4 +1,4 @@
-# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of logilab-common.
@@ -28,10 +28,16 @@ class RawInputTC(TestCase):
# XXX with 2.6 we could test warnings
# http://docs.python.org/library/warnings.html#testing-warnings
# instead we just make sure it does not crash
+
+ def mock_warn(self, *args, **kwargs):
+ self.messages.append(args[0])
+
def setUp(self):
- warnings.simplefilter("ignore")
+ self.messages = []
+ deprecation.warn = self.mock_warn
+
def tearDown(self):
- warnings.simplefilter("default")
+ deprecation.warn = warnings.warn
def mk_func(self):
def any_func():
@@ -41,28 +47,36 @@ class RawInputTC(TestCase):
def test_class_deprecated(self):
class AnyClass:
__metaclass__ = deprecation.class_deprecated
+ AnyClass()
+ self.assertEqual(self.messages,
+ ['AnyClass is deprecated'])
def test_deprecated_func(self):
any_func = deprecation.deprecated()(self.mk_func())
any_func()
any_func = deprecation.deprecated('message')(self.mk_func())
any_func()
+ self.assertEqual(self.messages,
+ ['The function "any_func" is deprecated', 'message'])
def test_deprecated_decorator(self):
@deprecation.deprecated()
def any_func():
pass
any_func()
-
@deprecation.deprecated('message')
def any_func():
pass
any_func()
+ self.assertEqual(self.messages,
+ ['The function "any_func" is deprecated', 'message'])
def test_moved(self):
module = 'data.deprecation'
any_func = deprecation.moved(module, 'moving_target')
any_func()
+ self.assertEqual(self.messages,
+ ['object moving_target has been moved to module data.deprecation'])
if __name__ == '__main__':
unittest_main()