def test_set(self): simple_cache = SimpleCache() simple_cache.set('foo', 'bar') simple_cache.set('moof', 'baz', timeout=1) # Use the underlying cache system to verify. self.assertEqual(cache.get('foo'), 'bar') self.assertEqual(cache.get('moof'), 'baz') # Check expiration. time.sleep(2) self.assertEqual(cache.get('moof'), None)
def test_set(self): simple_cache = SimpleCache(timeout=1) with mock.patch.object(simple_cache, 'cache', mock.Mock(wraps=simple_cache.cache)) as mocked_cache: simple_cache.set('foo', 'bar', timeout=10) simple_cache.set('moof', 'baz') # Use the underlying cache system to verify. self.assertEqual(cache.get('foo'), 'bar') self.assertEqual(cache.get('moof'), 'baz') # make sure cache was called with correct timeouts. self.assertEqual(mocked_cache.set.call_args_list[0][0][2], 10) self.assertEqual(mocked_cache.set.call_args_list[1][0][2], 1)
def test_set(self): simple_cache = SimpleCache(timeout=1) with mock.patch.object( simple_cache, 'cache', mock.Mock(wraps=simple_cache.cache)) as mocked_cache: simple_cache.set('foo', 'bar', timeout=10) simple_cache.set('moof', 'baz') # Use the underlying cache system to verify. self.assertEqual(cache.get('foo'), 'bar') self.assertEqual(cache.get('moof'), 'baz') # make sure cache was called with correct timeouts. self.assertEqual(mocked_cache.set.call_args_list[0][0][2], 10) self.assertEqual(mocked_cache.set.call_args_list[1][0][2], 1)