<s> '''<STR_LIT>''' <EOL> from Queue import Queue , Empty , Full <EOL> import cql <EOL> from chai import Chai <EOL> from kairos . cassandra_backend import * <EOL> class CassandraTest ( Chai ) : <EOL> def setUp ( self ) : <EOL> super ( CassandraTest , self ) . setUp ( ) <EOL> self . series = CassandraSeries . __new__ ( CassandraSeries , '<STR_LIT>' ) <EOL> def test_init ( self ) : <EOL> client = mock ( ) <EOL> client . cql_major_version = <NUM_LIT:3> <EOL> attrs = [ '<STR_LIT:host>' , '<STR_LIT:port>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for attr in attrs : <EOL> setattr ( client , attr , attr . encode ( '<STR_LIT>' ) ) <EOL> with expect ( client . cursor ) . returns ( mock ( ) ) as c : <EOL> expect ( c . execute ) <EOL> expect ( c . close ) <EOL> self . series . __init__ ( client ) <EOL> assert_equals ( '<STR_LIT:float>' , self . series . _value_type ) <EOL> assert_equals ( '<STR_LIT>' , self . series . _table ) <EOL> for attr in attrs : <EOL> assert_equals ( getattr ( client , attr ) , getattr ( self . series , '<STR_LIT:_>' + attr ) ) <EOL> assert_equals ( <NUM_LIT:1> , self . series . _pool . qsize ( ) ) <EOL> assert_equals ( <NUM_LIT:0> , self . series . _pool . maxsize ) <EOL> assert_equals ( client , self . series . _pool . get ( ) ) <EOL> def test_init_when_invalid_cql_version ( self ) : <EOL> client = mock ( ) <EOL> client . cql_major_version = <NUM_LIT:2> <EOL> with assert_raises ( TypeError ) : <EOL> self . series . __init__ ( client ) <EOL> def test_init_handles_value_type ( self ) : <EOL> client = mock ( ) <EOL> client . cql_major_version = <NUM_LIT:3> <EOL> with expect ( client . cursor ) . returns ( mock ( ) ) as c : <EOL> expect ( c . execute ) <EOL> expect ( c . close ) <EOL> self . series . __init__ ( client , value_type = bool ) <EOL> assert_equals ( '<STR_LIT>' , self . series . _value_type ) <EOL> self . series . __init__ ( client , value_type = '<STR_LIT>' ) <EOL> assert_equals ( '<STR_LIT>' , self . series . _value_type ) <EOL> with assert_raises ( TypeError ) : <EOL> self . series . __init__ ( client , value_type = object ( ) ) <EOL> def test_init_handles_table_name ( self ) : <EOL> client = mock ( ) <EOL> client . cql_major_version = <NUM_LIT:3> <EOL> with expect ( client . cursor ) . returns ( mock ( ) ) as c : <EOL> expect ( c . execute ) <EOL> expect ( c . close ) <EOL> self . series . __init__ ( client , table_name = '<STR_LIT>' ) <EOL> assert_equals ( '<STR_LIT>' , self . series . _table ) <EOL> def test_init_sets_pool_size ( self ) : <EOL> client = mock ( ) <EOL> client . cql_major_version = <NUM_LIT:3> <EOL> with expect ( client . cursor ) . returns ( mock ( ) ) as c : <EOL> expect ( c . execute ) <EOL> expect ( c . close ) <EOL> self . series . __init__ ( client , pool_size = <NUM_LIT:20> ) <EOL> assert_equals ( <NUM_LIT:20> , self . series . _pool . maxsize ) <EOL> def test_connection_from_pool ( self ) : <EOL> self . series . _pool = Queue ( ) <EOL> self . series . _pool . put ( '<STR_LIT>' ) <EOL> assert_equals ( '<STR_LIT>' , self . series . _connection ( ) ) <EOL> assert_equals ( <NUM_LIT:0> , self . series . _pool . qsize ( ) ) <EOL> def test_connection_when_pool_is_empty ( self ) : <EOL> self . series . _pool = Queue ( <NUM_LIT:2> ) <EOL> self . series . _host = '<STR_LIT>' <EOL> self . series . _port = '<STR_LIT>' <EOL> self . series . _keyspace = '<STR_LIT>' <EOL> self . series . _cql_version = '<STR_LIT>' <EOL> self . series . _compression = '<STR_LIT>' <EOL> self . series . _consistency_level = '<STR_LIT>' <EOL> self . series . _transport = '<STR_LIT>' <EOL> self . series . _credentials = { '<STR_LIT:user>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' } <EOL> expect ( cql , '<STR_LIT>' ) . args ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> user = '<STR_LIT>' , password = '<STR_LIT>' , cql_version = '<STR_LIT>' , <EOL> compression = '<STR_LIT>' , consistency_level = '<STR_LIT>' , <EOL> transport = '<STR_LIT>' ) . returns ( '<STR_LIT>' ) <EOL> assert_equals ( '<STR_LIT>' , self . series . _connection ( ) ) <EOL> def test_return_when_pool_not_full ( self ) : <EOL> self . series . _pool = Queue ( <NUM_LIT:1> ) <EOL> assert_equals ( <NUM_LIT:0> , self . series . _pool . qsize ( ) ) <EOL> self . series . _return ( '<STR_LIT>' ) <EOL> assert_equals ( <NUM_LIT:1> , self . series . _pool . qsize ( ) ) <EOL> def test_return_when_pool_full ( self ) : <EOL> self . series . _pool = Queue ( <NUM_LIT:2> ) <EOL> self . series . _return ( '<STR_LIT:a>' ) <EOL> self . series . _return ( '<STR_LIT:b>' ) <EOL> self . series . _return ( '<STR_LIT:c>' ) <EOL> assert_equals ( <NUM_LIT:2> , self . series . _pool . qsize ( ) ) <EOL> assert_equals ( '<STR_LIT:a>' , self . series . _pool . get ( ) ) <EOL> assert_equals ( '<STR_LIT:b>' , self . series . _pool . get ( ) ) </s>
