decorators_t.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:dark-chess 作者: AHAPX 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号