Download newtests/ttlcache/tests/test_lru_semantics.py from noodcon/SWE-DockerLess: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/datasets/noodcon/SWE-DockerLess/resolve/main/newtests/ttlcache/tests/test_lru_semantics.py
- Command line
-
hf download hf://datasets/noodcon/SWE-DockerLess/newtests/ttlcache/tests/test_lru_semantics.py
-
curl -L -o test_lru_semantics.py https://huggingface.co/datasets/noodcon/SWE-DockerLess/resolve/main/newtests/ttlcache/tests/test_lru_semantics.py
1.36 kB
| from ttlcache import FakeClock, TTLCache | |
| def test_get_refreshes_recency(): | |
| clock = FakeClock() | |
| cache = TTLCache(maxsize=2, ttl=10.0, clock=clock) | |
| cache["a"] = 1 | |
| cache["b"] = 2 | |
| assert cache["a"] == 1 | |
| cache["c"] = 3 | |
| assert "a" in cache | |
| assert "b" not in cache | |
| def test_overwrite_refreshes_recency(): | |
| clock = FakeClock() | |
| cache = TTLCache(maxsize=2, ttl=10.0, clock=clock) | |
| cache["a"] = 1 | |
| cache["b"] = 2 | |
| cache["a"] = 9 | |
| cache["c"] = 3 | |
| assert cache["a"] == 9 | |
| assert "b" not in cache | |
| def test_setdefault_refreshes_recency(): | |
| clock = FakeClock() | |
| cache = TTLCache(maxsize=2, ttl=10.0, clock=clock) | |
| cache["a"] = 1 | |
| cache["b"] = 2 | |
| assert cache.setdefault("a", lambda: 99) == 1 | |
| cache["c"] = 3 | |
| assert "a" in cache | |
| assert "b" not in cache | |
| def test_len_ignores_expired_entries(): | |
| clock = FakeClock() | |
| cache = TTLCache(maxsize=4, ttl=10.0, clock=clock) | |
| cache["a"] = 1 | |
| clock.advance(5) | |
| cache["b"] = 2 | |
| clock.advance(6) | |
| assert len(cache) == 1 | |
| assert "a" not in cache | |
| assert "b" in cache | |
| def test_items_reports_least_recently_used_first(): | |
| clock = FakeClock() | |
| cache = TTLCache(maxsize=3, ttl=10.0, clock=clock) | |
| cache["a"] = 1 | |
| cache["b"] = 2 | |
| assert cache["a"] == 1 | |
| assert list(cache.items()) == [("b", 2), ("a", 1)] | |