|
65 | 65 | @pytest.mark.parametrize(
|
66 | 66 | "schema, actual, expected, expected_warns",
|
67 | 67 | [
|
68 |
| - (SIMPLE_SCHEMA, {"value": 12}, {"value": "12"}, None), |
69 | 68 | (SIMPLE_SCHEMA, {"value": 12}, {"value": "12"}, None),
|
70 | 69 | (
|
71 | 70 | SIMPLE_SCHEMA,
|
|
104 | 103 | COMPLEX_SCHEMA,
|
105 | 104 | {"prop": 12, "number_prop": "aa12", "array": [12]},
|
106 | 105 | {"prop": "12", "number_prop": "aa12", "array": ["12"]},
|
107 |
| - "Failed to transform value 'aa12' of type 'string' to 'number', key path: '.number_prop'", |
| 106 | + "Failed to transform value from type 'string' to type 'number' at path: 'number_prop'", |
108 | 107 | ),
|
109 | 108 | # Field too_many_types have ambigious type, skip formatting
|
110 | 109 | (
|
111 | 110 | COMPLEX_SCHEMA,
|
112 | 111 | {"prop": 12, "too_many_types": 1212, "array": [12]},
|
113 | 112 | {"prop": "12", "too_many_types": 1212, "array": ["12"]},
|
114 |
| - "Failed to transform value 1212 of type 'integer' to '['boolean', 'null', 'string']', key path: '.too_many_types'", |
| 113 | + "Failed to transform value from type 'integer' to type '['boolean', 'null', 'string']' at path: 'too_many_types'", |
115 | 114 | ),
|
116 | 115 | # Test null field
|
117 | 116 | (COMPLEX_SCHEMA, {"prop": None, "array": [12]}, {"prop": "None", "array": ["12"]}, None),
|
|
196 | 195 | },
|
197 | 196 | {"value": "string"},
|
198 | 197 | {"value": "string"},
|
199 |
| - "Failed to transform value 'string' of type 'string' to 'array', key path: '.value'", |
| 198 | + "Failed to transform value from type 'string' to type 'array' at path: 'value'", |
200 | 199 | ),
|
201 | 200 | (
|
202 | 201 | {
|
|
205 | 204 | },
|
206 | 205 | {"value": {"key": "value"}},
|
207 | 206 | {"value": {"key": "value"}},
|
208 |
| - "Failed to transform value {'key': 'value'} of type 'object' to 'array', key path: '.value'", |
| 207 | + "Failed to transform value from type '{'key': 'string'}' to type 'array' at path: 'value'", |
209 | 208 | ),
|
210 | 209 | (
|
211 | 210 | # Schema root object is not an object, no convertion should happen
|
212 | 211 | {"type": "integer"},
|
213 | 212 | {"value": "12"},
|
214 | 213 | {"value": "12"},
|
215 |
| - "Failed to transform value {'value': '12'} of type 'object' to 'integer', key path: '.'", |
| 214 | + "Failed to transform value from type '{'value': 'string'}' to type 'integer' at path: ''", |
216 | 215 | ),
|
217 | 216 | (
|
218 | 217 | # More than one type except null, no conversion should happen
|
219 | 218 | {"type": "object", "properties": {"value": {"type": ["string", "boolean", "null"]}}},
|
220 | 219 | {"value": 12},
|
221 | 220 | {"value": 12},
|
222 |
| - "Failed to transform value 12 of type 'integer' to '['string', 'boolean', 'null']', key path: '.value'", |
| 221 | + "Failed to transform value from type 'integer' to type '['string', 'boolean', 'null']' at path: 'value'", |
223 | 222 | ),
|
224 | 223 | (
|
225 | 224 | # Oneof not suported, no conversion for one_of_value should happen
|
|
252 | 251 | },
|
253 | 252 | {"value": {"key": "value"}},
|
254 | 253 | {"value": {"key": "value"}},
|
255 |
| - "Failed to transform value {'key': 'value'} of type 'object' to 'array', key path: '.value'", |
| 254 | + "Failed to transform value from type '{'key': 'string'}' to type 'array' at path: 'value'", |
256 | 255 | ),
|
257 | 256 | (
|
258 | 257 | {
|
|
263 | 262 | },
|
264 | 263 | {"value1": "value2"},
|
265 | 264 | {"value1": "value2"},
|
266 |
| - "Failed to transform value 'value2' of type 'string' to 'object', key path: '.value1'", |
| 265 | + "Failed to transform value from type 'string' to type 'object' at path: 'value1'", |
267 | 266 | ),
|
268 | 267 | (
|
269 | 268 | {
|
|
272 | 271 | },
|
273 | 272 | {"value": ["one", "two"]},
|
274 | 273 | {"value": ["one", "two"]},
|
275 |
| - "Failed to transform value 'one' of type 'string' to 'object', key path: '.value.0'", |
| 274 | + "Failed to transform value from type 'string' to type 'object' at path: 'value.0'", |
| 275 | + ), |
| 276 | + ( |
| 277 | + {"type": "string"}, |
| 278 | + None, |
| 279 | + None, |
| 280 | + "Failed to transform value from type 'null' to type 'string' at path: ''", |
| 281 | + ), |
| 282 | + ( |
| 283 | + {"type": "string"}, |
| 284 | + {"a": {"b": {"c": {"d": {"e": "deep value"}}}}}, |
| 285 | + {"a": {"b": {"c": {"d": {"e": "deep value"}}}}}, |
| 286 | + "Failed to transform value from type '{'a': {'b': {'c': 'object'}}}' to type 'string' at path: ''", |
276 | 287 | ),
|
277 | 288 | ],
|
| 289 | + ids=[ |
| 290 | + "simple_number_to_string", |
| 291 | + "preserve_unexpected_fields", |
| 292 | + "array_with_mixed_types", |
| 293 | + "nested_list_conversion", |
| 294 | + "array_in_nested_object", |
| 295 | + "string_to_boolean_nested", |
| 296 | + "empty_object", |
| 297 | + "string_to_integer", |
| 298 | + "skip_invalid_number_format", |
| 299 | + "skip_ambiguous_types", |
| 300 | + "null_to_string", |
| 301 | + "preserve_null_when_allowed", |
| 302 | + "very_nested_object_conversion", |
| 303 | + "null_in_nested_structure", |
| 304 | + "object_without_properties", |
| 305 | + "array_without_items", |
| 306 | + "non_array_to_array", |
| 307 | + "number_to_array", |
| 308 | + "null_to_array", |
| 309 | + "null_preserved_for_nullable_array", |
| 310 | + "number_to_string_array", |
| 311 | + "string_fails_object_array", |
| 312 | + "object_fails_array_with_string_array_items", |
| 313 | + "non_object_root_schema", |
| 314 | + "multiple_allowed_types", |
| 315 | + "oneof_not_supported", |
| 316 | + "facebook_cpc_number_conversion", |
| 317 | + "object_fails_array_with_string_item", |
| 318 | + "string_fails_object_conversion", |
| 319 | + "string_fails_object_in_array", |
| 320 | + "null_input_data", |
| 321 | + "max_nesting_depth_protection", |
| 322 | + ], |
278 | 323 | )
|
279 | 324 | def test_transform(schema, actual, expected, expected_warns, caplog):
|
280 | 325 | t = TypeTransformer(TransformConfig.DefaultSchemaNormalization)
|
|
0 commit comments