Make the cache encode and decode not crash if something goes wrong

This commit is contained in:
mathieui
2019-02-02 17:42:24 +01:00
parent 3a44ec8f15
commit b42fafabb4
2 changed files with 17 additions and 2 deletions

View File

@@ -34,9 +34,14 @@ class TestCacheClass(SlixTest):
)
def testFileSystemCache(self):
def failing_decode(value):
if value == "failme":
raise Exception("you failed")
return value
with TemporaryDirectory() as tmpdir:
cache = FileSystemCache(tmpdir, "test")
cache = FileSystemCache(tmpdir, "test", decode=failing_decode)
cache.store("test", "test_value")
cache.store("test2", "failme")
self.assertEqual(
cache.retrieve("test"),
"test_value"
@@ -47,6 +52,11 @@ class TestCacheClass(SlixTest):
None
)
self.assertEqual(
cache.retrieve("test2"),
None
)
def testFileSystemPerJidCache(self):
with TemporaryDirectory() as tmpdir:
cache = FileSystemPerJidCache(tmpdir, "test")