def test_validation(self): cache_name = self.check_cache_gone('validation') cache = PersistentCache(cache_name, cache_manager=self.manager, contents={ 'foo': 'bar' }, validator=lambda *args: False, builder=lambda *args: ['built']) cache.save() cache.load_or_build() # Invalid load, force rebuild self.assert_contents_equal(cache, ['built']) cache[0] = 'changed' cache.save() cache.validator = lambda *args: True cache.load() self.assert_contents_equal(cache, ['changed']) # Raising an exception in validator should invalidate the cache cache.validator = lambda *args: args['not legal'] cache.load() self.assert_contents_equal(cache, None)