Beispiel #1
0
    def test_remove_nothing(self):
        cache = GenerationalCache()
        cache.add(self.obj1)

        present = cache.remove(self.obj2)
        self.assertFalse(present)
        self.assertEqual(cache.get_cached(), [self.obj1])
Beispiel #2
0
    def test_remove_nothing(self):
        cache = GenerationalCache()
        cache.add(self.obj1)

        present = cache.remove(self.obj2)
        self.assertFalse(present)
        self.assertEqual(cache.get_cached(), [self.obj1])
Beispiel #3
0
def test_generational_cache_remove_nothing(obj1, obj2):
    cache = GenerationalCache()
    cache.add(obj1)

    present = cache.remove(obj2)
    assert not present
    assert cache.get_cached() == [obj1]
Beispiel #4
0
    def test_remove_object(self):
        cache = GenerationalCache()
        cache.add(self.obj1)
        cache.add(self.obj2)
        cache.add(self.obj3)

        present = cache.remove(self.obj2)
        self.assertTrue(present)
        self.assertEqual(sorted(cache.get_cached()), [self.obj1, self.obj3])
Beispiel #5
0
    def test_remove_object(self):
        cache = GenerationalCache()
        cache.add(self.obj1)
        cache.add(self.obj2)
        cache.add(self.obj3)

        present = cache.remove(self.obj2)
        self.assertTrue(present)
        self.assertEqual(sorted(cache.get_cached()), [self.obj1, self.obj3])
Beispiel #6
0
def test_generational_cache_remove_object(obj1, obj2, obj3):
    cache = GenerationalCache()
    cache.add(obj1)
    cache.add(obj2)
    cache.add(obj3)

    present = cache.remove(obj2)
    assert present
    assert sorted(cache.get_cached()) == [obj1, obj3]
Beispiel #7
0
    def test_remove_from_overlap(self):
        """
        Removing an object from the cache removes it from both its
        primary and secondary generations.
        """
        cache = GenerationalCache(2)
        cache.add(self.obj1) # new=[1]    old=[]
        cache.add(self.obj2) # new=[1, 2] old=[]
        cache.add(self.obj3) # new=[3]    old=[1, 2]
        cache.add(self.obj1) # new=[3, 1] old=[1, 2]

        present = cache.remove(self.obj1)
        self.assertTrue(present)
        self.assertEqual(sorted(cache.get_cached()), [self.obj2, self.obj3])
Beispiel #8
0
    def test_remove_from_overlap(self):
        """
        Removing an object from the cache removes it from both its
        primary and secondary generations.
        """
        cache = GenerationalCache(2)
        cache.add(self.obj1) # new=[1]    old=[]
        cache.add(self.obj2) # new=[1, 2] old=[]
        cache.add(self.obj3) # new=[3]    old=[1, 2]
        cache.add(self.obj1) # new=[3, 1] old=[1, 2]

        present = cache.remove(self.obj1)
        self.assertTrue(present)
        self.assertEqual(sorted(cache.get_cached()), [self.obj2, self.obj3])
Beispiel #9
0
def test_generational_cache_remove_from_overlap(obj1, obj2, obj3):
    """
    Removing an object from the cache removes it from both its
    primary and secondary generations.
    """
    cache = GenerationalCache(2)
    cache.add(obj1)  # new=[1]    old=[]
    cache.add(obj2)  # new=[1, 2] old=[]
    cache.add(obj3)  # new=[3]    old=[1, 2]
    cache.add(obj1)  # new=[3, 1] old=[1, 2]

    present = cache.remove(obj1)
    assert present
    assert sorted(cache.get_cached()) == [obj2, obj3]