Skip to content

Commit

Permalink
Add cache and configuration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eelregit committed Jan 27, 2022
1 parent efd6fcb commit 0dd2f76
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def test_Cosmology_immutability():
with assert_raises(FrozenInstanceError):
cosmo.h = 0.74 # Hubble doesn't budge on the tension

with assert_raises(FrozenInstanceError):
cosmo.config.log10_a_max = 0.0


def test_cache():
cosmo = Cosmology(
Expand All @@ -33,21 +36,22 @@ def test_cache():
wa=0.0,
)

def assert_pure(c1, c2):
assert c1 is not c2 and c1 == c2 and c1._cache != c2._cache

cosmo = cosmo.cache_set("a", 1)
cosmo = cosmo.cache_set("c", 3)

assert cosmo.is_cached("a")
assert not cosmo.is_cached("b")
assert cosmo.cache_get("c") == 3

cosmo = cosmo.cache_set("b", 2)
cosmo_no_c = cosmo.cache_del("c")
assert cosmo.is_cached("b")
assert not cosmo_no_c.is_cached("c")
assert (
cosmo_no_c is not cosmo
and cosmo_no_c == cosmo
and cosmo_no_c._cache != cosmo._cache
)
cosmo_add_b = cosmo.cache_set("b", 2)
cosmo_del_c = cosmo.cache_del("c")
cosmo_clean = cosmo.cache_clear()

cosmo = cosmo.cache_clear()
assert len(cosmo._cache) == 0
assert not cosmo_del_c.is_cached("c")
assert_pure(cosmo_add_b, cosmo) # test set purity
assert_pure(cosmo_del_c, cosmo) # test del purity
assert_pure(cosmo_clean, cosmo) # test clear purity
assert len(cosmo_clean._cache) == 0

0 comments on commit 0dd2f76

Please sign in to comment.