def test_add(self, proxy_mock): node = _ExpNode() proxy_mock.return_value = node self.clean_manager.add(node) self.cleaner_mock.start.assert_called_once() self._assert_on_add(node)
def test_add_when_initialized(self, proxy_mock): node = _ExpNode() proxy_mock.return_value = node self.clean_manager._initialized = True self.clean_manager.add(node) self.cleaner_mock.start.assert_not_called() self._assert_on_add(node)
def test_delete(self, create_mock, CleanManagerMock, RLockMock): cleanManager = CleanManagerMock() lock = RLockMock() node = _ExpNode(key='a', value='b', expires=10) create_mock.return_value = node cache = LruCache() cache.add('a', 'b', expires=10) del cache['a'] cleanManager.add.assert_called_with(node) cleanManager.on_delete.assert_called() lock.__enter__.assert_called() lock.__exit__.assert_called()