summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deprecation.py15
-rw-r--r--test/unittest_deprecation.py16
-rw-r--r--testlib.py17
3 files changed, 21 insertions, 27 deletions
diff --git a/deprecation.py b/deprecation.py
index f3c3d76..154ae7c 100644
--- a/deprecation.py
+++ b/deprecation.py
@@ -35,7 +35,7 @@ def class_renamed(old_name, new_class, message=None):
clsdict['__deprecation_warning__'] = message
try:
# new-style class
- return deprecated(old_name, (new_class,), clsdict)
+ return class_deprecated(old_name, (new_class,), clsdict)
except (NameError, TypeError):
# old-style class
class DeprecatedClass(new_class):
@@ -72,17 +72,8 @@ def deprecated(reason=None):
return wrapped
return deprecated_decorator
+@deprecated('replace deprecated_function(f,m) with deprecated(m)(f)')
def deprecated_function(func, message=None):
- """Creates a function which fires a DeprecationWarning when used.
-
- For example, if <bar> is deprecated in favour of <foo>:
-
- >>> bar = deprecated_function(foo, 'bar is deprecated')
- >>> bar()
- sample.py:57: DeprecationWarning: bar is deprecated
- bar()
- >>>
- """
return deprecated(message)(func)
def moved(modpath, objname):
@@ -104,5 +95,5 @@ def moved(modpath, objname):
return getattr(m, objname)(*args, **kwargs)
return callnew
-obsolete = deprecated_function(deprecated, 'obsolete is deprecated, use deprecated instead')
+obsolete = deprecated('obsolete is deprecated, use deprecated instead')(deprecated)
diff --git a/test/unittest_deprecation.py b/test/unittest_deprecation.py
index f03585b..844cd18 100644
--- a/test/unittest_deprecation.py
+++ b/test/unittest_deprecation.py
@@ -18,23 +18,27 @@ class RawInputTC(TestCase):
def tearDown(self):
warnings.simplefilter("default")
+ def mk_func(self):
+ def any_func():
+ pass
+ return any_func
+
def test_class_deprecated(self):
class AnyClass:
__metaclass__ = deprecation.class_deprecated
- def test_deprecated_function(self):
- def any_func():
- pass
- any_func = deprecation.deprecated_function(any_func)
+ def test_deprecated_func(self):
+ any_func = deprecation.deprecated()(self.mk_func())
any_func()
- any_func = deprecation.deprecated_function(any_func,'message')
+ any_func = deprecation.deprecated('message')(self.mk_func())
any_func()
+
+ def test_deprecated_decorator(self):
@deprecation.deprecated_function
def any_func():
pass
any_func()
- def test_deprecated(self):
@deprecation.deprecated()
def any_func():
pass
diff --git a/testlib.py b/testlib.py
index 9882dfa..d795d92 100644
--- a/testlib.py
+++ b/testlib.py
@@ -56,8 +56,7 @@ except ImportError:
pass
test_support = TestSupport()
-from logilab.common.deprecation import class_renamed, deprecated_function, \
- deprecated
+from logilab.common.deprecation import class_renamed, deprecated
# pylint: disable-msg=W0622
from logilab.common.compat import set, enumerate, any, sorted
# pylint: enable-msg=W0622
@@ -1314,7 +1313,7 @@ succeeded test into", osp.join(os.getcwd(),FILE_RESTART)
"""mark a test as skipped for the <msg> reason"""
msg = msg or 'test was skipped'
raise TestSkipped(msg)
- skipped_test = deprecated_function(skip)
+ skipped_test = deprecated()(skip)
def assertIn(self, object, set):
"""assert <object> are in <set>"""
@@ -1440,18 +1439,18 @@ succeeded test into", osp.join(os.getcwd(),FILE_RESTART)
if msg is None:
msg = 'XML stream not well formed'
self.fail(msg)
- assertXMLValid = deprecated_function(assertXMLWellFormed,
- 'assertXMLValid renamed to more precise assertXMLWellFormed')
+ assertXMLValid = deprecated('assertXMLValid renamed to more precise '
+ 'assertXMLWellFormed')(assertXMLWellFormed)
+
def assertXMLStringWellFormed(self, xml_string, msg=None):
"""asserts the XML string is well-formed (no DTD conformance check)"""
stream = StringIO(xml_string)
self.assertXMLWellFormed(stream, msg)
- assertXMLStringValid = deprecated_function(
- assertXMLStringWellFormed,
- 'assertXMLStringValid renamed to more precise assertXMLStringWellFormed'
- )
+ assertXMLStringValid = deprecated(
+ 'assertXMLStringValid renamed to more precise assertXMLStringWellFormed')(
+ assertXMLStringWellFormed)
def assertXMLEqualsTuple(self, element, tup):
"""compare an ElementTree Element to a tuple formatted as follow: