-
Notifications
You must be signed in to change notification settings - Fork 292
Make TzInfo picklable #770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
41a43c3
Make TzInfo picklable
adriangb 2fd0df1
Improve test
adriangb b5e37e6
Fix export
adriangb 6f7528a
more tests
adriangb bf36108
remove unused code
adriangb 12f6962
Update src/input/datetime.rs
adriangb df52a8a
Update src/lib.rs
adriangb 8c33771
Update src/input/mod.rs
adriangb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import copy | ||
import json | ||
import pickle | ||
import platform | ||
import re | ||
from datetime import date, datetime, time, timedelta, timezone, tzinfo | ||
from decimal import Decimal | ||
from typing import Dict | ||
|
||
import pytest | ||
import pytz | ||
|
@@ -476,3 +478,38 @@ def test_tz_constraint_too_high(): | |
def test_tz_constraint_wrong(): | ||
with pytest.raises(SchemaError, match="Input should be 'aware' or 'naive"): | ||
SchemaValidator(core_schema.datetime_schema(tz_constraint='wrong')) | ||
|
||
|
||
def test_tz_pickle() -> None: | ||
""" | ||
https://github.com/pydantic/pydantic-core/issues/589 | ||
""" | ||
v = SchemaValidator(core_schema.datetime_schema()) | ||
original = datetime(2022, 6, 8, 12, 13, 14, tzinfo=timezone(timedelta(hours=-12, minutes=-15))) | ||
validated = v.validate_python('2022-06-08T12:13:14-12:15') | ||
assert validated == original | ||
assert pickle.loads(pickle.dumps(validated)) == validated == original | ||
|
||
|
||
def test_tz_hash() -> None: | ||
v = SchemaValidator(core_schema.datetime_schema()) | ||
lookup: Dict[datetime, str] = {} | ||
for day in range(1, 10): | ||
input_str = f'2022-06-{day:02}T12:13:14-12:15' | ||
validated = v.validate_python(input_str) | ||
lookup[validated] = input_str | ||
|
||
assert len(lookup) == 9 | ||
assert ( | ||
lookup[datetime(2022, 6, 8, 12, 13, 14, tzinfo=timezone(timedelta(hours=-12, minutes=-15)))] | ||
== '2022-06-08T12:13:14-12:15' | ||
) | ||
|
||
|
||
def test_tz_cmp() -> None: | ||
v = SchemaValidator(core_schema.datetime_schema()) | ||
validated1 = v.validate_python('2022-06-08T12:13:14-12:15') | ||
validated2 = v.validate_python('2022-06-08T12:13:14-12:14') | ||
|
||
assert validated1 > validated2 | ||
assert validated2 < validated1 | ||
Comment on lines
+494
to
+515
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are just testing existing properties |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this actually need to be exported? If it does, we should have a test for importing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does so that it can be unpickled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pickle test is already testing that it can be imported