From 11935301b32872f264bab5b9afd2cd9ee654b4e2 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 6 Dec 2024 11:23:34 -0600 Subject: [PATCH] chore: use more verbose paths in hello snippets (#1045) --- samples/beam/requirements-test.txt | 2 +- samples/hello/async_main.py | 14 +++++++------- samples/hello/main.py | 8 ++++++-- samples/hello/requirements-test.txt | 2 +- samples/hello_happybase/requirements-test.txt | 2 +- samples/instanceadmin/requirements-test.txt | 2 +- samples/metricscaler/requirements-test.txt | 2 +- samples/quickstart/requirements-test.txt | 2 +- samples/quickstart_happybase/requirements-test.txt | 2 +- samples/snippets/data_client/requirements-test.txt | 2 +- samples/snippets/deletes/deletes_async_test.py | 8 ++++++++ samples/snippets/deletes/requirements-test.txt | 2 +- .../snippets/filters/filter_snippets_async_test.py | 8 ++++++++ samples/snippets/filters/requirements-test.txt | 2 +- samples/snippets/reads/requirements-test.txt | 2 +- samples/snippets/writes/requirements-test.txt | 2 +- samples/tableadmin/requirements-test.txt | 2 +- 17 files changed, 42 insertions(+), 22 deletions(-) diff --git a/samples/beam/requirements-test.txt b/samples/beam/requirements-test.txt index fe93bd52f..e079f8a60 100644 --- a/samples/beam/requirements-test.txt +++ b/samples/beam/requirements-test.txt @@ -1 +1 @@ -pytest==8.3.2 +pytest diff --git a/samples/hello/async_main.py b/samples/hello/async_main.py index 0130161e1..34159bedb 100644 --- a/samples/hello/async_main.py +++ b/samples/hello/async_main.py @@ -31,11 +31,11 @@ # [START bigtable_async_hw_imports] from google.cloud import bigtable from google.cloud.bigtable.data import row_filters -from google.cloud.bigtable.data import RowMutationEntry -from google.cloud.bigtable.data import SetCell -from google.cloud.bigtable.data import ReadRowsQuery # [END bigtable_async_hw_imports] +# use to ignore warnings +row_filters + async def main(project_id, instance_id, table_id): # [START bigtable_async_hw_connect] @@ -85,8 +85,8 @@ async def main(project_id, instance_id, table_id): # # https://cloud.google.com/bigtable/docs/schema-design row_key = "greeting{}".format(i).encode() - row_mutation = RowMutationEntry( - row_key, SetCell(column_family_id, column, value) + row_mutation = bigtable.data.RowMutationEntry( + row_key, bigtable.data.SetCell(column_family_id, column, value) ) mutations.append(row_mutation) await table.bulk_mutate_rows(mutations) @@ -95,7 +95,7 @@ async def main(project_id, instance_id, table_id): # [START bigtable_async_hw_create_filter] # Create a filter to only retrieve the most recent version of the cell # for each column across entire row. - row_filter = row_filters.CellsColumnLimitFilter(1) + row_filter = bigtable.data.row_filters.CellsColumnLimitFilter(1) # [END bigtable_async_hw_create_filter] # [START bigtable_async_hw_get_with_filter] @@ -112,7 +112,7 @@ async def main(project_id, instance_id, table_id): # [START bigtable_async_hw_scan_with_filter] # [START bigtable_async_hw_scan_all] print("Scanning for all greetings:") - query = ReadRowsQuery(row_filter=row_filter) + query = bigtable.data.ReadRowsQuery(row_filter=row_filter) async for row in await table.read_rows_stream(query): cell = row.cells[0] print(cell.value.decode("utf-8")) diff --git a/samples/hello/main.py b/samples/hello/main.py index 3e5078608..41124e826 100644 --- a/samples/hello/main.py +++ b/samples/hello/main.py @@ -36,6 +36,10 @@ # [END bigtable_hw_imports] +# use to avoid warnings +row_filters +column_family + def main(project_id, instance_id, table_id): # [START bigtable_hw_connect] @@ -52,7 +56,7 @@ def main(project_id, instance_id, table_id): print("Creating column family cf1 with Max Version GC rule...") # Create a column family with GC policy : most recent N versions # Define the GC policy to retain only the most recent 2 versions - max_versions_rule = column_family.MaxVersionsGCRule(2) + max_versions_rule = bigtable.column_family.MaxVersionsGCRule(2) column_family_id = "cf1" column_families = {column_family_id: max_versions_rule} if not table.exists(): @@ -93,7 +97,7 @@ def main(project_id, instance_id, table_id): # [START bigtable_hw_create_filter] # Create a filter to only retrieve the most recent version of the cell # for each column across entire row. - row_filter = row_filters.CellsColumnLimitFilter(1) + row_filter = bigtable.row_filters.CellsColumnLimitFilter(1) # [END bigtable_hw_create_filter] # [START bigtable_hw_get_with_filter] diff --git a/samples/hello/requirements-test.txt b/samples/hello/requirements-test.txt index fe93bd52f..e079f8a60 100644 --- a/samples/hello/requirements-test.txt +++ b/samples/hello/requirements-test.txt @@ -1 +1 @@ -pytest==8.3.2 +pytest diff --git a/samples/hello_happybase/requirements-test.txt b/samples/hello_happybase/requirements-test.txt index fe93bd52f..e079f8a60 100644 --- a/samples/hello_happybase/requirements-test.txt +++ b/samples/hello_happybase/requirements-test.txt @@ -1 +1 @@ -pytest==8.3.2 +pytest diff --git a/samples/instanceadmin/requirements-test.txt b/samples/instanceadmin/requirements-test.txt index fe93bd52f..e079f8a60 100644 --- a/samples/instanceadmin/requirements-test.txt +++ b/samples/instanceadmin/requirements-test.txt @@ -1 +1 @@ -pytest==8.3.2 +pytest diff --git a/samples/metricscaler/requirements-test.txt b/samples/metricscaler/requirements-test.txt index caf5f029c..13d734378 100644 --- a/samples/metricscaler/requirements-test.txt +++ b/samples/metricscaler/requirements-test.txt @@ -1,3 +1,3 @@ -pytest==8.3.2 +pytest mock==5.1.0 google-cloud-testutils diff --git a/samples/quickstart/requirements-test.txt b/samples/quickstart/requirements-test.txt index a63626120..ee4ba0186 100644 --- a/samples/quickstart/requirements-test.txt +++ b/samples/quickstart/requirements-test.txt @@ -1,2 +1,2 @@ -pytest==8.3.2 +pytest pytest-asyncio diff --git a/samples/quickstart_happybase/requirements-test.txt b/samples/quickstart_happybase/requirements-test.txt index fe93bd52f..55b033e90 100644 --- a/samples/quickstart_happybase/requirements-test.txt +++ b/samples/quickstart_happybase/requirements-test.txt @@ -1 +1 @@ -pytest==8.3.2 +pytest \ No newline at end of file diff --git a/samples/snippets/data_client/requirements-test.txt b/samples/snippets/data_client/requirements-test.txt index a63626120..ee4ba0186 100644 --- a/samples/snippets/data_client/requirements-test.txt +++ b/samples/snippets/data_client/requirements-test.txt @@ -1,2 +1,2 @@ -pytest==8.3.2 +pytest pytest-asyncio diff --git a/samples/snippets/deletes/deletes_async_test.py b/samples/snippets/deletes/deletes_async_test.py index 9408a8320..4fb4898e5 100644 --- a/samples/snippets/deletes/deletes_async_test.py +++ b/samples/snippets/deletes/deletes_async_test.py @@ -30,6 +30,14 @@ TABLE_ID = f"mobile-time-series-deletes-async-{str(uuid.uuid4())[:16]}" +@pytest.fixture(scope="module") +def event_loop(): + import asyncio + loop = asyncio.get_event_loop_policy().new_event_loop() + yield loop + loop.close() + + @pytest_asyncio.fixture(scope="module", autouse=True) async def table_id() -> AsyncGenerator[str, None]: with create_table_cm(PROJECT, BIGTABLE_INSTANCE, TABLE_ID, {"stats_summary": None, "cell_plan": None}, verbose=False): diff --git a/samples/snippets/deletes/requirements-test.txt b/samples/snippets/deletes/requirements-test.txt index a63626120..ee4ba0186 100644 --- a/samples/snippets/deletes/requirements-test.txt +++ b/samples/snippets/deletes/requirements-test.txt @@ -1,2 +1,2 @@ -pytest==8.3.2 +pytest pytest-asyncio diff --git a/samples/snippets/filters/filter_snippets_async_test.py b/samples/snippets/filters/filter_snippets_async_test.py index 124db8157..a3f83a6f2 100644 --- a/samples/snippets/filters/filter_snippets_async_test.py +++ b/samples/snippets/filters/filter_snippets_async_test.py @@ -34,6 +34,14 @@ TABLE_ID = f"mobile-time-series-filters-async-{str(uuid.uuid4())[:16]}" +@pytest.fixture(scope="module") +def event_loop(): + import asyncio + loop = asyncio.get_event_loop_policy().new_event_loop() + yield loop + loop.close() + + @pytest_asyncio.fixture(scope="module", autouse=True) async def table_id() -> AsyncGenerator[str, None]: with create_table_cm(PROJECT, BIGTABLE_INSTANCE, TABLE_ID, {"stats_summary": None, "cell_plan": None}): diff --git a/samples/snippets/filters/requirements-test.txt b/samples/snippets/filters/requirements-test.txt index a63626120..ee4ba0186 100644 --- a/samples/snippets/filters/requirements-test.txt +++ b/samples/snippets/filters/requirements-test.txt @@ -1,2 +1,2 @@ -pytest==8.3.2 +pytest pytest-asyncio diff --git a/samples/snippets/reads/requirements-test.txt b/samples/snippets/reads/requirements-test.txt index fe93bd52f..e079f8a60 100644 --- a/samples/snippets/reads/requirements-test.txt +++ b/samples/snippets/reads/requirements-test.txt @@ -1 +1 @@ -pytest==8.3.2 +pytest diff --git a/samples/snippets/writes/requirements-test.txt b/samples/snippets/writes/requirements-test.txt index 0f4b18778..5e15eb26f 100644 --- a/samples/snippets/writes/requirements-test.txt +++ b/samples/snippets/writes/requirements-test.txt @@ -1,2 +1,2 @@ backoff==2.2.1 -pytest==8.3.2 +pytest diff --git a/samples/tableadmin/requirements-test.txt b/samples/tableadmin/requirements-test.txt index 7f86b7bc4..a4c9e9c0b 100644 --- a/samples/tableadmin/requirements-test.txt +++ b/samples/tableadmin/requirements-test.txt @@ -1,2 +1,2 @@ -pytest==8.3.2 +pytest google-cloud-testutils==1.4.0