@@ -116,6 +116,39 @@ async def delete_rows(self):
116116 }
117117 await self .target .client ._gapic_client .mutate_rows (request )
118118
119+ @CrossSync .convert
120+ async def retrieve_cell_value (self , target , row_key ):
121+ """
122+ Helper to read an individual row
123+ """
124+ from google .cloud .bigtable .data import ReadRowsQuery
125+
126+ row_list = await target .read_rows (ReadRowsQuery (row_keys = row_key ))
127+ assert len (row_list ) == 1
128+ row = row_list [0 ]
129+ cell = row .cells [0 ]
130+ return cell .value
131+
132+ @CrossSync .convert
133+ async def create_row_and_mutation (
134+ self , table , * , start_value = b"start" , new_value = b"new_value"
135+ ):
136+ """
137+ Helper to create a new row, and a sample set_cell mutation to change its value
138+ """
139+ from google .cloud .bigtable .data .mutations import SetCell
140+
141+ row_key = uuid .uuid4 ().hex .encode ()
142+ family = TEST_FAMILY
143+ qualifier = b"test-qualifier"
144+ await self .add_row (
145+ row_key , family = family , qualifier = qualifier , value = start_value
146+ )
147+ # ensure cell is initialized
148+ assert await self .retrieve_cell_value (table , row_key ) == start_value
149+
150+ mutation = SetCell (family = TEST_FAMILY , qualifier = qualifier , new_value = new_value )
151+ return row_key , mutation
119152
120153@CrossSync .convert_class (sync_name = "TestSystem" )
121154class TestSystemAsync (SystemTestRunner ):
@@ -148,41 +181,6 @@ async def target(self, client, table_id, authorized_view_id, instance_id, reques
148181 else :
149182 raise ValueError (f"unknown target type: { request .param } " )
150183
151- @CrossSync .convert
152- @pytest .mark .usefixtures ("target" )
153- async def _retrieve_cell_value (self , target , row_key ):
154- """
155- Helper to read an individual row
156- """
157- from google .cloud .bigtable .data import ReadRowsQuery
158-
159- row_list = await target .read_rows (ReadRowsQuery (row_keys = row_key ))
160- assert len (row_list ) == 1
161- row = row_list [0 ]
162- cell = row .cells [0 ]
163- return cell .value
164-
165- @CrossSync .convert
166- async def _create_row_and_mutation (
167- self , table , temp_rows , * , start_value = b"start" , new_value = b"new_value"
168- ):
169- """
170- Helper to create a new row, and a sample set_cell mutation to change its value
171- """
172- from google .cloud .bigtable .data .mutations import SetCell
173-
174- row_key = uuid .uuid4 ().hex .encode ()
175- family = TEST_FAMILY
176- qualifier = b"test-qualifier"
177- await temp_rows .add_row (
178- row_key , family = family , qualifier = qualifier , value = start_value
179- )
180- # ensure cell is initialized
181- assert await self ._retrieve_cell_value (table , row_key ) == start_value
182-
183- mutation = SetCell (family = TEST_FAMILY , qualifier = qualifier , new_value = new_value )
184- return row_key , mutation
185-
186184 @CrossSync .convert
187185 @CrossSync .pytest_fixture (scope = "function" )
188186 async def temp_rows (self , target ):
@@ -280,13 +278,13 @@ async def test_mutation_set_cell(self, target, temp_rows):
280278 """
281279 row_key = b"bulk_mutate"
282280 new_value = uuid .uuid4 ().hex .encode ()
283- row_key , mutation = await self . _create_row_and_mutation (
284- target , temp_rows , new_value = new_value
281+ row_key , mutation = await temp_rows . create_row_and_mutation (
282+ target , new_value = new_value
285283 )
286284 await target .mutate_row (row_key , mutation )
287285
288286 # ensure cell is updated
289- assert (await self . _retrieve_cell_value (target , row_key )) == new_value
287+ assert (await temp_rows . retrieve_cell_value (target , row_key )) == new_value
290288
291289 @CrossSync .pytest
292290 @pytest .mark .usefixtures ("target" )
@@ -308,14 +306,14 @@ async def test_mutation_add_to_cell(self, target, temp_rows):
308306 await target .mutate_row (
309307 row_key , AddToCell (family , qualifier , 1 , timestamp_micros = 0 )
310308 )
311- encoded_result = await self . _retrieve_cell_value (target , row_key )
309+ encoded_result = await temp_rows . retrieve_cell_value (target , row_key )
312310 int_result = int .from_bytes (encoded_result , byteorder = "big" )
313311 assert int_result == 1
314312 # update again
315313 await target .mutate_row (
316314 row_key , AddToCell (family , qualifier , 9 , timestamp_micros = 0 )
317315 )
318- encoded_result = await self . _retrieve_cell_value (target , row_key )
316+ encoded_result = await temp_rows . retrieve_cell_value (target , row_key )
319317 int_result = int .from_bytes (encoded_result , byteorder = "big" )
320318 assert int_result == 10
321319
@@ -357,15 +355,15 @@ async def test_bulk_mutations_set_cell(self, client, target, temp_rows):
357355 from google .cloud .bigtable .data .mutations import RowMutationEntry
358356
359357 new_value = uuid .uuid4 ().hex .encode ()
360- row_key , mutation = await self . _create_row_and_mutation (
361- target , temp_rows , new_value = new_value
358+ row_key , mutation = await temp_rows . create_row_and_mutation (
359+ target , new_value = new_value
362360 )
363361 bulk_mutation = RowMutationEntry (row_key , [mutation ])
364362
365363 await target .bulk_mutate_rows ([bulk_mutation ])
366364
367365 # ensure cell is updated
368- assert (await self . _retrieve_cell_value (target , row_key )) == new_value
366+ assert (await temp_rows . retrieve_cell_value (target , row_key )) == new_value
369367
370368 @CrossSync .pytest
371369 async def test_bulk_mutations_raise_exception (self , client , target ):
@@ -403,11 +401,11 @@ async def test_mutations_batcher_context_manager(self, client, target, temp_rows
403401 from google .cloud .bigtable .data .mutations import RowMutationEntry
404402
405403 new_value , new_value2 = [uuid .uuid4 ().hex .encode () for _ in range (2 )]
406- row_key , mutation = await self . _create_row_and_mutation (
407- target , temp_rows , new_value = new_value
404+ row_key , mutation = await temp_rows . create_row_and_mutation (
405+ target , new_value = new_value
408406 )
409- row_key2 , mutation2 = await self . _create_row_and_mutation (
410- target , temp_rows , new_value = new_value2
407+ row_key2 , mutation2 = await temp_rows . create_row_and_mutation (
408+ target , new_value = new_value2
411409 )
412410 bulk_mutation = RowMutationEntry (row_key , [mutation ])
413411 bulk_mutation2 = RowMutationEntry (row_key2 , [mutation2 ])
@@ -416,7 +414,7 @@ async def test_mutations_batcher_context_manager(self, client, target, temp_rows
416414 await batcher .append (bulk_mutation )
417415 await batcher .append (bulk_mutation2 )
418416 # ensure cell is updated
419- assert (await self . _retrieve_cell_value (target , row_key )) == new_value
417+ assert (await temp_rows . retrieve_cell_value (target , row_key )) == new_value
420418 assert len (batcher ._staged_entries ) == 0
421419
422420 @pytest .mark .usefixtures ("client" )
@@ -432,8 +430,8 @@ async def test_mutations_batcher_timer_flush(self, client, target, temp_rows):
432430 from google .cloud .bigtable .data .mutations import RowMutationEntry
433431
434432 new_value = uuid .uuid4 ().hex .encode ()
435- row_key , mutation = await self . _create_row_and_mutation (
436- target , temp_rows , new_value = new_value
433+ row_key , mutation = await temp_rows . create_row_and_mutation (
434+ target , new_value = new_value
437435 )
438436 bulk_mutation = RowMutationEntry (row_key , [mutation ])
439437 flush_interval = 0.1
@@ -444,7 +442,7 @@ async def test_mutations_batcher_timer_flush(self, client, target, temp_rows):
444442 await CrossSync .sleep (flush_interval + 0.1 )
445443 assert len (batcher ._staged_entries ) == 0
446444 # ensure cell is updated
447- assert (await self . _retrieve_cell_value (target , row_key )) == new_value
445+ assert (await temp_rows . retrieve_cell_value (target , row_key )) == new_value
448446
449447 @pytest .mark .usefixtures ("client" )
450448 @pytest .mark .usefixtures ("target" )
@@ -459,12 +457,12 @@ async def test_mutations_batcher_count_flush(self, client, target, temp_rows):
459457 from google .cloud .bigtable .data .mutations import RowMutationEntry
460458
461459 new_value , new_value2 = [uuid .uuid4 ().hex .encode () for _ in range (2 )]
462- row_key , mutation = await self . _create_row_and_mutation (
463- target , temp_rows , new_value = new_value
460+ row_key , mutation = await temp_rows . create_row_and_mutation (
461+ target , new_value = new_value
464462 )
465463 bulk_mutation = RowMutationEntry (row_key , [mutation ])
466- row_key2 , mutation2 = await self . _create_row_and_mutation (
467- target , temp_rows , new_value = new_value2
464+ row_key2 , mutation2 = await temp_rows . create_row_and_mutation (
465+ target , new_value = new_value2
468466 )
469467 bulk_mutation2 = RowMutationEntry (row_key2 , [mutation2 ])
470468
@@ -484,8 +482,8 @@ async def test_mutations_batcher_count_flush(self, client, target, temp_rows):
484482 assert len (batcher ._staged_entries ) == 0
485483 assert len (batcher ._flush_jobs ) == 0
486484 # ensure cells were updated
487- assert (await self . _retrieve_cell_value (target , row_key )) == new_value
488- assert (await self . _retrieve_cell_value (target , row_key2 )) == new_value2
485+ assert (await temp_rows . retrieve_cell_value (target , row_key )) == new_value
486+ assert (await temp_rows . retrieve_cell_value (target , row_key2 )) == new_value2
489487
490488 @pytest .mark .usefixtures ("client" )
491489 @pytest .mark .usefixtures ("target" )
@@ -500,12 +498,12 @@ async def test_mutations_batcher_bytes_flush(self, client, target, temp_rows):
500498 from google .cloud .bigtable .data .mutations import RowMutationEntry
501499
502500 new_value , new_value2 = [uuid .uuid4 ().hex .encode () for _ in range (2 )]
503- row_key , mutation = await self . _create_row_and_mutation (
504- target , temp_rows , new_value = new_value
501+ row_key , mutation = await temp_rows . create_row_and_mutation (
502+ target , new_value = new_value
505503 )
506504 bulk_mutation = RowMutationEntry (row_key , [mutation ])
507- row_key2 , mutation2 = await self . _create_row_and_mutation (
508- target , temp_rows , new_value = new_value2
505+ row_key2 , mutation2 = await temp_rows . create_row_and_mutation (
506+ target , new_value = new_value2
509507 )
510508 bulk_mutation2 = RowMutationEntry (row_key2 , [mutation2 ])
511509
@@ -525,8 +523,8 @@ async def test_mutations_batcher_bytes_flush(self, client, target, temp_rows):
525523 # for sync version: grab result
526524 future .result ()
527525 # ensure cells were updated
528- assert (await self . _retrieve_cell_value (target , row_key )) == new_value
529- assert (await self . _retrieve_cell_value (target , row_key2 )) == new_value2
526+ assert (await temp_rows . retrieve_cell_value (target , row_key )) == new_value
527+ assert (await temp_rows . retrieve_cell_value (target , row_key2 )) == new_value2
530528
531529 @pytest .mark .usefixtures ("client" )
532530 @pytest .mark .usefixtures ("target" )
@@ -539,12 +537,12 @@ async def test_mutations_batcher_no_flush(self, client, target, temp_rows):
539537
540538 new_value = uuid .uuid4 ().hex .encode ()
541539 start_value = b"unchanged"
542- row_key , mutation = await self . _create_row_and_mutation (
543- target , temp_rows , start_value = start_value , new_value = new_value
540+ row_key , mutation = await temp_rows . create_row_and_mutation (
541+ target , start_value = start_value , new_value = new_value
544542 )
545543 bulk_mutation = RowMutationEntry (row_key , [mutation ])
546- row_key2 , mutation2 = await self . _create_row_and_mutation (
547- target , temp_rows , start_value = start_value , new_value = new_value
544+ row_key2 , mutation2 = await temp_rows . create_row_and_mutation (
545+ target , start_value = start_value , new_value = new_value
548546 )
549547 bulk_mutation2 = RowMutationEntry (row_key2 , [mutation2 ])
550548
@@ -561,8 +559,8 @@ async def test_mutations_batcher_no_flush(self, client, target, temp_rows):
561559 assert len (batcher ._staged_entries ) == 2
562560 assert len (batcher ._flush_jobs ) == 0
563561 # ensure cells were not updated
564- assert (await self . _retrieve_cell_value (target , row_key )) == start_value
565- assert (await self . _retrieve_cell_value (target , row_key2 )) == start_value
562+ assert (await temp_rows . retrieve_cell_value (target , row_key )) == start_value
563+ assert (await temp_rows . retrieve_cell_value (target , row_key2 )) == start_value
566564
567565 @pytest .mark .usefixtures ("client" )
568566 @pytest .mark .usefixtures ("target" )
@@ -633,7 +631,7 @@ async def test_read_modify_write_row_increment(
633631 assert result [0 ].qualifier == qualifier
634632 assert int (result [0 ]) == expected
635633 # ensure that reading from server gives same value
636- assert (await self . _retrieve_cell_value (target , row_key )) == result [0 ].value
634+ assert (await temp_rows . retrieve_cell_value (target , row_key )) == result [0 ].value
637635
638636 @pytest .mark .usefixtures ("client" )
639637 @pytest .mark .usefixtures ("target" )
@@ -673,7 +671,7 @@ async def test_read_modify_write_row_append(
673671 assert result [0 ].qualifier == qualifier
674672 assert result [0 ].value == expected
675673 # ensure that reading from server gives same value
676- assert (await self . _retrieve_cell_value (target , row_key )) == result [0 ].value
674+ assert (await temp_rows . retrieve_cell_value (target , row_key )) == result [0 ].value
677675
678676 @pytest .mark .usefixtures ("client" )
679677 @pytest .mark .usefixtures ("target" )
@@ -710,7 +708,7 @@ async def test_read_modify_write_row_chained(self, client, target, temp_rows):
710708 + b"helloworld!"
711709 )
712710 # ensure that reading from server gives same value
713- assert (await self . _retrieve_cell_value (target , row_key )) == result [0 ].value
711+ assert (await temp_rows . retrieve_cell_value (target , row_key )) == result [0 ].value
714712
715713 @pytest .mark .usefixtures ("client" )
716714 @pytest .mark .usefixtures ("target" )
@@ -759,7 +757,7 @@ async def test_check_and_mutate(
759757 expected_value = (
760758 true_mutation_value if expected_result else false_mutation_value
761759 )
762- assert (await self . _retrieve_cell_value (target , row_key )) == expected_value
760+ assert (await temp_rows . retrieve_cell_value (target , row_key )) == expected_value
763761
764762 @pytest .mark .skipif (
765763 bool (os .environ .get (BIGTABLE_EMULATOR )),
0 commit comments