File: test_lrucache.py

package info (click to toggle)
python-fs 2.4.16-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,944 kB
  • sloc: python: 13,048; makefile: 226; sh: 3
file content (32 lines) | stat: -rw-r--r-- 862 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from __future__ import unicode_literals

import unittest

from fs import lrucache


class TestLRUCache(unittest.TestCase):
    def setUp(self):
        self.lrucache = lrucache.LRUCache(3)

    def test_lrucache(self):
        # insert some values
        self.lrucache["foo"] = 1
        self.lrucache["bar"] = 2
        self.lrucache["baz"] = 3
        self.assertIn("foo", self.lrucache)

        #  Cache size is 3, so the following should kick oldest one out
        self.lrucache["egg"] = 4
        self.assertNotIn("foo", self.lrucache)
        self.assertIn("egg", self.lrucache)

        # cache is now full
        # look up two keys
        self.lrucache["bar"]
        self.lrucache["baz"]

        # Insert a new value
        self.lrucache["eggegg"] = 5
        # Check it kicked out the 'oldest' key
        self.assertNotIn("egg", self.lrucache)