Skip to content

Commit a83c87e

Browse files
committed
rewrite old testcases for uuid support
1 parent 3b1d673 commit a83c87e

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

tests/expressions/test_literals.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def test_string_to_uuid_literal() -> None:
373373
uuid_str = literal(str(expected))
374374
uuid_lit = uuid_str.to(UUIDType())
375375

376-
assert expected.bytes == uuid_lit.value
376+
assert uuid_lit.value == expected
377377

378378

379379
def test_string_to_decimal_literal() -> None:
@@ -530,8 +530,7 @@ def test_binary_to_uuid() -> None:
530530
lit = literal(test_uuid.bytes)
531531
uuid_lit = lit.to(UUIDType())
532532
assert uuid_lit is not None
533-
assert lit.value == uuid_lit.value
534-
assert uuid_lit.value == test_uuid.bytes
533+
assert uuid_lit.value == test_uuid
535534

536535

537536
def test_incompatible_binary_to_uuid() -> None:
@@ -560,8 +559,7 @@ def test_fixed_to_uuid() -> None:
560559
lit = literal(test_uuid.bytes).to(FixedType(16))
561560
uuid_lit = lit.to(UUIDType())
562561
assert uuid_lit is not None
563-
assert lit.value == uuid_lit.value
564-
assert uuid_lit.value == test_uuid.bytes
562+
assert uuid_lit.value == test_uuid
565563

566564

567565
def test_incompatible_fixed_to_uuid() -> None:
@@ -900,7 +898,7 @@ def test_uuid_literal_initialization() -> None:
900898
test_uuid = uuid.UUID("f79c3e09-677c-4bbd-a479-3f349cb785e7")
901899
uuid_literal = literal(test_uuid)
902900
assert isinstance(uuid_literal, Literal)
903-
assert test_uuid.bytes == uuid_literal.value
901+
assert test_uuid == uuid_literal.value
904902

905903

906904
def test_uuid_to_fixed() -> None:

