From 193f5d7a8627c988b1c7fab9a3712c779afbbe94 Mon Sep 17 00:00:00 2001 From: Sydney Runkle <54324534+sydney-runkle@users.noreply.github.com> Date: Thu, 21 Mar 2024 10:36:42 -0500 Subject: [PATCH] Uprev `speedate` (#1244) --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- tests/serializers/test_any.py | 6 +++--- tests/serializers/test_timedelta.py | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 31280f2cb..910e9b456 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -506,9 +506,9 @@ checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "speedate" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "242f76c50fd18cbf098607090ade73a08d39cfd84ea835f3796a2c855223b19b" +checksum = "c323c4e6fece5a5a1a2a7f726d243144cce9fbcfe3ce4d9f3c6ede726a2bc780" dependencies = [ "strum", "strum_macros 0.25.3", diff --git a/Cargo.toml b/Cargo.toml index 076a92666..46b1ed4ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ strum_macros = "0.26.1" serde_json = {version = "1.0.114", features = ["arbitrary_precision", "preserve_order"]} enum_dispatch = "0.3.8" serde = { version = "1.0.196", features = ["derive"] } -speedate = "0.13.0" +speedate = "0.14.0" smallvec = "1.13.1" ahash = "0.8.10" url = "2.5.0" diff --git a/tests/serializers/test_any.py b/tests/serializers/test_any.py index 875a3fcf1..281c96970 100644 --- a/tests/serializers/test_any.py +++ b/tests/serializers/test_any.py @@ -105,7 +105,7 @@ def test_set_member_db(any_serializer): (datetime(2032, 1, 1, 1, 1), b'"2032-01-01T01:01:00"'), (date(2022, 12, 3), b'"2022-12-03"'), (time(12, 30, 45), b'"12:30:45"'), - (timedelta(hours=2), b'"PT7200S"'), + (timedelta(hours=2), b'"PT2H"'), (MyDataclass(1, 'foo', 2), b'{"a":1,"b":"foo"}'), (MyModel(a=1, b='foo'), b'{"a":1,"b":"foo"}'), ([MyDataclass(1, 'a', 2), MyModel(a=2, b='b')], b'[{"a":1,"b":"a"},{"a":2,"b":"b"}]'), @@ -164,8 +164,8 @@ def test_any_with_date_serializer(): def test_any_with_timedelta_serializer(): s = SchemaSerializer(core_schema.any_schema(serialization={'type': 'timedelta'})) assert s.to_python(timedelta(hours=2)) == timedelta(hours=2) - assert s.to_python(timedelta(hours=2), mode='json') == 'PT7200S' - assert s.to_json(timedelta(hours=2)) == b'"PT7200S"' + assert s.to_python(timedelta(hours=2), mode='json') == 'PT2H' + assert s.to_json(timedelta(hours=2)) == b'"PT2H"' with pytest.warns(UserWarning) as warning_info: assert s.to_python(b'bang', mode='json') == 'bang' diff --git a/tests/serializers/test_timedelta.py b/tests/serializers/test_timedelta.py index 391da1d52..91b5716b0 100644 --- a/tests/serializers/test_timedelta.py +++ b/tests/serializers/test_timedelta.py @@ -14,8 +14,8 @@ def test_timedelta(): v = SchemaSerializer(core_schema.timedelta_schema()) assert v.to_python(timedelta(days=2, hours=3, minutes=4)) == timedelta(days=2, hours=3, minutes=4) - assert v.to_python(timedelta(days=2, hours=3, minutes=4), mode='json') == 'P2DT11040S' - assert v.to_json(timedelta(days=2, hours=3, minutes=4)) == b'"P2DT11040S"' + assert v.to_python(timedelta(days=2, hours=3, minutes=4), mode='json') == 'P2DT3H4M' + assert v.to_json(timedelta(days=2, hours=3, minutes=4)) == b'"P2DT3H4M"' with pytest.warns( UserWarning, match='Expected `timedelta` but got `int` - serialized value may not be as expected' @@ -39,8 +39,8 @@ def test_timedelta_float(): def test_timedelta_key(): v = SchemaSerializer(core_schema.dict_schema(core_schema.timedelta_schema(), core_schema.int_schema())) assert v.to_python({timedelta(days=2, hours=3, minutes=4): 1}) == {timedelta(days=2, hours=3, minutes=4): 1} - assert v.to_python({timedelta(days=2, hours=3, minutes=4): 1}, mode='json') == {'P2DT11040S': 1} - assert v.to_json({timedelta(days=2, hours=3, minutes=4): 1}) == b'{"P2DT11040S":1}' + assert v.to_python({timedelta(days=2, hours=3, minutes=4): 1}, mode='json') == {'P2DT3H4M': 1} + assert v.to_json({timedelta(days=2, hours=3, minutes=4): 1}) == b'{"P2DT3H4M":1}' @pytest.mark.skipif(not pandas, reason='pandas not installed') @@ -48,5 +48,5 @@ def test_pandas(): v = SchemaSerializer(core_schema.timedelta_schema()) d = pandas.Timestamp('2023-01-01T02:00:00Z') - pandas.Timestamp('2023-01-01T00:00:00Z') assert v.to_python(d) == d - assert v.to_python(d, mode='json') == 'PT7200S' - assert v.to_json(d) == b'"PT7200S"' + assert v.to_python(d, mode='json') == 'PT2H' + assert v.to_json(d) == b'"PT2H"'