Skip to content

Commit

Permalink
Uprev speedate (#1244)
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-runkle authored Mar 21, 2024
1 parent da16140 commit 193f5d7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions tests/serializers/test_any.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]'),
Expand Down Expand Up @@ -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'
Expand Down
12 changes: 6 additions & 6 deletions tests/serializers/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -39,14 +39,14 @@ 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')
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"'

0 comments on commit 193f5d7

Please sign in to comment.