diff --git a/tests/serialization/serializers/test_serializers.py b/tests/serialization/serializers/test_serializers.py index aab9f913957b..e46f4e10b028 100644 --- a/tests/serialization/serializers/test_serializers.py +++ b/tests/serialization/serializers/test_serializers.py @@ -21,11 +21,13 @@ from unittest.mock import patch import numpy as np +import pendulum import pendulum.tz import pytest from dateutil.tz import tzutc from deltalake import DeltaTable -from pendulum import DateTime +from pendulum import DateTime, Timezone +from pendulum.tz.timezone import FixedTimezone from pyiceberg.catalog import Catalog from pyiceberg.io import FileIO from pyiceberg.table import Table @@ -39,6 +41,8 @@ else: from backports.zoneinfo import ZoneInfo +PENDULUM3 = pendulum.__version__.startswith("3") + class TestSerializers: def test_datetime(self): @@ -222,3 +226,77 @@ def test_deltalake(self, mock_table_uri, mock_version, mock_deltalake, mock_meta assert i.version() == d.version() assert i._storage_options == d._storage_options assert d._storage_options is None + + @pytest.mark.skipif(not PENDULUM3, reason="Test case for pendulum~=3") + @pytest.mark.parametrize( + "ser_value, expected", + [ + pytest.param( + { + "__classname__": "pendulum.datetime.DateTime", + "__version__": 2, + "__data__": { + "timestamp": 1680307200.0, + "tz": { + "__classname__": "builtins.tuple", + "__version__": 1, + "__data__": ["UTC", "pendulum.tz.timezone.FixedTimezone", 1, True], + }, + }, + }, + pendulum.datetime(2023, 4, 1, tz=Timezone("UTC")), + id="in-utc-timezone", + ), + pytest.param( + { + "__classname__": "pendulum.datetime.DateTime", + "__version__": 2, + "__data__": { + "timestamp": 1680292800.0, + "tz": { + "__classname__": "builtins.tuple", + "__version__": 1, + "__data__": ["Asia/Tbilisi", "pendulum.tz.timezone.Timezone", 1, True], + }, + }, + }, + pendulum.datetime(2023, 4, 1, tz=Timezone("Asia/Tbilisi")), + id="non-dts-timezone", + ), + pytest.param( + { + "__classname__": "pendulum.datetime.DateTime", + "__version__": 2, + "__data__": { + "timestamp": 1680303600.0, + "tz": { + "__classname__": "builtins.tuple", + "__version__": 1, + "__data__": ["Europe/London", "pendulum.tz.timezone.Timezone", 1, True], + }, + }, + }, + pendulum.datetime(2023, 4, 1, tz=Timezone("Europe/London")), + id="dts-timezone", + ), + pytest.param( + { + "__classname__": "pendulum.datetime.DateTime", + "__version__": 2, + "__data__": { + "timestamp": 1680310800.0, + "tz": { + "__classname__": "builtins.tuple", + "__version__": 1, + "__data__": [-3600, "pendulum.tz.timezone.FixedTimezone", 1, True], + }, + }, + }, + pendulum.datetime(2023, 4, 1, tz=FixedTimezone(-3600)), + id="offset-timezone", + ), + ], + ) + def test_pendulum_2_to_3(self, ser_value, expected): + """Test deserialize objects in pendulum 3 which serialised in pendulum 2.""" + assert deserialize(ser_value) == expected