<s> "<STR_LIT>" <EOL> import errno <EOL> import functools as ft <EOL> import io <EOL> import mock <EOL> import nose . tools as nt <EOL> import os <EOL> import random <EOL> import shutil <EOL> import sqlite3 <EOL> import sys <EOL> import threading <EOL> import time <EOL> import warnings <EOL> try : <EOL> import cPickle as pickle <EOL> except : <EOL> import pickle <EOL> import diskcache as dc <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> warnings . simplefilter ( '<STR_LIT:ignore>' , category = dc . EmptyDirWarning ) <EOL> if sys . hexversion < <NUM_LIT> : <EOL> range = xrange <EOL> def setup_cache ( func ) : <EOL> @ ft . wraps ( func ) <EOL> def wrapper ( ) : <EOL> shutil . rmtree ( '<STR_LIT>' , ignore_errors = True ) <EOL> with dc . FanoutCache ( '<STR_LIT>' ) as cache : <EOL> func ( cache ) <EOL> shutil . rmtree ( '<STR_LIT>' , ignore_errors = True ) <EOL> return wrapper <EOL> @ setup_cache <EOL> def test_init ( cache ) : <EOL> for key , value in dc . DEFAULT_SETTINGS . items ( ) : <EOL> assert getattr ( cache , key ) == value <EOL> cache . check ( ) <EOL> for key , value in dc . DEFAULT_SETTINGS . items ( ) : <EOL> setattr ( cache , key , value ) <EOL> cache . check ( ) <EOL> @ setup_cache <EOL> def test_set_get_delete ( cache ) : <EOL> for value in range ( <NUM_LIT:100> ) : <EOL> cache . set ( value , value ) <EOL> cache . check ( ) <EOL> for value in range ( <NUM_LIT:100> ) : <EOL> assert cache . get ( value ) == value <EOL> cache . check ( ) <EOL> for value in range ( <NUM_LIT:100> ) : <EOL> assert value in cache <EOL> cache . check ( ) <EOL> for value in range ( <NUM_LIT:100> ) : <EOL> assert cache . delete ( value ) <EOL> assert cache . delete ( <NUM_LIT:100> ) == False <EOL> cache . check ( ) <EOL> for value in range ( <NUM_LIT:100> ) : <EOL> cache [ value ] = value <EOL> cache . check ( ) <EOL> for value in range ( <NUM_LIT:100> ) : <EOL> assert cache [ value ] == value <EOL> cache . check ( ) <EOL> cache . clear ( ) <EOL> assert len ( cache ) == <NUM_LIT:0> <EOL> cache . check ( ) <EOL> def test_operationalerror ( ) : <EOL> cache = dc . FanoutCache ( '<STR_LIT>' , shards = <NUM_LIT:1> ) <EOL> shards = mock . Mock ( ) <EOL> shards . __getitem__ = mock . Mock ( side_effect = sqlite3 . OperationalError ) <EOL> object . __setattr__ ( cache , '<STR_LIT>' , shards ) <EOL> assert cache . set ( <NUM_LIT:0> , <NUM_LIT:0> ) == False <EOL> assert cache . get ( <NUM_LIT:0> ) == None <EOL> assert ( <NUM_LIT:0> in cache ) == False <EOL> assert cache . __delitem__ ( <NUM_LIT:0> ) == False <EOL> shutil . rmtree ( '<STR_LIT>' ) <EOL> @ nt . raises ( KeyError ) <EOL> @ setup_cache <EOL> def test_getitem_keyerror ( cache ) : <EOL> cache [ <NUM_LIT:0> ] <EOL> @ setup_cache <EOL> def test_expire ( cache ) : <EOL> cache . cull_limit = <NUM_LIT:0> <EOL> for value in range ( <NUM_LIT:100> ) : <EOL> cache . set ( value , value , expire = <NUM_LIT:0> ) <EOL> assert len ( cache ) == <NUM_LIT:100> <EOL> cache . cull_limit = <NUM_LIT:10> <EOL> assert cache . expire ( ) == <NUM_LIT:100> <EOL> @ setup_cache <EOL> def test_evict ( cache ) : <EOL> colors = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> for value in range ( <NUM_LIT> ) : <EOL> assert cache . set ( value , value , tag = colors [ value % len ( colors ) ] ) <EOL> assert len ( cache ) == <NUM_LIT> <EOL> assert cache . evict ( '<STR_LIT>' ) == <NUM_LIT:30> <EOL> assert len ( cache ) == <NUM_LIT> <EOL> assert len ( cache . check ( ) ) == <NUM_LIT:0> <EOL> @ setup_cache <EOL> def test_clear ( cache ) : <EOL> for value in range ( <NUM_LIT:100> ) : <EOL> cache [ value ] = value <EOL> assert len ( cache ) == <NUM_LIT:100> <EOL> assert cache . clear ( ) == <NUM_LIT:100> <EOL> assert len ( cache ) == <NUM_LIT:0> <EOL> assert len ( cache . check ( ) ) == <NUM_LIT:0> <EOL> @ setup_cache <EOL> def test_stats ( cache ) : <EOL> for value in range ( <NUM_LIT:100> ) : <EOL> cache [ value ] = value <EOL> assert cache . stats ( enable = True ) == ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> for value in range ( <NUM_LIT:100> ) : <EOL> cache [ value ] <EOL> for value in range ( <NUM_LIT:100> , <NUM_LIT> ) : <EOL> cache . get ( value ) <EOL> assert cache . stats ( reset = True ) == ( <NUM_LIT:100> , <NUM_LIT:10> ) <EOL> assert cache . stats ( enable = False ) == ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> for value in range ( <NUM_LIT:100> ) : <EOL> cache [ value ] <EOL> for value in range ( <NUM_LIT:100> , <NUM_LIT> ) : <EOL> cache . get ( value ) <EOL> assert cache . stats ( ) == ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> assert len ( cache . check ( ) ) == <NUM_LIT:0> <EOL> @ setup_cache <EOL> def test_volume ( cache ) : <EOL> volume = sum ( shard . volume ( ) for shard in cache . _shards ) <EOL> assert volume == cache . volume ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import nose <EOL> nose . runmodule ( ) </s>
