Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasleitner committed Nov 4, 2024
1 parent d52050b commit 3bdd58e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions adcc/test_misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest

from adcc.misc import cached_member_function


class SomeClass:
def uncached(self, x=0, y=1):
return (x, y)

@cached_member_function
def cached(self, x=0, y=1):
return (x, y)


class TestCachedMemberFunction(unittest.TestCase):
def test_cache(self):
instance = SomeClass()
assert instance.uncached() is not instance.uncached()
res = instance.cached(0, 1)
assert res is instance.cached(0, 1)
assert res is instance.cached(0)
assert res is instance.cached()
assert res is instance.cached(x=0)
assert res is instance.cached(y=1)
assert res is instance.cached(y=1, x=0)

def test_wrappable(self):
def kwargs_only(self, *, kwarg):
pass

def kwargs(self, **kwargs):
pass

def positional_only(self, /, arg):
pass

def args(self, *args):
pass

with self.assertRaises(ValueError):
cached_member_function(kwargs_only)
with self.assertRaises(ValueError):
cached_member_function(kwargs)
cached_member_function(positional_only)
cached_member_function(args)

0 comments on commit 3bdd58e

Please sign in to comment.