rdblue commented on code in PR #5011:
URL: https://github.com/apache/iceberg/pull/5011#discussion_r895229695
##########
python/tests/test_types.py:
##########
@@ -204,3 +206,388 @@ def test_non_parameterized_type_equality(input_index,
input_type, check_index, c
assert input_type() == check_type()
else:
assert input_type() != check_type()
+
+
+# Examples based on
https://iceberg.apache.org/spec/#appendix-c-json-serialization
+
+
+class TestType(IcebergBaseModel):
+ __root__: IcebergType
+
+
+def test_serialization_boolean():
+ assert BooleanType().json() == '"boolean"'
+
+
+def test_deserialization_boolean():
+ assert TestType.parse_raw('"boolean"') == BooleanType()
+
+
+def test_str_boolean():
+ assert str(BooleanType()) == "boolean"
+
+
+def test_repr_boolean():
+ assert repr(BooleanType()) == "BooleanType()"
+
+
+def test_serialization_int():
+ assert IntegerType().json() == '"int"'
+
+
+def test_deserialization_int():
+ assert TestType.parse_raw('"int"') == IntegerType()
+
+
+def test_str_int():
+ assert str(IntegerType()) == "int"
+
+
+def test_repr_int():
+ assert repr(IntegerType()) == "IntegerType()"
+
+
+def test_serialization_long():
+ assert LongType().json() == '"long"'
+
+
+def test_deserialization_long():
+ assert TestType.parse_raw('"long"') == LongType()
+
+
+def test_str_long():
+ assert str(LongType()) == "long"
+
+
+def test_repr_long():
+ assert repr(LongType()) == "LongType()"
+
+
+def test_serialization_float():
+ assert FloatType().json() == '"float"'
+
+
+def test_deserialization_float():
+ assert TestType.parse_raw('"float"') == FloatType()
+
+
+def test_str_float():
+ assert str(FloatType()) == "float"
+
+
+def test_repr_float():
+ assert repr(FloatType()) == "FloatType()"
+
+
+def test_serialization_double():
+ assert DoubleType().json() == '"double"'
+
+
+def test_deserialization_double():
+ assert TestType.parse_raw('"double"') == DoubleType()
+
+
+def test_str_double():
+ assert str(DoubleType()) == "double"
+
+
+def test_repr_double():
+ assert repr(DoubleType()) == "DoubleType()"
+
+
+def test_serialization_date():
+ assert DateType().json() == '"date"'
+
+
+def test_deserialization_date():
+ assert TestType.parse_raw('"date"') == DateType()
+
+
+def test_str_date():
+ assert str(DateType()) == "date"
+
+
+def test_repr_date():
+ assert repr(DateType()) == "DateType()"
+
+
+def test_serialization_time():
+ assert TimeType().json() == '"time"'
+
+
+def test_deserialization_time():
+ assert TestType.parse_raw('"time"') == TimeType()
+
+
+def test_str_time():
+ assert str(TimeType()) == "time"
+
+
+def test_repr_time():
+ assert repr(TimeType()) == "TimeType()"
+
+
+def test_serialization_timestamp():
+ assert TimestampType().json() == '"timestamp"'
+
+
+def test_deserialization_timestamp():
+ assert TestType.parse_raw('"timestamp"') == TimestampType()
+
+
+def test_str_timestamp():
+ assert str(TimestampType()) == "timestamp"
+
+
+def test_repr_timestamp():
+ assert repr(TimestampType()) == "TimestampType()"
+
+
+def test_serialization_timestamptz():
+ assert TimestamptzType().json() == '"timestamptz"'
+
+
+def test_deserialization_timestamptz():
+ assert TestType.parse_raw('"timestamptz"') == TimestamptzType()
+
+
+def test_str_timestamptz():
+ assert str(TimestamptzType()) == "timestamptz"
+
+
+def test_repr_timestamptz():
+ assert repr(TimestamptzType()) == "TimestamptzType()"
+
+
+def test_serialization_string():
+ assert StringType().json() == '"string"'
+
+
+def test_deserialization_string():
+ assert TestType.parse_raw('"string"') == StringType()
+
+
+def test_str_string():
+ assert str(StringType()) == "string"
+
+
+def test_repr_string():
+ assert repr(StringType()) == "StringType()"
+
+
+def test_serialization_uuid():
+ assert UUIDType().json() == '"uuid"'
+
+
+def test_deserialization_uuid():
+ assert TestType.parse_raw('"uuid"') == UUIDType()
+
+
+def test_str_uuid():
+ assert str(UUIDType()) == "uuid"
+
+
+def test_repr_uuid():
+ assert repr(UUIDType()) == "UUIDType()"
+
+
+def test_serialization_fixed():
+ assert FixedType(22).json() == '"fixed[22]"'
+
+
+def test_deserialization_fixed():
+ fixed = TestType.parse_raw('"fixed[22]"')
+ assert fixed == FixedType(22)
+
+ inner = fixed.__root__
+ assert isinstance(inner, FixedType)
+ assert inner.length == 22
+
+
+def test_str_fixed():
+ assert str(FixedType(22)) == "fixed[22]"
+
+
+def test_repr_fixed():
+ assert repr(FixedType(22)) == "FixedType(length=22)"
+
+
+def test_serialization_binary():
+ assert BinaryType().json() == '"binary"'
+
+
+def test_deserialization_binary():
+ assert TestType.parse_raw('"binary"') == BinaryType()
+
+
+def test_str_binary():
+ assert str(BinaryType()) == "binary"
+
+
+def test_repr_binary():
+ assert repr(BinaryType()) == "BinaryType()"
+
+
+def test_serialization_decimal():
+ assert DecimalType(19, 25).json() == '"decimal(19, 25)"'
Review Comment:
Somewhat unrelated: Isn't this type invalid because the scale is greater
than the precision? (I think we check that in Java)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]