@@ -889,15 +889,45 @@ def _counter_inc_helper(self, row, column, value, commit_result):
889889 {tuple (column .split (':' )): incremented_value })
890890
891891 def test_counter_set (self ):
892+ import struct
893+ from gcloud ._testing import _Monkey
894+ from gcloud .bigtable .happybase import table as MUT
895+
892896 name = 'table-name'
893897 connection = None
894898 table = self ._makeOne (name , connection )
899+ batches_created = []
900+
901+ def make_batch (* args , ** kwargs ):
902+ result = _MockBatch (* args , ** kwargs )
903+ batches_created .append (result )
904+ return result
895905
896906 row = 'row-key'
897907 column = 'fam:col1'
898908 value = 42
899- with self .assertRaises (NotImplementedError ):
900- table .counter_set (row , column , value = value )
909+ with _Monkey (MUT , Batch = make_batch ):
910+ result = table .counter_set (row , column , value = value )
911+
912+ # There is no return value.
913+ self .assertEqual (result , None )
914+
915+ # Check how the batch was created and used.
916+ batch , = batches_created
917+ self .assertTrue (isinstance (batch , _MockBatch ))
918+ self .assertEqual (batch .args , (table ,))
919+ expected_kwargs = {
920+ 'timestamp' : None ,
921+ 'batch_size' : None ,
922+ 'transaction' : False ,
923+ 'wal' : MUT ._WAL_SENTINEL ,
924+ }
925+ self .assertEqual (batch .kwargs , expected_kwargs )
926+ # Make sure it was a successful context manager
927+ self .assertEqual (batch .exit_vals , [(None , None , None )])
928+ data = {column : struct .Struct ('>q' ).pack (value )}
929+ self .assertEqual (batch .put_args , [(row , data )])
930+ self .assertEqual (batch .delete_args , [])
901931
902932 def test_counter_inc (self ):
903933 import struct
0 commit comments