<s> import unittest , random , time , hashlib , os <EOL> from peafowl . collection import QueueCollection , QueueCollectionError <EOL> try : <EOL> from cmemcache import Client <EOL> except ImportError : <EOL> from memcache import Client <EOL> class TestPeafowl ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . memcache = Client ( [ '<STR_LIT>' ] ) <EOL> def tearDown ( self ) : <EOL> self . memcache . disconnect_all ( ) <EOL> def test_set_and_get_one_entry ( self ) : <EOL> v = random . randint ( <NUM_LIT:1> , <NUM_LIT:32> ) <EOL> self . assertEqual ( None , self . memcache . get ( '<STR_LIT>' ) ) <EOL> self . memcache . set ( '<STR_LIT>' , v ) <EOL> self . assertEqual ( v , self . memcache . get ( '<STR_LIT>' ) ) <EOL> def test_set_with_expiry ( self ) : <EOL> v = random . randint ( <NUM_LIT:1> , <NUM_LIT:32> ) <EOL> self . assertEqual ( None , self . memcache . get ( '<STR_LIT>' ) ) <EOL> now = time . time ( ) <EOL> self . memcache . set ( '<STR_LIT>' , v + <NUM_LIT:2> , now ) <EOL> self . memcache . set ( '<STR_LIT>' , v ) <EOL> time . sleep ( now + <NUM_LIT:1> - time . time ( ) ) <EOL> self . assertEqual ( v , self . memcache . get ( '<STR_LIT>' ) ) <EOL> def test_long_value ( self ) : <EOL> string = '<STR_LIT>' . join ( [ random . choice ( "<STR_LIT>" ) for i in range ( <NUM_LIT> ) ] ) <EOL> self . memcache . set ( '<STR_LIT>' , string ) <EOL> string = self . memcache . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( string ) , <NUM_LIT> ) <EOL> def test_stats ( self ) : <EOL> ( key , stats ) = self . memcache . get_stats ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( '<STR_LIT>' , key ) <EOL> keys = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:time>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:version>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for key in keys : <EOL> self . assert_ ( stats . has_key ( key ) , "<STR_LIT>" % key ) <EOL> def test_unknown_command_returns_valid_result ( self ) : <EOL> response = self . memcache . add ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . assertEqual ( False , response ) <EOL> def test_that_disconnecting_and_reconnecting_works ( self ) : <EOL> v = random . randint ( <NUM_LIT:1> , <NUM_LIT:32> ) <EOL> self . memcache . set ( '<STR_LIT>' , v ) <EOL> self . memcache . disconnect_all ( ) <EOL> self . assertEqual ( v , int ( self . memcache . get ( '<STR_LIT>' ) ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
