<s> import unittest2 <EOL> from pyelevator import Elevator , WriteBatch <EOL> from pyelevator . constants import * <EOL> from . fakers import TestDaemon <EOL> class WriteBatchElevator ( unittest2 . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . elevator_daemon = TestDaemon ( ) <EOL> self . elevator_daemon . start ( ) <EOL> self . endpoint = '<STR_LIT>' . format ( self . elevator_daemon . bind , self . elevator_daemon . port ) <EOL> self . client = Elevator ( endpoint = self . endpoint ) <EOL> self . batch = WriteBatch ( endpoint = self . endpoint ) <EOL> def tearDown ( self ) : <EOL> self . elevator_daemon . stop ( ) <EOL> del self . elevator_daemon <EOL> del self . client <EOL> del self . batch <EOL> def _bootstrap_db ( self ) : <EOL> for l in [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' , '<STR_LIT:g>' , '<STR_LIT:h>' , '<STR_LIT:i>' , '<STR_LIT>' ] : <EOL> self . batch . Put ( l , l ) <EOL> self . batch . Write ( ) <EOL> def test_batch_put_only ( self ) : <EOL> for x in xrange ( <NUM_LIT:10> ) : <EOL> self . batch . Put ( str ( x ) , str ( x ) ) <EOL> self . assertEqual ( len ( self . batch . container ) , <NUM_LIT:10> ) <EOL> for elem in self . batch . container : <EOL> self . assertEqual ( elem [ <NUM_LIT:0> ] , SIGNAL_BATCH_PUT ) <EOL> self . assertIsInstance ( elem [ <NUM_LIT:1> ] , str ) <EOL> self . batch . Write ( ) <EOL> for x in xrange ( <NUM_LIT:10> ) : <EOL> r = self . client . Get ( str ( x ) ) <EOL> self . assertIsNotNone ( r ) <EOL> self . assertIsInstance ( r , str ) <EOL> self . assertEqual ( r , str ( x ) ) <EOL> def test_batch_mixed_put_delete ( self ) : <EOL> self . batch . Delete ( '<STR_LIT:a>' ) <EOL> self . batch . Put ( '<STR_LIT:a>' ) <EOL> self . batch . Delete ( '<STR_LIT:b>' ) <EOL> self . batch . Write ( ) <EOL> self . assertEqual ( self . client . Get ( '<STR_LIT:a>' ) , '<STR_LIT:a>' ) <EOL> self . assertIsNone ( self . client . Get ( '<STR_LIT:b>' ) ) <EOL> def test_batch_with ( self ) : <EOL> with self . batch as batch : <EOL> for x in xrange ( <NUM_LIT:10> ) : <EOL> batch . Put ( str ( x ) , str ( x ) ) <EOL> self . assertEqual ( len ( batch . container ) , <NUM_LIT:10> ) <EOL> for elem in batch . container : <EOL> self . assertEqual ( elem [ <NUM_LIT:0> ] , SIGNAL_BATCH_PUT ) <EOL> self . assertIsInstance ( elem [ <NUM_LIT:1> ] , str ) <EOL> for x in xrange ( <NUM_LIT:10> ) : <EOL> r = self . client . Get ( str ( x ) ) <EOL> self . assertIsNotNone ( r ) <EOL> self . assertIsInstance ( r , str ) <EOL> self . assertEqual ( r , str ( x ) ) </s>
