added caching utility

This commit is contained in:
2024-02-13 15:57:03 +01:00
parent 8b38c500f9
commit f0502d93c5
3 changed files with 134 additions and 0 deletions

59
tests/test_cache.py Normal file
View File

@@ -0,0 +1,59 @@
from scgenerator.cache import Cache
def test_io():
cache = Cache("Hello")
assert not cache.dir.exists()
cache.reset()
assert cache.dir.exists()
cache.save("a", "bonjour")
assert cache.load("a") == "bonjour"
assert "a" in cache
cache.delete()
assert not cache.dir.exists()
def test_toml():
s1 = """
[config]
plot_range = [750, 1350]
rin_measurement = "./DualComb1GHz_updated_corrected_extrapolated_1GHz_noqn.csv"
num_segments = 31
num_frequencies = 513
noise_seed_start = 3012
anticorrelated_width = true
"""
s2 = """
# some commment
[config]
anticorrelated_width = true
plot_range = [750,1350]
num_segments=31
num_frequencies = 513
noise_seed_start=3012
rin_measurement='./DualComb1GHz_updated_corrected_extrapolated_1GHz_noqn.csv'
"""
s3 = """
# some commment
[config]
anticorrelated_width = true
plot_range = [750,1351]
num_segments=31
num_frequencies = 513
noise_seed_start=3012
rin_measurement='./DualComb1GHz_updated_corrected_extrapolated_1GHz_noqn.csv'
"""
cache1 = Cache.from_toml(s1)
cache3 = Cache.from_toml(s3, create=False)
assert cache1.dir == Cache.from_toml(s2).dir
assert cache1.dir != cache3.dir
assert cache1.dir.exists()
cache1.delete()
assert not cache1.dir.exists()
assert not cache3.dir.exists()