|
62 | 62 | (12, BinaryType),
|
63 | 63 | ]
|
64 | 64 |
|
| 65 | +primitive_types = { |
| 66 | + "boolean": BooleanType, |
| 67 | + "int": IntegerType, |
| 68 | + "long": LongType, |
| 69 | + "float": FloatType, |
| 70 | + "double": DoubleType, |
| 71 | + "date": DateType, |
| 72 | + "time": TimeType, |
| 73 | + "timestamp": TimestampType, |
| 74 | + "timestamptz": TimestamptzType, |
| 75 | + "string": StringType, |
| 76 | + "uuid": UUIDType, |
| 77 | + "binary": BinaryType, |
| 78 | +} |
| 79 | + |
65 | 80 |
|
66 | 81 | @pytest.mark.parametrize("input_index, input_type", non_parameterized_types)
|
67 | 82 | def test_repr_primitive_types(input_index: int, input_type: Type[PrimitiveType]) -> None:
|
@@ -231,6 +246,32 @@ def test_nested_field() -> None:
|
231 | 246 | assert "validation errors for NestedField" in str(exc_info.value)
|
232 | 247 |
|
233 | 248 |
|
| 249 | +def test_nested_field_complex_type_as_str_unsupported() -> None: |
| 250 | + unsupported_types = ["list", "map", "struct"] |
| 251 | + for type_str in unsupported_types: |
| 252 | + with pytest.raises(ValueError) as exc_info: |
| 253 | + _ = NestedField(1, "field", type_str, required=True) |
| 254 | + assert f"Unsupported field type: '{type_str}'" in str(exc_info.value) |
| 255 | + |
| 256 | + |
| 257 | +def test_nested_field_primitive_type_as_str() -> None: |
| 258 | + for type_str, type_class in primitive_types.items(): |
| 259 | + field_var = NestedField( |
| 260 | + 1, |
| 261 | + "field", |
| 262 | + type_str, |
| 263 | + required=True, |
| 264 | + ) |
| 265 | + assert isinstance( |
| 266 | + field_var.field_type, type_class |
| 267 | + ), f"Expected {type_class.__name__}, got {field_var.field_type.__class__.__name__}" |
| 268 | + |
| 269 | + # Test that passing 'bool' raises a ValueError, as it should be 'boolean' |
| 270 | + with pytest.raises(ValueError) as exc_info: |
| 271 | + _ = NestedField(1, "field", "bool", required=True) |
| 272 | + assert "Unsupported field type: 'bool'" in str(exc_info.value) |
| 273 | + |
| 274 | + |
234 | 275 | @pytest.mark.parametrize("input_index,input_type", non_parameterized_types)
|
235 | 276 | @pytest.mark.parametrize("check_index,check_type", non_parameterized_types)
|
236 | 277 | def test_non_parameterized_type_equality(
|
|
0 commit comments