from ..lrucache import LRUCache
from . import BaseTestCase


class LRUCacheTestCase(BaseTestCase):

    def test(self):
        c = LRUCache(2, dispose=lambda _: None)
        self.assert_equal(len(c), 0)
        for i, x in enumerate('abc'):
            c[x] = i
        self.assert_equal(len(c), 2)
        self.assert_equal(c.items(), set([('b', 1), ('c', 2)]))
        self.assert_equal(False, 'a' in c)
        self.assert_equal(True, 'b' in c)
        self.assert_raises(KeyError, lambda: c['a'])
        self.assert_equal(c['b'], 1)
        self.assert_equal(c['c'], 2)
        c['d'] = 3
        self.assert_equal(len(c), 2)
        self.assert_equal(c['c'], 2)
        self.assert_equal(c['d'], 3)
        del c['c']
        self.assert_equal(len(c), 1)
        self.assert_raises(KeyError, lambda: c['c'])
        self.assert_equal(c['d'], 3)

@@ -52,16 +52,51 @@
 estCase%0A
+from tempfile import TemporaryFile%0A
 %0A%0Aclass 
@@ -861,28 +861,731 @@
 elf.assert_equal(c%5B'd'%5D, 3)%0A
+        c.clear()%0A        self.assert_equal(c.items(), set())%0A%0A    def test_dispose(self):%0A        c = LRUCache(2, dispose=lambda f: f.close())%0A        f1 = TemporaryFile()%0A        f2 = TemporaryFile()%0A        f3 = TemporaryFile()%0A        c%5B1%5D = f1%0A        c%5B2%5D = f2%0A        self.assert_equal(False, f2.closed)%0A        c%5B3%5D = f3%0A        self.assert_equal(False, 1 in c)%0A        self.assert_equal(True, f1.closed)%0A        self.assert_equal(True, 2 in c)%0A        self.assert_equal(False, f2.closed)%0A        del c%5B2%5D%0A        self.assert_equal(False, 2 in c)%0A        self.assert_equal(True, f2.closed)%0A        c.clear()%0A        self.assert_equal(c.items(), set())%0A        self.assert_equal(True, f3.closed)%0A

test added code