def test_use_cache(self):
def _func(a, b):
invert_color(a)
return 'ok'
func = use_cache(10, name='test_func')(_func)
a, b = Game.create(white='1234', black='qwer'), delete_cache
# run first time, no cache
with patch('tests.decorators_t.invert_color') as mock:
self.assertEqual(func(a, b=b), 'ok')
mock.assert_called_once_with(a)
# run second time, results from cached
with patch('tests.decorators_t.invert_color') as mock:
self.assertEqual(func(a, b=b), 'ok')
self.assertFalse(mock.called)
# delete cache and run again, no cache
delete_cache(get_cache_func_name('test_func', a, b=b))
with patch('tests.decorators_t.invert_color') as mock:
self.assertEqual(func(a, b=b), 'ok')
mock.assert_called_once_with(a)
评论列表
文章目录