|
20 | 20 |
|
21 | 21 | fromgoogle.cloudimportbigquery |
22 | 22 | fromgoogle.cloud.bigquery.standard_sqlimportStandardSqlStructType |
| 23 | +fromgoogle.cloud.bigqueryimportschema |
23 | 24 | fromgoogle.cloud.bigquery.schemaimportPolicyTagList |
24 | 25 |
|
25 | 26 |
|
@@ -130,8 +131,6 @@ def test_constructor_range_str(self): |
130 | 131 | self.assertEqual(field.range_element_type.element_type,"DATETIME") |
131 | 132 |
|
132 | 133 | deftest_to_api_repr(self): |
133 | | -fromgoogle.cloud.bigquery.schemaimportPolicyTagList |
134 | | - |
135 | 134 | policy=PolicyTagList(names=("foo","bar")) |
136 | 135 | self.assertEqual( |
137 | 136 | policy.to_api_repr(), |
@@ -886,8 +885,6 @@ def test_valid_mapping_representation(self): |
886 | 885 | classTestPolicyTags(unittest.TestCase): |
887 | 886 | @staticmethod |
888 | 887 | def_get_target_class(): |
889 | | -fromgoogle.cloud.bigquery.schemaimportPolicyTagList |
890 | | - |
891 | 888 | returnPolicyTagList |
892 | 889 |
|
893 | 890 | def_make_one(self,*args,**kw): |
@@ -1129,3 +1126,90 @@ def test_to_api_repr_parameterized(field, api): |
1129 | 1126 | fromgoogle.cloud.bigquery.schemaimportSchemaField |
1130 | 1127 |
|
1131 | 1128 | assertSchemaField(**field).to_api_repr()==api |
| 1129 | + |
| 1130 | + |
| 1131 | +classTestSerDeInfo: |
| 1132 | +"""Tests for the SerDeInfo class.""" |
| 1133 | + |
| 1134 | +@staticmethod |
| 1135 | +def_get_target_class(): |
| 1136 | +returnschema.SerDeInfo |
| 1137 | + |
| 1138 | +def_make_one(self,*args,**kwargs): |
| 1139 | +returnself._get_target_class()(*args,**kwargs) |
| 1140 | + |
| 1141 | +@pytest.mark.parametrize( |
| 1142 | +"serialization_library,name,parameters", |
| 1143 | + [ |
| 1144 | + ("testpath.to.LazySimpleSerDe",None,None), |
| 1145 | + ("testpath.to.LazySimpleSerDe","serde_name",None), |
| 1146 | + ("testpath.to.LazySimpleSerDe",None, {"key":"value"}), |
| 1147 | + ("testpath.to.LazySimpleSerDe","serde_name", {"key":"value"}), |
| 1148 | + ], |
| 1149 | + ) |
| 1150 | +deftest_ctor_valid_input(self,serialization_library,name,parameters): |
| 1151 | +serde_info=self._make_one( |
| 1152 | +serialization_library=serialization_library, |
| 1153 | +name=name, |
| 1154 | +parameters=parameters, |
| 1155 | + ) |
| 1156 | +assertserde_info.serialization_library==serialization_library |
| 1157 | +assertserde_info.name==name |
| 1158 | +assertserde_info.parameters==parameters |
| 1159 | + |
| 1160 | +@pytest.mark.parametrize( |
| 1161 | +"serialization_library,name,parameters", |
| 1162 | + [ |
| 1163 | + (123,None,None), |
| 1164 | + ("testpath.to.LazySimpleSerDe",123,None), |
| 1165 | + ("testpath.to.LazySimpleSerDe",None, ["test","list"]), |
| 1166 | + ("testpath.to.LazySimpleSerDe",None,123), |
| 1167 | + ], |
| 1168 | + ) |
| 1169 | +deftest_ctor_invalid_input(self,serialization_library,name,parameters): |
| 1170 | +withpytest.raises(TypeError)ase: |
| 1171 | +self._make_one( |
| 1172 | +serialization_library=serialization_library, |
| 1173 | +name=name, |
| 1174 | +parameters=parameters, |
| 1175 | + ) |
| 1176 | +# Looking for the first word from the string "Pass <variable> as..." |
| 1177 | +assert"Pass "instr(e.value) |
| 1178 | + |
| 1179 | +deftest_to_api_repr(self): |
| 1180 | +serde_info=self._make_one( |
| 1181 | +serialization_library="testpath.to.LazySimpleSerDe", |
| 1182 | +name="serde_name", |
| 1183 | +parameters={"key":"value"}, |
| 1184 | + ) |
| 1185 | +expected_repr= { |
| 1186 | +"serializationLibrary":"testpath.to.LazySimpleSerDe", |
| 1187 | +"name":"serde_name", |
| 1188 | +"parameters": {"key":"value"}, |
| 1189 | + } |
| 1190 | +assertserde_info.to_api_repr()==expected_repr |
| 1191 | + |
| 1192 | +deftest_from_api_repr(self): |
| 1193 | +"""GIVEN an api representation of a SerDeInfo object (i.e. resource) |
| 1194 | + WHEN converted into a SerDeInfo object using from_api_repr() |
| 1195 | + THEN it will have the representation in dict format as a SerDeInfo |
| 1196 | + object made directly (via _make_one()) and represented in dict format. |
| 1197 | + """ |
| 1198 | +api_repr= { |
| 1199 | +"serializationLibrary":"testpath.to.LazySimpleSerDe", |
| 1200 | +"name":"serde_name", |
| 1201 | +"parameters": {"key":"value"}, |
| 1202 | + } |
| 1203 | + |
| 1204 | +expected=self._make_one( |
| 1205 | +serialization_library="testpath.to.LazySimpleSerDe", |
| 1206 | +name="serde_name", |
| 1207 | +parameters={"key":"value"}, |
| 1208 | + ) |
| 1209 | + |
| 1210 | +klass=self._get_target_class() |
| 1211 | +result=klass.from_api_repr(api_repr) |
| 1212 | + |
| 1213 | +# We convert both to dict format because these classes do not have a |
| 1214 | +# __eq__() method to facilitate direct equality comparisons. |
| 1215 | +assertresult.to_api_repr()==expected.to_api_repr() |