mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Allow resetting memoized cache. Fixes #3110.
This commit is contained in:
parent
86f62d0a92
commit
7adcfc7938
2 changed files with 34 additions and 1 deletions
|
|
@ -860,3 +860,34 @@ class TestSanitisedJoin(unittest.TestCase):
|
||||||
utils.posixize_path(
|
utils.posixize_path(
|
||||||
os.path.abspath(os.path.join("/foo/bar", "test")))
|
os.path.abspath(os.path.join("/foo/bar", "test")))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestMemoized(unittest.TestCase):
|
||||||
|
def test_memoized(self):
|
||||||
|
class Container:
|
||||||
|
def _get(self, key):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@utils.memoized
|
||||||
|
def get(self, key):
|
||||||
|
return self._get(key)
|
||||||
|
|
||||||
|
container = Container()
|
||||||
|
|
||||||
|
with unittest.mock.patch.object(
|
||||||
|
container, "_get", side_effect=lambda x: x
|
||||||
|
) as get_mock:
|
||||||
|
self.assertEqual("foo", container.get("foo"))
|
||||||
|
get_mock.assert_called_once_with("foo")
|
||||||
|
|
||||||
|
get_mock.reset_mock()
|
||||||
|
self.assertEqual("foo", container.get("foo"))
|
||||||
|
get_mock.assert_not_called()
|
||||||
|
|
||||||
|
self.assertEqual("bar", container.get("bar"))
|
||||||
|
get_mock.assert_called_once_with("bar")
|
||||||
|
|
||||||
|
get_mock.reset_mock()
|
||||||
|
container.get.cache.clear()
|
||||||
|
self.assertEqual("bar", container.get("bar"))
|
||||||
|
get_mock.assert_called_once_with("bar")
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,9 @@ class memoized:
|
||||||
|
|
||||||
def __get__(self, obj, objtype):
|
def __get__(self, obj, objtype):
|
||||||
'''Support instance methods.'''
|
'''Support instance methods.'''
|
||||||
return partial(self.__call__, obj)
|
fn = partial(self.__call__, obj)
|
||||||
|
fn.cache = self.cache
|
||||||
|
return fn
|
||||||
|
|
||||||
|
|
||||||
def deprecated_attribute(old, new, since=None, remove=None, doc=None):
|
def deprecated_attribute(old, new, since=None, remove=None, doc=None):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue