diff options
author | Laurent Peuch <cortex@worlddomination.be> | 2020-08-26 17:26:22 +0200 |
---|---|---|
committer | Laurent Peuch <cortex@worlddomination.be> | 2020-08-26 17:26:22 +0200 |
commit | 894ccade059de8cab667187e93ea27daf7c75658 (patch) | |
tree | 678d77dd8e65679cb71d41a2663bf0a4a8a6c585 /test/test_deprecation.py | |
parent | ae769891236f32de955497b8e80b714a4d684d92 (diff) | |
download | logilab-common-894ccade059de8cab667187e93ea27daf7c75658.tar.gz |
fix(deprecation): stacked decorators breaks getting the real callable __name__ attribute
Diffstat (limited to 'test/test_deprecation.py')
-rw-r--r-- | test/test_deprecation.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/test_deprecation.py b/test/test_deprecation.py index 3cbce9c..2508208 100644 --- a/test/test_deprecation.py +++ b/test/test_deprecation.py @@ -143,6 +143,31 @@ class RawInputTC(TestCase): # by default. # See: https://forge.extranet.logilab.fr/cubicweb/cubicweb/blob/3.24.0/cubicweb/schemas/__init__.py#L51 # noqa + def test_lazy_wraps_function_name(self): + """ + Avoid conflict from lazy_wraps where __name__ isn't correctly set on + the wrapper from the wrapped and we end up with the name of the wrapper + instead of the wrapped. + + Like here it would fail if "check_kwargs" is the name of the new + function instead of new_function_name, this is because the wrapper in + argument_renamed is called check_kwargs and doesn't transmit the + __name__ of the wrapped (new_function_name) correctly. + """ + + @deprecation.argument_renamed(old_name="a", new_name="b") + def new_function_name(b): + pass + + old_function_name = deprecation.callable_renamed( + old_name="old_function_name", new_function=new_function_name + ) + old_function_name(None) + + assert "old_function_name" in self.messages[0] + assert "new_function_name" in self.messages[0] + assert "check_kwargs" not in self.messages[0] + def test_attribute_renamed(self): @deprecation.attribute_renamed(old_name="old", new_name="new") class SomeClass: |