def test_call_cache_disabled(load_mock: MagicMock, save_mock: MagicMock) -> None: df_func = MagicMock(return_value=pd.DataFrame([1, 2], columns=['a'])) df_func.__name__ = "df_func" df_cache = cache.df_cache() assert not df_cache.cache_config.enabled wrapper = df_cache.__call__(df_func) wrapper(*(1, 2), **{'val1': 'a'}) df_func.assert_called_once_with(1, 2, val1='a') load_mock.assert_not_called() save_mock.assert_not_called()
def test_call_cache_ignores_expired(mock_data_1: pd.DataFrame, load_mock: MagicMock, save_mock: MagicMock, save_json_mock: MagicMock) -> None: df_func = MagicMock(return_value=mock_data_1) df_func.__name__ = "df_func" df_cache = cache.df_cache() assert df_cache.cache_config.enabled wrapper = df_cache.__call__(df_func) wrapper(*(1, 2), **{'val1': 'a'}) df_func.assert_called_once_with(1, 2, val1='a') load_mock.assert_not_called() save_mock.assert_called_once() pd.testing.assert_frame_equal(mock_data_1, save_mock.call_args[0][0])
def test_call_cache_enabled_loads_cache(mock_data_1: pd.DataFrame, load_mock: MagicMock, save_mock: MagicMock) -> None: df_func = MagicMock() df_func.__name__ = "df_func" df_cache = cache.df_cache() assert df_cache.cache_config.enabled wrapper = df_cache.__call__(df_func) result = wrapper(*(1, 2), **{'val1': 'a'}) load_mock.assert_called_once() df_func.assert_not_called() save_mock.assert_not_called() assert isinstance(result, pd.DataFrame) pd.testing.assert_frame_equal(result, mock_data_1)