OXIESEC PANEL
- Current Dir:
/
/
opt
/
gsutil
/
third_party
/
cachetools
/
tests
Server IP: 191.96.63.230
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
12/11/2024 09:39:44 AM
rwxr-xr-x
📄
__init__.py
9.51 KB
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_cache.py
148 bytes
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_cached.py
8.19 KB
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_cachedmethod.py
6.89 KB
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_fifo.py
1.34 KB
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_func.py
5.26 KB
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_keys.py
4.66 KB
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_lfu.py
1.17 KB
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_lru.py
1.34 KB
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_mru.py
1.87 KB
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_rr.py
831 bytes
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_tlru.py
7.96 KB
08/18/2024 08:25:26 PM
rw-r--r--
📄
test_ttl.py
5.85 KB
08/18/2024 08:25:26 PM
rw-r--r--
Editing: test_mru.py
Close
import unittest import warnings from cachetools import MRUCache from . import CacheTestMixin class MRUCacheTest(unittest.TestCase, CacheTestMixin): # TODO: method to create cache that can be overridden Cache = MRUCache def test_evict__writes_only(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") cache = MRUCache(maxsize=2) self.assertEqual(len(w), 1) self.assertIs(w[0].category, DeprecationWarning) cache[1] = 1 cache[2] = 2 cache[3] = 3 # Evicts 1 because nothing's been used yet assert len(cache) == 2 assert 1 not in cache, "Wrong key was evicted. Should have been '1'." assert 2 in cache assert 3 in cache def test_evict__with_access(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") cache = MRUCache(maxsize=2) self.assertEqual(len(w), 1) self.assertIs(w[0].category, DeprecationWarning) cache[1] = 1 cache[2] = 2 cache[1] cache[2] cache[3] = 3 # Evicts 2 assert 2 not in cache, "Wrong key was evicted. Should have been '2'." assert 1 in cache assert 3 in cache def test_evict__with_delete(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") cache = MRUCache(maxsize=2) self.assertEqual(len(w), 1) self.assertIs(w[0].category, DeprecationWarning) cache[1] = 1 cache[2] = 2 del cache[2] cache[3] = 3 # Doesn't evict anything because we just deleted 2 assert 2 not in cache assert 1 in cache cache[4] = 4 # Should evict 1 as we just accessed it with __contains__ assert 1 not in cache assert 3 in cache assert 4 in cache