@@ -472,7 +472,7 @@ def test_ctor(self):
472
472
self .assertIsNone (table .view_query )
473
473
self .assertIsNone (table .view_use_legacy_sql )
474
474
self .assertIsNone (table .external_data_configuration )
475
- self .assertEquals (table .labels , {})
475
+ self .assertEqual (table .labels , {})
476
476
self .assertIsNone (table .encryption_configuration )
477
477
self .assertIsNone (table .time_partitioning )
478
478
self .assertIsNone (table .clustering_fields )
@@ -876,57 +876,68 @@ def test_time_partitioning_setter_none(self):
876
876
self .assertIsNone (table .time_partitioning )
877
877
878
878
def test_partitioning_type_setter (self ):
879
+ import warnings
879
880
from google .cloud .bigquery .table import TimePartitioningType
880
881
881
882
dataset = DatasetReference (self .PROJECT , self .DS_ID )
882
883
table_ref = dataset .table (self .TABLE_NAME )
883
884
table = self ._make_one (table_ref )
884
885
885
- with mock . patch ( ' warnings.warn' ) as warn_patch :
886
+ with warnings .catch_warnings ( record = True ) as warned :
886
887
self .assertIsNone (table .partitioning_type )
887
888
888
889
table .partitioning_type = TimePartitioningType .DAY
889
890
890
891
self .assertEqual (table .partitioning_type , 'DAY' )
891
892
892
- assert warn_patch .called
893
+ self .assertEqual (len (warned ), 3 )
894
+ for warning in warned :
895
+ self .assertIs (warning .category , PendingDeprecationWarning )
893
896
894
897
def test_partitioning_type_setter_w_time_partitioning_set (self ):
898
+ import warnings
895
899
from google .cloud .bigquery .table import TimePartitioning
896
900
897
901
dataset = DatasetReference (self .PROJECT , self .DS_ID )
898
902
table_ref = dataset .table (self .TABLE_NAME )
899
903
table = self ._make_one (table_ref )
900
904
table .time_partitioning = TimePartitioning ()
901
905
902
- with mock . patch ( ' warnings.warn' ) as warn_patch :
906
+ with warnings .catch_warnings ( record = True ) as warned :
903
907
table .partitioning_type = 'NEW_FAKE_TYPE'
904
908
905
909
self .assertEqual (table .partitioning_type , 'NEW_FAKE_TYPE' )
906
910
907
- assert warn_patch .called
911
+ self .assertEqual (len (warned ), 2 )
912
+ for warning in warned :
913
+ self .assertIs (warning .category , PendingDeprecationWarning )
908
914
909
915
def test_partitioning_expiration_setter_w_time_partitioning_set (self ):
916
+ import warnings
910
917
from google .cloud .bigquery .table import TimePartitioning
911
918
912
919
dataset = DatasetReference (self .PROJECT , self .DS_ID )
913
920
table_ref = dataset .table (self .TABLE_NAME )
914
921
table = self ._make_one (table_ref )
915
922
table .time_partitioning = TimePartitioning ()
916
923
917
- with mock . patch ( ' warnings.warn' ) as warn_patch :
924
+ with warnings .catch_warnings ( record = True ) as warned :
918
925
table .partition_expiration = 100000
919
926
920
927
self .assertEqual (table .partition_expiration , 100000 )
921
928
922
- assert warn_patch .called
929
+ self .assertEqual (len (warned ), 2 )
930
+ for warning in warned :
931
+ self .assertIs (warning .category , PendingDeprecationWarning )
923
932
924
933
def test_partition_expiration_setter (self ):
934
+ import warnings
935
+
925
936
dataset = Datase
3FD1
tReference (self .PROJECT , self .DS_ID )
926
937
table_ref = dataset .table (self .TABLE_NAME )
927
938
table = self ._make_one (table_ref )
928
939
929
- with mock . patch ( ' warnings.warn' ) as warn_patch :
940
+ with warnings .catch_warnings ( record = True ) as warned :
930
941
self .assertIsNone (table .partition_expiration )
931
942
932
943
table .partition_expiration = 100
@@ -935,7 +946,9 @@ def test_partition_expiration_setter(self):
935
946
# defaults to 'DAY' when expiration is set and type is not set
936
947
self .assertEqual (table .partitioning_type , 'DAY' )
937
948
938
- assert warn_patch .called
949
+ self .assertEqual (len (warned ), 4 )
950
+ for warning in warned :
951
+ self .assertIs (warning .category , PendingDeprecationWarning )
939
952
940
953
def test_clustering_fields_setter_w_fields (self ):
941
954
dataset = DatasetReference (self .PROJECT , self .DS_ID )
@@ -1069,6 +1082,8 @@ def _make_one(self, *args, **kw):
1069
1082
return self ._get_target_class ()(* args , ** kw )
1070
1083
1071
1084
def test_ctor (self ):
1085
+ import warnings
1086
+
1072
1087
project = 'test-project'
1073
1088
dataset_id = 'test_dataset'
1074
1089
table_id = 'coffee_table'
@@ -1107,11 +1122,17 @@ def test_ctor(self):
1107
1122
self .assertEqual (table .time_partitioning .type_ , 'DAY' )
1108
1123
self .assertEqual (table .time_partitioning .expiration_ms , 10000 )
1109
1124
self .assertEqual (table .time_partitioning .field , 'mycolumn' )
1110
- self .assertEqual (table .partitioning_type , 'DAY' )
1111
- self .assertEqual (table .partition_expiration , 10000 )
1112
1125
self .assertEqual (table .labels ['some-stuff' ], 'this-is-a-label' )
1113
1126
self .assertIsNone (table .view_use_legacy_sql )
1114
1127
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
+
1115
1136
def test_ctor_view (self ):
1116
1137
project = 'test-project'
1117
1138
dataset_id = 'test_dataset'
@@ -1142,6 +1163,8 @@ def test_ctor_view(self):
1142
1163
self .assertTrue (table .view_use_legacy_sql )
1143
1164
1144
1165
def test_ctor_missing_properties (self ):
1166
+ import warnings
1167
+
1145
1168
resource = {
1146
1169
'tableReference' : {
1147
1170
'projectId' : 'testproject' ,
@@ -1157,11 +1180,17 @@ def test_ctor_missing_properties(self):
1157
1180
self .assertIsNone (table .friendly_name )
1158
1181
self .assertIsNone (table .table_type )
1159
1182
self .assertIsNone (table .time_partitioning )
1160
- self .assertIsNone (table .partitioning_type )
1161
- self .assertIsNone (table .partition_expiration )
1162
1183
self .assertEqual (table .labels , {})
1163
1184
self .assertIsNone (table .view_use_legacy_sql )
1164
1185
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
+
1165
1194
def test_ctor_wo_project (self ):
1166
1195
resource = {
1167
1196
'tableReference' : {
0 commit comments