Exemple #1
0
Fichier : tvfs.py Projet : bup/bup
def test_cache_behavior():
    orig_max = vfs._cache_max_items
    try:
        vfs._cache_max_items = 2
        vfs.clear_cache()
        wvpasseq({}, vfs._cache)
        wvpasseq([], vfs._cache_keys)
        wvfail(vfs._cache_keys)
        wvexcept(Exception, vfs.cache_notice, 'x', 1)
        key_0 = 'itm:' + b'\0' * 20
        key_1 = 'itm:' + b'\1' * 20
        key_2 = 'itm:' + b'\2' * 20
        vfs.cache_notice(key_0, 'something')
        wvpasseq({key_0 : 'something'}, vfs._cache)
        wvpasseq([key_0], vfs._cache_keys)
        vfs.cache_notice(key_1, 'something else')
        wvpasseq({key_0 : 'something', key_1 : 'something else'}, vfs._cache)
        wvpasseq(frozenset([key_0, key_1]), frozenset(vfs._cache_keys))
        vfs.cache_notice(key_2, 'and also')
        wvpasseq(2, len(vfs._cache))
        wvpass(frozenset(vfs._cache.iteritems())
               < frozenset({key_0 : 'something',
                            key_1 : 'something else',
                            key_2 : 'and also'}.iteritems()))
        wvpasseq(2, len(vfs._cache_keys))
        wvpass(frozenset(vfs._cache_keys) < frozenset([key_0, key_1, key_2]))
        vfs.clear_cache()
        wvpasseq({}, vfs._cache)
        wvpasseq([], vfs._cache_keys)
    finally:
        vfs._cache_max_items = orig_max
        vfs.clear_cache()
Exemple #2
0
def test_cache_behavior():
    orig_max = vfs._cache_max_items
    try:
        vfs._cache_max_items = 2
        vfs.clear_cache()
        wvpasseq({}, vfs._cache)
        wvpasseq([], vfs._cache_keys)
        wvfail(vfs._cache_keys)
        wvexcept(Exception, vfs.cache_notice, 'x', 1)
        key_0 = 'itm:' + b'\0' * 20
        key_1 = 'itm:' + b'\1' * 20
        key_2 = 'itm:' + b'\2' * 20
        vfs.cache_notice(key_0, 'something')
        wvpasseq({key_0: 'something'}, vfs._cache)
        wvpasseq([key_0], vfs._cache_keys)
        vfs.cache_notice(key_1, 'something else')
        wvpasseq({key_0: 'something', key_1: 'something else'}, vfs._cache)
        wvpasseq(frozenset([key_0, key_1]), frozenset(vfs._cache_keys))
        vfs.cache_notice(key_2, 'and also')
        wvpasseq(2, len(vfs._cache))
        wvpass(
            frozenset(vfs._cache.iteritems()) < frozenset({
                key_0: 'something',
                key_1: 'something else',
                key_2: 'and also'
            }.iteritems()))
        wvpasseq(2, len(vfs._cache_keys))
        wvpass(frozenset(vfs._cache_keys) < frozenset([key_0, key_1, key_2]))
        vfs.clear_cache()
        wvpasseq({}, vfs._cache)
        wvpasseq([], vfs._cache_keys)
    finally:
        vfs._cache_max_items = orig_max
        vfs.clear_cache()