<s> from . . lrucache import LRUCache <EOL> import pytest <EOL> from tempfile import TemporaryFile <EOL> class TestLRUCache : <EOL> def test_lrucache ( self ) : <EOL> c = LRUCache ( <NUM_LIT:2> , dispose = lambda _ : None ) <EOL> assert len ( c ) == <NUM_LIT:0> <EOL> assert c . items ( ) == set ( ) <EOL> for i , x in enumerate ( '<STR_LIT:abc>' ) : <EOL> c [ x ] = i <EOL> assert len ( c ) == <NUM_LIT:2> <EOL> assert c . items ( ) == set ( [ ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> assert '<STR_LIT:a>' not in c <EOL> assert '<STR_LIT:b>' in c <EOL> with pytest . raises ( KeyError ) : <EOL> c [ '<STR_LIT:a>' ] <EOL> assert c [ '<STR_LIT:b>' ] == <NUM_LIT:1> <EOL> assert c [ '<STR_LIT:c>' ] == <NUM_LIT:2> <EOL> c [ '<STR_LIT:d>' ] = <NUM_LIT:3> <EOL> assert len ( c ) == <NUM_LIT:2> <EOL> assert c [ '<STR_LIT:c>' ] == <NUM_LIT:2> <EOL> assert c [ '<STR_LIT:d>' ] == <NUM_LIT:3> <EOL> del c [ '<STR_LIT:c>' ] <EOL> assert len ( c ) == <NUM_LIT:1> <EOL> with pytest . raises ( KeyError ) : <EOL> c [ '<STR_LIT:c>' ] <EOL> assert c [ '<STR_LIT:d>' ] == <NUM_LIT:3> <EOL> c . clear ( ) <EOL> assert c . items ( ) == set ( ) <EOL> def test_dispose ( self ) : <EOL> c = LRUCache ( <NUM_LIT:2> , dispose = lambda f : f . close ( ) ) <EOL> f1 = TemporaryFile ( ) <EOL> f2 = TemporaryFile ( ) <EOL> f3 = TemporaryFile ( ) <EOL> c [ <NUM_LIT:1> ] = f1 <EOL> c [ <NUM_LIT:2> ] = f2 <EOL> assert not f2 . closed <EOL> c [ <NUM_LIT:3> ] = f3 <EOL> assert <NUM_LIT:1> not in c <EOL> assert f1 . closed <EOL> assert <NUM_LIT:2> in c <EOL> assert not f2 . closed <EOL> del c [ <NUM_LIT:2> ] <EOL> assert <NUM_LIT:2> not in c <EOL> assert f2 . closed <EOL> c . clear ( ) <EOL> assert c . items ( ) == set ( ) <EOL> assert f3 . closed </s>
