summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnkit Patel <ankit.patel@affirm.com>2018-12-03 16:48:47 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2018-12-07 23:04:14 -0500
commit7e8d9b0a2eb552adb6734c8570c63eb6ea2e3a7a (patch)
tree3bb9195a4dfedfd4f51ba446030b57f7130329e3 /tests
parent2762ada1f5e43075494d91c512f7c1ec68907258 (diff)
downloaddogpile-cache-7e8d9b0a2eb552adb6734c8570c63eb6ea2e3a7a.tar.gz
Preserve function signatures within decorated functions
The ``decorator`` module is now used when creating function decorators within :meth:`.CacheRegion.cache_on_arguments` and :meth:`.CacheRegion.cache_multi_on_arguments` so that function signatures are preserved. Pull request courtesy ankitpatel96. Additionally adds a small performance enhancement which is to avoid internally creating a ``@wraps()`` decorator for the creator function on every get operation, by allowing the arguments to the creator be passed separately to :meth:`.CacheRegion.get_or_create`. Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #137 Change-Id: Id1008da596445770cfbf19402d38169aa60678b0 Pull-request: https://github.com/sqlalchemy/dogpile.cache/pull/136
Diffstat (limited to 'tests')
-rw-r--r--tests/cache/test_decorator.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/cache/test_decorator.py b/tests/cache/test_decorator.py
index 01d7bf4..d82b1e8 100644
--- a/tests/cache/test_decorator.py
+++ b/tests/cache/test_decorator.py
@@ -586,3 +586,27 @@ class CacheDecoratorTest(_GenericBackendFixture, TestCase):
generate.set({7: 18, 10: 15})
eq_(generate(2, 7, 10), ['2 5', 18, 15])
+
+ def test_cache_preserve_sig(self):
+ reg = self._region()
+
+ def func(a, b, c=True, *args, **kwargs):
+ return None
+
+ signature = compat.inspect_getargspec(func)
+ cached_func = reg.cache_on_arguments()(func)
+ cached_signature = compat.inspect_getargspec(cached_func)
+
+ self.assertEqual(signature, cached_signature)
+
+ def test_cache_multi_preserve_sig(self):
+ reg = self._region()
+
+ def func(a, b, c=True, *args, **kwargs):
+ return None, None
+
+ signature = compat.inspect_getargspec(func)
+ cached_func = reg.cache_multi_on_arguments()(func)
+ cached_signature = compat.inspect_getargspec(cached_func)
+
+ self.assertEqual(signature, cached_signature)