Skip to content
Snippets Groups Projects
Commit ffd766c5 authored by Rob Moss's avatar Rob Moss
Browse files

Verify use of cache via logging output

Inspecting the logging output allows us to detect whether a forecast
resumed from a cached state, so we can test whether the desired caching
behaviour was produced.
parent 6bf4b027
No related branches found
No related tags found
No related merge requests found
Pipeline #17222 passed
......@@ -22,7 +22,7 @@ def test_cached_prng_states(caplog):
t0 = 0.0
t1 = 15.0
t2 = 30.0
(state_1, state_2) = run_two_forecasts(time_scale, t0, t1, t2)
(state_1, state_2) = run_two_forecasts(caplog, time_scale, t0, t1, t2)
# Extract the relevant summary tables for each forecast.
cints_1 = state_1[t1]['summary']['model_cints']
......@@ -84,7 +84,7 @@ def run_forecast(time_scale, t0, t1, t2, cache_file, x_tbl, obs):
return pypfilt.forecast(params, [obs], [t1], filename=None)
def run_two_forecasts(time_scale, t0, t1, t2):
def run_two_forecasts(caplog, time_scale, t0, t1, t2):
"""
Run the same forecast twice; the first time with an empty cache, and the
second resuming from a cached state.
......@@ -112,8 +112,16 @@ def run_two_forecasts(time_scale, t0, t1, t2):
# forecast from the cached state produces identical model dynamics.
assert not os.path.isfile(cache_file)
state_1 = run_forecast(time_scale, t0, t1, t2, cache_file, sim_obs, obs)
# Check that no cached state was used.
assert 'No estimation pass needed' not in caplog.text
# NOTE: this message has *two spaces* so that it aligns with
# 'Forecasting from' messages.
assert 'Estimating from' in caplog.text
assert os.path.isfile(cache_file)
state_2 = run_forecast(time_scale, t0, t1, t2, cache_file, sim_obs, obs)
# Check that a cached state was used.
assert 'No estimation pass needed' in caplog.text
os.remove(cache_file)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment