8000 BigQuery: deprecation cleanups (#6304) · googleapis/google-cloud-python@c5c556e · GitHub
[go: up one dir, main page]

Skip to content

Commit c5c556e

Browse files
authored
BigQuery: deprecation cleanups (#6304)
* Remove use of deprecated 'assertEquals'. * Use 'PendingDeprecationWarning' and 'stacklevel=2' for future deprecations. Catch and assert the warnings in tests.
1 parent 372bad1 commit c5c556e

File tree

4 files changed

+51
-22
lines changed

4 files changed

+51
-22
lines changed

bigquery/google/cloud/bigquery/table.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def partitioning_type(self):
536536
warnings.warn(
537537
"This method will be deprecated in future versions. Please use "
538538
"Table.time_partitioning.type_ instead.",
539-
UserWarning)
539+
PendingDeprecationWarning, stacklevel=2)
540540
if self.time_partitioning is not None:
541541
return self.time_partitioning.type_
542542

@@ -545,7 +545,7 @@ def partitioning_type(self, value):
545545
warnings.warn(
546546
"This method will be deprecated in future versions. Please use "
547547
"Table.time_partitioning.type_ instead.",
548-
UserWarning)
548+
PendingDeprecationWarning, stacklevel=2)
549549
if self.time_partitioning is None:
550550
self._properties['timePartitioning'] = {}
551551
self._properties['timePartitioning']['type'] = value
@@ -561,7 +561,7 @@ def partition_expiration(self):
561561
warnings.warn(
562562
"This method will be deprecated in future versions. Please use "
563563
"Table.time_partitioning.expiration_ms instead.",
564-
UserWarning)
564+
PendingDeprecationWarning, stacklevel=2)
565565
if self.time_partitioning is not None:
566566
return self.time_partitioning.expiration_ms
567567

@@ -570,7 +570,7 @@ def partition_expiration(self, value):
570570
warnings.warn(
571571
"This method will be deprecated in future versions. Please use "
572572
"Table.time_partitioning.expiration_ms instead.",
573-
UserWarning)
573+
PendingDeprecationWarning, stacklevel=2)
574574
if self.time_partitioning is None:
575575
self._properties['timePartitioning'] = {
576576
'type': TimePartitioningType.DAY}
@@ -928,7 +928,7 @@ def partitioning_type(self):
928928
warnings.warn(
929929
"This method will be deprecated in future versions. Please use "
930930
"TableListItem.time_partitioning.type_ instead.",
931-
PendingDeprecationWarning)
931+
PendingDeprecationWarning, stacklevel=2)
932932
if self.time_partitioning is not None:
933933
return self.time_partitioning.type_
934934

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

bigquery/tests/system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_update_dataset(self):
204204
self.assertTrue(_dataset_exists(dataset))
205205
self.assertIsNone(dataset.friendly_name)
206206
self.assertIsNone(dataset.description)
207-
self.assertEquals(dataset.labels, {})
207+
self.assertEqual(dataset.labels, {})
208208

209209
dataset.friendly_name = 'Friendly'
210210
dataset.description = 'Description'
@@ -400,7 +400,7 @@ def test_update_table(self):
400400
self.assertTrue(_table_exists(table))
401401
self.assertIsNone(table.friendly_name)
402402
self.assertIsNone(table.description)
403-
self.assertEquals(table.labels, {})
403+
self.assertEqual(table.labels, {})
404404
table.friendly_name = 'Friendly'
405405
table.description = 'Description'
406406
table.labels = {'priority': 'high', 'color': 'blue'}

bigquery/tests/unit/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3834,7 +3834,7 @@ def test_list_partitions_with_string_id(self):
38343834
partition_list = client.list_partitions(
38353835
'{}.{}'.format(self.DS_ID, self.TABLE_ID))
38363836

3837-
self.assertEquals(len(partition_list), 0)
3837+
self.assertEqual(len(partition_list), 0)
38383838

38393839
def test_list_rows(self):
CBEF
38403840
import datetime

bigquery/tests/unit/test_table.py

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ def test_ctor(self):
472472
self.assertIsNone(table.view_query)
473473
self.assertIsNone(table.view_use_legacy_sql)
474474
self.assertIsNone(table.external_data_configuration)
475-
self.assertEquals(table.labels, {})
475+
self.assertEqual(table.labels, {})
476476
self.assertIsNone(table.encryption_configuration)
477477
self.assertIsNone(table.time_partitioning)
478478
self.assertIsNone(table.clustering_fields)
@@ -876,57 +876,68 @@ def test_time_partitioning_setter_none(self):
876876
self.assertIsNone(table.time_partitioning)
877877

878878
def test_partitioning_type_setter(self):
879+
import warnings
879880
from google.cloud.bigquery.table import TimePartitioningType
880881

881882
dataset = DatasetReference(self.PROJECT, self.DS_ID)
882883
table_ref = dataset.table(self.TABLE_NAME)
883884
table = self._make_one(table_ref)
884885

885-
with mock.patch('warnings.warn') as warn_patch:
886+
with warnings.catch_warnings(record=True) as warned:
886887
self.assertIsNone(table.partitioning_type)
887888

888889
table.partitioning_type = TimePartitioningType.DAY
889890

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

