diff options
author | Laurent Peuch <cortex@worlddomination.be> | 2020-05-20 20:47:31 +0200 |
---|---|---|
committer | Laurent Peuch <cortex@worlddomination.be> | 2020-05-20 20:47:31 +0200 |
commit | be136de1bc2cbf3e9108c8b6f9d0e233339988ce (patch) | |
tree | 1ba40b681491acfdf9c92848c3858f812a9f3a4f /test | |
parent | cfc6d86916a4080d7ca805d62887977b80b86b3f (diff) | |
download | logilab-common-be136de1bc2cbf3e9108c8b6f9d0e233339988ce.tar.gz |
[deprecation/fix] implement lazy_wraps, a lazy version of functools.wraps for LazyObject
functools.wraps was breaking the behavior of LazyObject because it tried to
access attributes of the LazyObject that triggers an import which could
sometime fails in this situation where some modules are marked as deprecated
but aren't imported yet.
For example see https://forge.extranet.logilab.fr/cubicweb/cubicweb/blob/3.24.0/cubicweb/schemas/__init__.py#L51
Diffstat (limited to 'test')
-rw-r--r-- | test/test_deprecation.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/test_deprecation.py b/test/test_deprecation.py index 65ef8fd..3cbce9c 100644 --- a/test/test_deprecation.py +++ b/test/test_deprecation.py @@ -20,6 +20,7 @@ import warnings from logilab.common.testlib import TestCase, unittest_main +from logilab.common.modutils import LazyObject from logilab.common import deprecation @@ -128,6 +129,20 @@ class RawInputTC(TestCase): ], ) + def test_deprecated_decorator_bad_lazyobject(self): + # this should not raised an ImportationError + deprecation.deprecated("foobar")(LazyObject("cubes.localperms", "xperm")) + + # with or without giving it a message (because it shouldn't access + # attributes of the wrapped object before the object is called) + deprecation.deprecated()(LazyObject("cubes.localperms", "xperm")) + + # all of this is done because of the magical way LazyObject is working + # and that sometime CW used to use it to do fake import on deprecated + # modules to raise a warning if they were used but not importing them + # by default. + # See: https://forge.extranet.logilab.fr/cubicweb/cubicweb/blob/3.24.0/cubicweb/schemas/__init__.py#L51 # noqa + def test_attribute_renamed(self): @deprecation.attribute_renamed(old_name="old", new_name="new") class SomeClass: |