#NEWLINE# def test_expiration( ) : #NEWLINE# #INDENT# time = 1 #NEWLINE# cache = Cache ( max_age = 5 , clock = ( lambda : time ) ) #NEWLINE# assert ( cache . clock ( ) == 1 ) #NEWLINE# time = 2 #NEWLINE# assert ( cache . clock ( ) == 2 ) #NEWLINE# cache [ 'a' ] = 'b' #NEWLINE# cache [ 'b' ] = 'c' #NEWLINE# time += 3 #NEWLINE# cache [ 'c' ] = 'd' #NEWLINE# cache [ 'd' ] = 'e' #NEWLINE# assert ( len ( cache ) == 4 ) #NEWLINE# assert ( len ( cache . queue ) == 4 ) #NEWLINE# cache . evict_expired ( ) #NEWLINE# assert ( len ( cache ) == 4 ) #NEWLINE# assert ( len ( cache . queue ) == 4 ) #NEWLINE# time += 3 #NEWLINE# cache . evict_expired ( ) #NEWLINE# assert ( len ( _ ) == 2 ) #NEWLINE# assert ( len ( cache . queue ) == 2 ) #NEWLINE# assert ( 'a' not in cache ) #NEWLINE# assert ( 'b' not in cache ) #NEWLINE# assert ( 'c' in cache ) #NEWLINE# assert ( 'd' in cache ) #NEWLINE# cache [ 'c' ] = 'f' #NEWLINE# assert ( len ( cache ) == 2 ) #NEWLINE# assert ( len ( cache . queue ) == 3 ) #NEWLINE# time += 3 #NEWLINE# cache . evict_expired ( ) #NEWLINE# assert ( len ( cache ) == 1 ) #NEWLINE# assert ( len ( cache . queue ) == 1 ) #NEWLINE# assert ( 'c' in cache ) #NEWLINE# try : #NEWLINE# #INDENT# _ = cache [ 'd' ] #NEWLINE# assert False , "'d' should not be in cache" #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# pass