892-
assert warn_patch.called
893+
self.assertEqual(len(warned), 3)
894+
for warning in warned:
895+
self.assertIs(warning.category, PendingDeprecationWarning)
893896

894897
def test_partitioning_type_setter_w_time_partitioning_set(self):
898+
import warnings
895899
from google.cloud.bigquery.table import TimePartitioning
896900

897901
dataset = DatasetReference(self.PROJECT, self.DS_ID)
898902
table_ref = dataset.table(self.TABLE_NAME)
899903
table = self._make_one(table_ref)
900904
table.time_partitioning = TimePartitioning()
901905

902-
with mock.patch('warnings.warn') as warn_patch:
906+
with warnings.catch_warnings(record=True) as warned:
903907
table.partitioning_type = 'NEW_FAKE_TYPE'
904908

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

907-
assert warn_patch.called
911+
self.assertEqual(len(warned), 2)
912+
for warning in warned:
913+
self.assertIs(warning.category, PendingDeprecationWarning)
908914

909915
def test_partitioning_expiration_setter_w_time_partitioning_set(self):
916+
import warnings
910917
from google.cloud.bigquery.table import TimePartitioning
911918

912919
dataset = DatasetReference(self.PROJECT, self.DS_ID)
913920
table_ref = dataset.table(self.TABLE_NAME)
914921
table = self._make_one(table_ref)
915922
table.time_partitioning = TimePartitioning()
916923

917-
with mock.patch('warnings.warn') as warn_patch:
924+
with warnings.catch_warnings(record=True) as warned:
918925
table.partition_expiration = 100000
919926

920927
self.assertEqual(table.partition_expiration, 100000)
921928

922-
assert warn_patch.called
929+
self.assertEqual(len(warned), 2)
930+
for warning in warned:
931+
self.assertIs(warning.category, PendingDeprecationWarning)
923932

924933
def test_partition_expiration_setter(self):
934+
import warnings
935+
925936
dataset = Datase 3FD1 tReference(self.PROJECT, self.DS_ID)
926937
table_ref = dataset.table(self.TABLE_NAME)
927938
table = self._make_one(table_ref)
928939

929-
with mock.patch('warnings.warn') as warn_patch:
940+
with warnings.catch_warnings(record=True) as warned:
930941
self.assertIsNone(table.partition_expiration)
931942

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

938-
assert warn_patch.called
949+
self.assertEqual(len(warned), 4)
950+
for warning in warned:
951+
self.assertIs(warning.category, PendingDeprecationWarning)
939952

940953
def test_clustering_fields_setter_w_fields(self):
941954
dataset = DatasetReference(self.PROJECT, self.DS_ID)
@@ -1069,6 +1082,8 @@ def _make_one(self, *args, **kw):
10691082
return self._get_target_class()(*args, **kw)
10701083

10711084
def test_ctor(self):
1085+
import warnings
1086+
10721087
project = 'test-project'
10731088
dataset_id = 'test_dataset'
10741089
table_id = 'coffee_table'
@@ -1107,11 +1122,17 @@ def test_ctor(self):
11071122
self.assertEqual(table.time_partitioning.type_, 'DAY')
11081123
self.assertEqual(table.time_partitioning.expiration_ms, 10000)
11091124
self.assertEqual(table.time_partitioning.field, 'mycolumn')
1110-
self.assertEqual(table.partitioning_type, 'DAY')
1111-
self.assertEqual(table.partition_expiration, 10000)
11121125
self.assertEqual(table.labels['some-stuff'], 'this-is-a-label')
11131126
self.assertIsNone(table.view_use_legacy_sql)
11141127

1128+
with warnings.catch_warnings(record=True) as warned:
1129+
self.assertEqual(table.partitioning_type, 'DAY')
1130+
self.assertEqual(table.partition_expiration, 10000)
1131+
1132+
self.assertEqual(len(warned), 2)
1133+
for warning in warned:
1134+
self.assertIs(warning.category, PendingDeprecationWarning)
1135+
11151136
def test_ctor_view(self):
11161137
project = 'test-project'
11171138
dataset_id = 'test_dataset'
@@ -1142,6 +1163,8 @@ def test_ctor_view(self):
11421163
self.assertTrue(table.view_use_legacy_sql)
11431164

11441165
def test_ctor_missing_properties(self):
1166+
import warnings
1167+
11451168
resource = {
11461169
'tableReference': {
11471170
'projectId': 'testproject',
@@ -1157,11 +1180,17 @@ def test_ctor_missing_properties(self):
11571180
self.assertIsNone(table.friendly_name)
11581181
self.assertIsNone(table.table_type)
11591182
self.assertIsNone(table.time_partitioning)
1160-
self.assertIsNone(table.partitioning_type)
1161-
self.assertIsNone(table.partition_expiration)
11621183
self.assertEqual(table.labels, {})
11631184
self.assertIsNone(table.view_use_legacy_sql)
11641185

1186+
with warnings.catch_warnings(record=True) as warned:
1187+
self.assertIsNone(table.partitioning_type)
1188+
self.assertIsNone(table.partition_expiration)
1189+
1190+
self.assertEqual(len(warned), 2)
1191+
for warning in warned:
1192+
self.assertIs(warning.category, PendingDeprecationWarning)
1193+
11651194
def test_ctor_wo_project(self):
11661195
resource = {
11671196
'tableReference': {

0 commit comments

Comments
 (0)
0