def test_configure(self): cache.configure(cache_time=13) with mock.patch('time.time', return_value=1): cache.setv(se.key, se.value) with mock.patch.object(cache, 'has_expired', return_value=False) as m: cache.getv(se.key, time.time()) m.assert_called_once_with(cache.Record(14, mock.ANY), 1)
def setUp(self): # flush the cache before every test cache.configure() self.config_file = tempfile.NamedTemporaryFile(delete=True) self.spool = tempfile.mkdtemp() mock_config = {'cache_time': 100.0, 'spool_root': self.spool} self.config_file.write(yaml.dump(mock_config).encode('utf-8')) self.config_file.flush() spool.configure(spool_root=self.spool) handlers._reset_stats() super(ApplicationTestCase, self).setUp()
def setUp(self): # flush the cache before every test cache.configure() self.config_file = tempfile.NamedTemporaryFile(delete=True) self.spool = tempfile.mkdtemp() mock_config = { 'cache_time': 100.0, 'spool_root': self.spool } self.config_file.write(yaml.dump(mock_config).encode('utf-8')) self.config_file.flush() spool.configure(spool_root=self.spool) handlers._reset_stats() super(ApplicationTestCase, self).setUp()
def test_stats_reset(self): self.assertEqual(cache.get_stats()['gets'], 0) self.assertRaises(KeyError, cache.getv, se.key) self.assertEqual(cache.get_stats()['gets'], 1) cache.configure() self.assertEqual(cache.get_stats()['gets'], 0)
def setUp(self): cache.configure()