<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import unittest <EOL> def fix_sys_path ( ) : <EOL> """<STR_LIT>""" <EOL> def add_path_first ( path ) : <EOL> sys . path = [ path ] + [ p for p in sys . path if ( <EOL> not p == path and not p == ( path + '<STR_LIT:/>' ) ) ] <EOL> path = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> if not os . path . isfile ( os . path . join ( path , '<STR_LIT>' ) ) : <EOL> i = <NUM_LIT:0> <EOL> while i < <NUM_LIT:10> : <EOL> i += <NUM_LIT:1> <EOL> if os . path . exists ( os . path . join ( path , '<STR_LIT>' ) ) : <EOL> break <EOL> path = os . path . abspath ( os . path . join ( path , '<STR_LIT:..>' ) ) <EOL> paths = [ path , <EOL> os . path . abspath ( os . path . join ( path , '<STR_LIT>' ) ) , <EOL> os . path . abspath ( os . path . join ( path , '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' ] <EOL> [ add_path_first ( path ) for path in paths ] <EOL> fix_sys_path ( ) <EOL> from storage import Storage <EOL> from cache import CacheInRam , CacheOnDisk <EOL> oldcwd = None <EOL> def setUpModule ( ) : <EOL> global oldcwd <EOL> if oldcwd is None : <EOL> oldcwd = os . getcwd ( ) <EOL> if not os . path . isdir ( '<STR_LIT>' ) : <EOL> os . chdir ( os . path . realpath ( '<STR_LIT>' ) ) <EOL> def tearDownModule ( ) : <EOL> global oldcwd <EOL> if oldcwd : <EOL> os . chdir ( oldcwd ) <EOL> oldcwd = None <EOL> class TestCache ( unittest . TestCase ) : <EOL> def testCacheInRam ( self ) : <EOL> cache = CacheInRam ( ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:1> , <NUM_LIT:0> ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:2> , <NUM_LIT:100> ) , <NUM_LIT:1> ) <EOL> cache . clear ( '<STR_LIT:b>' ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:2> , <NUM_LIT:100> ) , <NUM_LIT:1> ) <EOL> cache . clear ( '<STR_LIT:a>' ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:2> , <NUM_LIT:100> ) , <NUM_LIT:2> ) <EOL> cache . clear ( ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:3> , <NUM_LIT:100> ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:4> , <NUM_LIT:0> ) , <NUM_LIT:4> ) <EOL> def testCacheOnDisk ( self ) : <EOL> s = Storage ( { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> cache = CacheOnDisk ( s ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:1> , <NUM_LIT:0> ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:2> , <NUM_LIT:100> ) , <NUM_LIT:1> ) <EOL> cache . clear ( '<STR_LIT:b>' ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:2> , <NUM_LIT:100> ) , <NUM_LIT:1> ) <EOL> cache . clear ( '<STR_LIT:a>' ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:2> , <NUM_LIT:100> ) , <NUM_LIT:2> ) <EOL> cache . clear ( ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:3> , <NUM_LIT:100> ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( cache ( '<STR_LIT:a>' , lambda : <NUM_LIT:4> , <NUM_LIT:0> ) , <NUM_LIT:4> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> setUpModule ( ) <EOL> unittest . main ( ) <EOL> tearDownModule ( ) </s>
