1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
from unittest.mock import Mock, call
from dacite.cache import set_cache_size, get_cache_size, cache
def test_cache_size():
set_cache_size(4321)
assert get_cache_size() == 4321
function = Mock()
cache(function)(get_cache_size())
set_cache_size(8765)
cache(function)(get_cache_size())
set_cache_size(None)
cache(function)(get_cache_size())
assert function.call_count == 3
assert function.mock_calls == [call(4321), call(8765), call(None)]
def test_cache_from_function():
function = Mock()
cache(function)()
cache(function)()
function.assert_called_once()
|