self.assertEqual(3, self.call_mock.call_count) def testDeleteCache(self): @memcache_utils.ConditionallyCached() def foo(): return self.call_mock() foo() foo.DeleteCache() foo() # Both calls should call through because of the interstitial cache deletion. self.assertEqual(2, self.call_mock.call_count) def testPassThroughKwargs(self): # Only cache if return is truthy and only cache to a single memcache entry. @memcache_utils.ConditionallyCached(cache_predicate=lambda a, k, r: r, create_key_func=lambda *a: 'const') def foo(a='a'): return self.call_mock(a) self.assertTrue(foo()) # Truthy return so cache value. foo(a='b') # Cache hit even though args differ. self.assertEqual(1, self.call_mock.call_count) if __name__ == '__main__': basetest.main()
def main(): basetest.main()