Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery: deprecation cleanups #6304

Merged
merged 2 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bigquery/google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def partitioning_type(self):
warnings.warn(
"This method will be deprecated in future versions. Please use "
"Table.time_partitioning.type_ instead.",
UserWarning)
PendingDeprecationWarning, stacklevel=2)
if self.time_partitioning is not None:
return self.time_partitioning.type_

Expand All @@ -545,7 +545,7 @@ def partitioning_type(self, value):
warnings.warn(
"This method will be deprecated in future versions. Please use "
"Table.time_partitioning.type_ instead.",
UserWarning)
PendingDeprecationWarning, stacklevel=2)
if self.time_partitioning is None:
self._properties['timePartitioning'] = {}
self._properties['timePartitioning']['type'] = value
Expand All @@ -561,7 +561,7 @@ def partition_expiration(self):
warnings.warn(
"This method will be deprecated in future versions. Please use "
"Table.time_partitioning.expiration_ms instead.",
UserWarning)
PendingDeprecationWarning, stacklevel=2)
if self.time_partitioning is not None:
return self.time_partitioning.expiration_ms

Expand All @@ -570,7 +570,7 @@ def partition_expiration(self, value):
warnings.warn(
"This method will be deprecated in future versions. Please use "
"Table.time_partitioning.expiration_ms instead.",
UserWarning)
PendingDeprecationWarning, stacklevel=2)
if self.time_partitioning is None:
self._properties['timePartitioning'] = {
'type': TimePartitioningType.DAY}
Expand Down Expand Up @@ -928,7 +928,7 @@ def partitioning_type(self):
warnings.warn(
"This method will be deprecated in future versions. Please use "
"TableListItem.time_partitioning.type_ instead.",
PendingDeprecationWarning)
PendingDeprecationWarning, stacklevel=2)
if self.time_partitioning is not None:
return self.time_partitioning.type_

Expand All @@ -942,7 +942,7 @@ def partition_expiration(self):
warnings.warn(
"This method will be deprecated in future versions. Please use "
"TableListItem.time_partitioning.expiration_ms instead.",
PendingDeprecationWarning)
PendingDeprecationWarning, stacklevel=2)
if self.time_partitioning is not None:
return self.time_partitioning.expiration_ms

Expand Down
4 changes: 2 additions & 2 deletions bigquery/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_update_dataset(self):
self.assertTrue(_dataset_exists(dataset))
self.assertIsNone(dataset.friendly_name)
self.assertIsNone(dataset.description)
self.assertEquals(dataset.labels, {})
self.assertEqual(dataset.labels, {})

dataset.friendly_name = 'Friendly'
dataset.description = 'Description'
Expand Down Expand Up @@ -400,7 +400,7 @@ def test_update_table(self):
self.assertTrue(_table_exists(table))
self.assertIsNone(table.friendly_name)
self.assertIsNone(table.description)
self.assertEquals(table.labels, {})
self.assertEqual(table.labels, {})
table.friendly_name = 'Friendly'
table.description = 'Description'
table.labels = {'priority': 'high', 'color': 'blue'}
Expand Down
2 changes: 1 addition & 1 deletion bigquery/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3834,7 +3834,7 @@ def test_list_partitions_with_string_id(self):
partition_list = client.list_partitions(
'{}.{}'.format(self.DS_ID, self.TABLE_ID))

self.assertEquals(len(partition_list), 0)
self.assertEqual(len(partition_list), 0)

def test_list_rows(self):
import datetime
Expand Down
55 changes: 42 additions & 13 deletions bigquery/tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def test_ctor(self):
self.assertIsNone(table.view_query)
self.assertIsNone(table.view_use_legacy_sql)
self.assertIsNone(table.external_data_configuration)
self.assertEquals(table.labels, {})
self.assertEqual(table.labels, {})
self.assertIsNone(table.encryption_configuration)
self.assertIsNone(table.time_partitioning)
self.assertIsNone(table.clustering_fields)
Expand Down Expand Up @@ -876,57 +876,68 @@ def test_time_partitioning_setter_none(self):
self.assertIsNone(table.time_partitioning)

def test_partitioning_type_setter(self):
import warnings
from google.cloud.bigquery.table import TimePartitioningType

dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
table = self._make_one(table_ref)

with mock.patch('warnings.warn') as warn_patch:
with warnings.catch_warnings(record=True) as warned:
self.assertIsNone(table.partitioning_type)

table.partitioning_type = TimePartitioningType.DAY

