From 2062f725d6cf0a426514574efa1f25671bc07631 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Tue, 6 Aug 2019 22:23:02 +0100
Subject: [PATCH] TEST: Test Cache lru option

---
 tests/test_cache.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/tests/test_cache.py b/tests/test_cache.py
index cb643ae43..4dcc97032 100644
--- a/tests/test_cache.py
+++ b/tests/test_cache.py
@@ -113,7 +113,36 @@ def test_expiry():
     with pytest.raises(cache.Expired):
         c.get(0)
 
+    with pytest.raises(cache.Expired):
+        c.get(1)
+
     assert c.get(1, default='default') == 'default'
 
     # And that the cache is empty
     assert len(c) == 0
+
+
+def test_lru():
+    c = cache.Cache(maxsize=3, lru=True)
+
+    c[0] = '0'
+    c[1] = '1'
+    c[2] = '2'
+    c[3] = '3'
+
+    # normal behaviour - first inserted
+    # is dropped
+    with pytest.raises(KeyError):
+        assert c.get(0)
+
+    # lru behaviour - oldest accessed is
+    # dropped
+    c[1]
+    c[4] = '4'
+    with pytest.raises(KeyError):
+        c[2]
+
+    c[1]
+    c[3]
+    c[4]
+    assert len(c) == 3
-- 
GitLab