tests/io/test_pyarrow_stats.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
TableMetadataV1,
6767
TableMetadataV2,
6868
)
69+
from pyiceberg.typedef import UTF8
6970
from pyiceberg.types import (
7071
BooleanType,
7172
FloatType,
@@ -537,7 +538,7 @@ def test_metrics_primitive_types() -> None:
537538
assert datafile.lower_bounds[8] == STRUCT_INT64.pack(datetime_to_micros(datetime(2022, 1, 2, 17, 30, 34, 399)))
538539
assert datafile.lower_bounds[9] == STRUCT_INT64.pack(datetime_to_micros(datetime(2022, 1, 2, 17, 30, 34, 399, tz)))
539540
assert datafile.lower_bounds[10] == b"he"
540-
assert datafile.lower_bounds[11] == uuid.uuid3(uuid.NAMESPACE_DNS, "foo").bytes
541+
assert datafile.lower_bounds[11] == str(uuid.uuid3(uuid.NAMESPACE_DNS, "foo")).encode(UTF8)
541542
assert datafile.lower_bounds[12] == b"he"
542543
assert datafile.lower_bounds[13][::-1].ljust(4, b"\x00") == STRUCT_INT32.pack(12345)
543544
assert datafile.lower_bounds[14][::-1].ljust(8, b"\x00") == STRUCT_INT64.pack(12345679123456)
@@ -554,7 +555,7 @@ def test_metrics_primitive_types() -> None:
554555
assert datafile.upper_bounds[8] == STRUCT_INT64.pack(datetime_to_micros(datetime(2023, 2, 4, 13, 21, 4, 354)))
555556
assert datafile.upper_bounds[9] == STRUCT_INT64.pack(datetime_to_micros(datetime(2023, 2, 4, 13, 21, 4, 354, tz)))
556557
assert datafile.upper_bounds[10] == b"wp"
557-
assert datafile.upper_bounds[11] == uuid.uuid3(uuid.NAMESPACE_DNS, "bar").bytes
558+
assert datafile.upper_bounds[11] == str(uuid.uuid3(uuid.NAMESPACE_DNS, "bar")).encode(UTF8)
558559
assert datafile.upper_bounds[12] == b"wp"
559560
assert datafile.upper_bounds[13][::-1].ljust(4, b"\x00") == STRUCT_INT32.pack(67891)
560561
assert datafile.upper_bounds[14][::-1].ljust(8, b"\x00") == STRUCT_INT64.pack(67891234678912)

tests/test_conversions.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ def test_partition_to_py_raise_on_incorrect_precision_or_scale(
278278
(StringType(), b"foo", "foo"),
279279
(
280280
UUIDType(),
281-
b"\xf7\x9c>\tg|K\xbd\xa4y?4\x9c\xb7\x85\xe7",
282-
b"\xf7\x9c>\tg|K\xbd\xa4y?4\x9c\xb7\x85\xe7",
281+
b"f79c3e09-677c-4bbd-a479-3f349cb785e7",
282+
uuid.UUID("f79c3e09-677c-4bbd-a479-3f349cb785e7"),
283283
),
284-
(UUIDType(), b"\xf7\x9c>\tg|K\xbd\xa4y?4\x9c\xb7\x85\xe7", b"\xf7\x9c>\tg|K\xbd\xa4y?4\x9c\xb7\x85\xe7"),
284+
(UUIDType(), b"f79c3e09-677c-4bbd-a479-3f349cb785e7", uuid.UUID("f79c3e09-677c-4bbd-a479-3f349cb785e7")),
285285
(FixedType(3), b"foo", b"foo"),
286286
(BinaryType(), b"foo", b"foo"),
287287
(DecimalType(5, 2), b"\x30\x39", Decimal("123.45")),
@@ -316,10 +316,10 @@ def test_from_bytes(primitive_type: PrimitiveType, b: bytes, result: Any) -> Non
316316
(StringType(), b"foo", "foo"),
317317
(
318318
UUIDType(),
319-
b"\xf7\x9c>\tg|K\xbd\xa4y?4\x9c\xb7\x85\xe7",
320-
b"\xf7\x9c>\tg|K\xbd\xa4y?4\x9c\xb7\x85\xe7",
319+
b"f79c3e09-677c-4bbd-a479-3f349cb785e7",
320+
uuid.UUID("f79c3e09-677c-4bbd-a479-3f349cb785e7"),
321321
),
322-
(UUIDType(), b"\xf7\x9c>\tg|K\xbd\xa4y?4\x9c\xb7\x85\xe7", b"\xf7\x9c>\tg|K\xbd\xa4y?4\x9c\xb7\x85\xe7"),
322+
(UUIDType(), b"f79c3e09-677c-4bbd-a479-3f349cb785e7", uuid.UUID("f79c3e09-677c-4bbd-a479-3f349cb785e7")),
323323
(FixedType(3), b"foo", b"foo"),
324324
(BinaryType(), b"foo", b"foo"),
325325
(DecimalType(5, 2), b"\x30\x39", Decimal("123.45")),
@@ -356,9 +356,9 @@ def test_round_trip_conversion(primitive_type: PrimitiveType, b: bytes, result:
356356
(
357357
UUIDType(),
358358
uuid.UUID("f79c3e09-677c-4bbd-a479-3f349cb785e7"),
359-
b"\xf7\x9c>\tg|K\xbd\xa4y?4\x9c\xb7\x85\xe7",
359+
b"f79c3e09-677c-4bbd-a479-3f349cb785e7",
360360
),
361-
(UUIDType(), uuid.UUID("f79c3e09-677c-4bbd-a479-3f349cb785e7"), b"\xf7\x9c>\tg|K\xbd\xa4y?4\x9c\xb7\x85\xe7"),
361+
(UUIDType(), uuid.UUID("f79c3e09-677c-4bbd-a479-3f349cb785e7"), b"f79c3e09-677c-4bbd-a479-3f349cb785e7"),
362362
],
363363
)
364364
def test_uuid_to_bytes(primitive_type: PrimitiveType, v: Any, result: bytes) -> None:

0 commit comments

Comments
 (0)