self.assertEqual(table.partitioning_type, 'DAY')

assert warn_patch.called
self.assertEqual(len(warned), 3)
for warning in warned:
self.assertIs(warning.category, PendingDeprecationWarning)

def test_partitioning_type_setter_w_time_partitioning_set(self):
import warnings
from google.cloud.bigquery.table import TimePartitioning

dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
table = self._make_one(table_ref)
table.time_partitioning = TimePartitioning()

with mock.patch('warnings.warn') as warn_patch:
with warnings.catch_warnings(record=True) as warned:
table.partitioning_type = 'NEW_FAKE_TYPE'

self.assertEqual(table.partitioning_type, 'NEW_FAKE_TYPE')

assert warn_patch.called
self.assertEqual(len(warned), 2)
for warning in warned:
self.assertIs(warning.category, PendingDeprecationWarning)

def test_partitioning_expiration_setter_w_time_partitioning_set(self):
import warnings
from google.cloud.bigquery.table import TimePartitioning

dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
table = self._make_one(table_ref)
table.time_partitioning = TimePartitioning()

with mock.patch('warnings.warn') as warn_patch:
with warnings.catch_warnings(record=True) as warned:
table.partition_expiration = 100000

self.assertEqual(table.partition_expiration, 100000)

assert warn_patch.called
self.assertEqual(len(warned), 2)
for warning in warned:
self.assertIs(warning.category, PendingDeprecationWarning)

def test_partition_expiration_setter(self):
import warnings

dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
table = self._make_one(table_ref)

with mock.patch('warnings.warn') as warn_patch:
with warnings.catch_warnings(record=True) as warned:
self.assertIsNone(table.partition_expiration)

table.partition_expiration = 100
Expand All @@ -935,7 +946,9 @@ def test_partition_expiration_setter(self):
# defaults to 'DAY' when expiration is set and type is not set
self.assertEqual(table.partitioning_type, 'DAY')

assert warn_patch.called
self.assertEqual(len(warned), 4)
for warning in warned:
self.assertIs(warning.category, PendingDeprecationWarning)

def test_clustering_fields_setter_w_fields(self):
dataset = DatasetReference(self.PROJECT, self.DS_ID)
Expand Down Expand Up @@ -1069,6 +1082,8 @@ def _make_one(self, *args, **kw):
return self._get_target_class()(*args, **kw)

def test_ctor(self):
import warnings

project = 'test-project'
dataset_id = 'test_dataset'
table_id = 'coffee_table'
Expand Down Expand Up @@ -1107,11 +1122,17 @@ def test_ctor(self):
self.assertEqual(table.time_partitioning.type_, 'DAY')
self.assertEqual(table.time_partitioning.expiration_ms, 10000)
self.assertEqual(table.time_partitioning.field, 'mycolumn')
self.assertEqual(table.partitioning_type, 'DAY')
self.assertEqual(table.partition_expiration, 10000)
self.assertEqual(table.labels['some-stuff'], 'this-is-a-label')
self.assertIsNone(table.view_use_legacy_sql)

with warnings.catch_warnings(record=True) as warned:
self.assertEqual(table.partitioning_type, 'DAY')
self.assertEqual(table.partition_expiration, 10000)

self.assertEqual(len(warned), 2)
for warning in warned:
self.assertIs(warning.category, PendingDeprecationWarning)

def test_ctor_view(self):
project = 'test-project'
dataset_id = 'test_dataset'
Expand Down Expand Up @@ -1142,6 +1163,8 @@ def test_ctor_view(self):
self.assertTrue(table.view_use_legacy_sql)

def test_ctor_missing_properties(self):
import warnings

resource = {
'tableReference': {
'projectId': 'testproject',
Expand All @@ -1157,11 +1180,17 @@ def test_ctor_missing_properties(self):
self.assertIsNone(table.friendly_name)
self.assertIsNone(table.table_type)
self.assertIsNone(table.time_partitioning)
self.assertIsNone(table.partitioning_type)
self.assertIsNone(table.partition_expiration)
self.assertEqual(table.labels, {})
self.assertIsNone(table.view_use_legacy_sql)

with warnings.catch_warnings(record=True) as warned:
self.assertIsNone(table.partitioning_type)
self.assertIsNone(table.partition_expiration)

self.assertEqual(len(warned), 2)
for warning in warned:
self.assertIs(warning.category, PendingDeprecationWarning)

def test_ctor_wo_project(self):
resource = {
'tableReference': {
Expand Down