Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH(TST): test workaround for decorating static and class methods #40

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/fscacher/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,54 @@ def f3(): # nesting call into f2
assert f3() == 3


#
# @classmethod and @staticmethod do not "decorate well enough":
# Somehow joblib inspection of them ends up with the instances
# of their classes and not underlying decorated methods.
#

#
# For classmethod to be "fscached" we would need to have class
# re-importable, thus the test class (and cache) are defined at
# module level
#
_public_cache = PersistentCache(name=_cache_name)


class _public_klass(object):
counter = 0
@_public_cache.memoize
# @classmethod
def f(cls):
cls.counter += 1
return cls.counter


_public_klass.f = classmethod(_public_klass.f)


def test_memoize_classmethod(cache):
for _ in range(3):
assert _public_klass.f() == 1
_public_cache.clear()


def test_memoize_staticmethod(cache):

mem = []

class klass(object):
@cache.memoize
# @staticmethod
def f():
mem.append(len(mem))
return len(mem)
klass.f = staticmethod(klass.f)

for _ in range(2):
assert klass.f() == 1


def test_memoize_path(cache, tmp_path):
calls = []

Expand Down