<s> from couchbase . exceptions import ( NotFoundError , DeltaBadvalError ) <EOL> from couchbase . tests . base import ConnectionTestCase <EOL> class ArithmeticTest ( ConnectionTestCase ) : <EOL> def test_trivial_incrdecr ( self ) : <EOL> key = self . gen_key ( "<STR_LIT>" ) <EOL> self . cb . remove ( key , quiet = True ) <EOL> rv_arith = self . cb . counter ( key , initial = <NUM_LIT:1> , delta = <NUM_LIT:1> ) <EOL> rv_get = self . cb . get ( key ) <EOL> self . assertEqual ( rv_arith . value , <NUM_LIT:1> ) <EOL> self . assertEqual ( int ( rv_get . value ) , <NUM_LIT:1> ) <EOL> rv = self . cb . counter ( key ) <EOL> self . assertEqual ( rv . value , <NUM_LIT:2> ) <EOL> rv = self . cb . counter ( key , delta = - <NUM_LIT:1> ) <EOL> self . assertEqual ( rv . value , <NUM_LIT:1> ) <EOL> self . assertEqual ( int ( self . cb . get ( key ) . value ) , <NUM_LIT:1> ) <EOL> rv = self . cb . counter ( key , delta = - <NUM_LIT:1> ) <EOL> self . assertEqual ( rv . value , <NUM_LIT:0> ) <EOL> self . assertEqual ( int ( self . cb . get ( key ) . value ) , <NUM_LIT:0> ) <EOL> def test_incr_notfound ( self ) : <EOL> key = self . gen_key ( "<STR_LIT>" ) <EOL> self . cb . remove ( key , quiet = True ) <EOL> self . assertRaises ( NotFoundError , self . cb . counter , key ) <EOL> def test_incr_badval ( self ) : <EOL> key = self . gen_key ( "<STR_LIT>" ) <EOL> self . cb . upsert ( key , "<STR_LIT>" ) <EOL> self . assertRaises ( DeltaBadvalError , self . cb . counter , key ) <EOL> def test_incr_multi ( self ) : <EOL> keys = self . gen_key_list ( amount = <NUM_LIT:5> , prefix = "<STR_LIT>" ) <EOL> def _multi_lim_assert ( expected ) : <EOL> for k , v in self . cb . get_multi ( keys ) . items ( ) : <EOL> self . assertTrue ( k in keys ) <EOL> self . assertEqual ( v . value , expected ) <EOL> self . cb . remove_multi ( keys , quiet = True ) <EOL> self . cb . counter_multi ( keys , initial = <NUM_LIT:5> ) <EOL> _multi_lim_assert ( <NUM_LIT:5> ) <EOL> self . cb . counter_multi ( keys ) <EOL> _multi_lim_assert ( <NUM_LIT:6> ) <EOL> self . cb . counter_multi ( keys , delta = - <NUM_LIT:1> ) <EOL> _multi_lim_assert ( <NUM_LIT:5> ) <EOL> self . cb . counter_multi ( keys , delta = <NUM_LIT:10> ) <EOL> _multi_lim_assert ( <NUM_LIT:15> ) <EOL> self . cb . counter_multi ( keys , delta = - <NUM_LIT:6> ) <EOL> _multi_lim_assert ( <NUM_LIT:9> ) <EOL> self . cb . remove ( keys [ <NUM_LIT:0> ] ) <EOL> self . assertRaises ( NotFoundError , self . cb . counter_multi , keys ) <EOL> def test_incr_extended ( self ) : <EOL> key = self . gen_key ( "<STR_LIT>" ) <EOL> self . cb . remove ( key , quiet = True ) <EOL> rv = self . cb . counter ( key , initial = <NUM_LIT:10> ) <EOL> self . assertEqual ( rv . value , <NUM_LIT:10> ) <EOL> srv = self . cb . upsert ( key , "<STR_LIT>" , cas = rv . cas ) <EOL> self . assertTrue ( srv . success ) <EOL> klist = self . gen_key_list ( amount = <NUM_LIT:5> , prefix = "<STR_LIT>" ) <EOL> self . cb . remove_multi ( klist , quiet = True ) <EOL> rvs = self . cb . counter_multi ( klist , initial = <NUM_LIT> ) <EOL> [ self . assertEqual ( x . value , <NUM_LIT> ) for x in rvs . values ( ) ] <EOL> self . assertEqual ( sorted ( list ( rvs . keys ( ) ) ) , sorted ( klist ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
