diff --git a/lumicks/pylake/tests/test_file/test_caching.py b/lumicks/pylake/tests/test_file/test_caching.py index c9ecfcb12..7ca9d5808 100644 --- a/lumicks/pylake/tests/test_file/test_caching.py +++ b/lumicks/pylake/tests/test_file/test_caching.py @@ -1,22 +1,20 @@ import pytest from lumicks import pylake +from lumicks.pylake.channel import _get_array def test_global_cache_continuous(h5_file): - # Load the file (never storing the file handle) - f1x1 = pylake.File.from_h5py(h5_file).force1x - f1x2 = pylake.File.from_h5py(h5_file).force1x - - # These should point to the same data - assert id(f1x1.data) == id(f1x2.data) + _get_array.cache_clear() # Load the file (never storing the file handle) f1x1 = pylake.File.from_h5py(h5_file)["Force HF/Force 1x"] f1x2 = pylake.File.from_h5py(h5_file).force1x + assert _get_array.cache_info().hits == 0 # No cache used yet (lazy loading) # These should point to the same data assert id(f1x1.data) == id(f1x2.data) + assert _get_array.cache_info().hits == 1 with pytest.raises(ValueError, match="assignment destination is read-only"): f1x1.data[5:100] = 3 @@ -26,12 +24,17 @@ def test_global_cache_continuous(h5_file): def test_global_cache_timeseries(h5_file): + _get_array.cache_clear() + f1x1 = pylake.File.from_h5py(h5_file).downsampled_force1x f1x2 = pylake.File.from_h5py(h5_file).downsampled_force1x + assert _get_array.cache_info().hits == 0 # No cache used yet (lazy loading) # These should point to the same data assert id(f1x1.data) == id(f1x2.data) + assert _get_array.cache_info().hits == 1 assert id(f1x1.timestamps) == id(f1x2.timestamps) + assert _get_array.cache_info().hits == 2 with pytest.raises(ValueError, match="assignment destination is read-only"): f1x1.data[5:100] = 3 @@ -42,11 +45,15 @@ def test_global_cache_timeseries(h5_file): def test_global_cache_timetags(h5_file): if pylake.File.from_h5py(h5_file).format_version == 2: + _get_array.cache_clear() tags1 = pylake.File.from_h5py(h5_file)["Photon Time Tags"]["Red"] + assert _get_array.cache_info().hits == 3 # start and stop pull the data every time tags2 = pylake.File.from_h5py(h5_file)["Photon Time Tags"]["Red"] + assert _get_array.cache_info().hits == 6 # These should point to the same data assert id(tags1.data) == id(tags2.data) + assert _get_array.cache_info().hits == 1 with pytest.raises(ValueError, match="assignment destination is read-only"): tags1.data[5:100] = 3