Skip to content

Commit

Permalink
tests: suppress PDR warnings in table unit tests (#358)
Browse files Browse the repository at this point in the history
Closes #357.
  • Loading branch information
tseaver authored Jul 13, 2021
1 parent 05a3435 commit e73b8d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
5 changes: 3 additions & 2 deletions google/cloud/bigtable/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# limitations under the License.

"""User-friendly container for Google Cloud Bigtable Table."""

import warnings

from google.api_core import timeout
from google.api_core.exceptions import Aborted
from google.api_core.exceptions import DeadlineExceeded
Expand Down Expand Up @@ -45,8 +48,6 @@
bigtable_table_admin as table_admin_messages_v2_pb2,
)

import warnings

# Maximum number of mutations in bulk (MutateRowsRequest message):
# (https://cloud.google.com/bigtable/docs/reference/data/rpc/
# google.bigtable.v2#google.bigtable.v2.MutateRowRequest)
Expand Down
38 changes: 28 additions & 10 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@


import unittest
import warnings

import mock

from ._testing import _make_credentials
from google.api_core.exceptions import DeadlineExceeded

Expand Down Expand Up @@ -224,33 +226,56 @@ def test_row_factory_direct(self):
from google.cloud.bigtable.row import DirectRow

table, row_key = self._row_methods_helper()
row = table.row(row_key)
with warnings.catch_warnings(record=True) as warned:
row = table.row(row_key)

self.assertIsInstance(row, DirectRow)
self.assertEqual(row._row_key, row_key)
self.assertEqual(row._table, table)

self.assertEqual(len(warned), 1)
self.assertIs(warned[0].category, PendingDeprecationWarning)

def test_row_factory_conditional(self):
from google.cloud.bigtable.row import ConditionalRow

table, row_key = self._row_methods_helper()
filter_ = object()
row = table.row(row_key, filter_=filter_)

with warnings.catch_warnings(record=True) as warned:
row = table.row(row_key, filter_=filter_)

self.assertIsInstance(row, ConditionalRow)
self.assertEqual(row._row_key, row_key)
self.assertEqual(row._table, table)

self.assertEqual(len(warned), 1)
self.assertIs(warned[0].category, PendingDeprecationWarning)

def test_row_factory_append(self):
from google.cloud.bigtable.row import AppendRow

table, row_key = self._row_methods_helper()
row = table.row(row_key, append=True)

with warnings.catch_warnings(record=True) as warned:
row = table.row(row_key, append=True)

self.assertIsInstance(row, AppendRow)
self.assertEqual(row._row_key, row_key)
self.assertEqual(row._table, table)

self.assertEqual(len(warned), 1)
self.assertIs(warned[0].category, PendingDeprecationWarning)

def test_row_factory_failure(self):
table, row_key = self._row_methods_helper()
with self.assertRaises(ValueError):
with warnings.catch_warnings(record=True) as warned:
table.row(row_key, filter_=object(), append=True)

self.assertEqual(len(warned), 1)
self.assertIs(warned[0].category, PendingDeprecationWarning)

def test_direct_row(self):
from google.cloud.bigtable.row import DirectRow

Expand Down Expand Up @@ -282,11 +307,6 @@ def test_append_row(self):
self.assertEqual(row._row_key, row_key)
self.assertEqual(row._table, table)

def test_row_factory_failure(self):
table, row_key = self._row_methods_helper()
with self.assertRaises(ValueError):
table.row(row_key, filter_=object(), append=True)

def test___eq__(self):
credentials = _make_credentials()
client = self._make_client(
Expand Down Expand Up @@ -965,7 +985,6 @@ def test_yield_retry_rows(self):
from google.cloud.bigtable_admin_v2.services.bigtable_table_admin import (
client as bigtable_table_admin,
)
import warnings

data_api = mock.create_autospec(BigtableClient)
table_api = mock.create_autospec(bigtable_table_admin.BigtableTableAdminClient)
Expand Down Expand Up @@ -1035,7 +1054,6 @@ def test_yield_rows_with_row_set(self):
)
from google.cloud.bigtable.row_set import RowSet
from google.cloud.bigtable.row_set import RowRange
import warnings

data_api = mock.create_autospec(BigtableClient)
table_api = mock.create_autospec(bigtable_table_admin.BigtableTableAdminClient)
Expand Down

0 comments on commit e73b8d5

Please sign in to comment.