test_datetime_parse.py — anthropic-sdk-python Source File
Architecture documentation for test_datetime_parse.py, a python file in the anthropic-sdk-python codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 59262a3f_6d06_383c_8999_fd1ad8974c65["test_datetime_parse.py"] 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"] 59262a3f_6d06_383c_8999_fd1ad8974c65 --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875 7e1d14c5_475e_409c_7c4e_1274f9d40aa9["datetime"] 59262a3f_6d06_383c_8999_fd1ad8974c65 --> 7e1d14c5_475e_409c_7c4e_1274f9d40aa9 cde8421b_93c7_41e4_d69d_2a3f1bade2f2["pytest"] 59262a3f_6d06_383c_8999_fd1ad8974c65 --> cde8421b_93c7_41e4_d69d_2a3f1bade2f2 d1009234_f799_7c53_7892_4262523206dd["anthropic._utils"] 59262a3f_6d06_383c_8999_fd1ad8974c65 --> d1009234_f799_7c53_7892_4262523206dd style 59262a3f_6d06_383c_8999_fd1ad8974c65 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""
Copied from https://github.com/pydantic/pydantic/blob/v1.10.22/tests/test_datetime_parse.py
with modifications so it works without pydantic v1 imports.
"""
from typing import Type, Union
from datetime import date, datetime, timezone, timedelta
import pytest
from anthropic._utils import parse_date, parse_datetime
def create_tz(minutes: int) -> timezone:
return timezone(timedelta(minutes=minutes))
@pytest.mark.parametrize(
"value,result",
[
# Valid inputs
("1494012444.883309", date(2017, 5, 5)),
(b"1494012444.883309", date(2017, 5, 5)),
(1_494_012_444.883_309, date(2017, 5, 5)),
("1494012444", date(2017, 5, 5)),
(1_494_012_444, date(2017, 5, 5)),
(0, date(1970, 1, 1)),
("2012-04-23", date(2012, 4, 23)),
(b"2012-04-23", date(2012, 4, 23)),
("2012-4-9", date(2012, 4, 9)),
(date(2012, 4, 9), date(2012, 4, 9)),
(datetime(2012, 4, 9, 12, 15), date(2012, 4, 9)),
# Invalid inputs
("x20120423", ValueError),
("2012-04-56", ValueError),
(19_999_999_999, date(2603, 10, 11)), # just before watershed
(20_000_000_001, date(1970, 8, 20)), # just after watershed
(1_549_316_052, date(2019, 2, 4)), # nowish in s
(1_549_316_052_104, date(2019, 2, 4)), # nowish in ms
(1_549_316_052_104_324, date(2019, 2, 4)), # nowish in μs
(1_549_316_052_104_324_096, date(2019, 2, 4)), # nowish in ns
("infinity", date(9999, 12, 31)),
("inf", date(9999, 12, 31)),
(float("inf"), date(9999, 12, 31)),
("infinity ", date(9999, 12, 31)),
(int("1" + "0" * 100), date(9999, 12, 31)),
(1e1000, date(9999, 12, 31)),
("-infinity", date(1, 1, 1)),
("-inf", date(1, 1, 1)),
("nan", ValueError),
],
)
def test_date_parsing(value: Union[str, bytes, int, float], result: Union[date, Type[Exception]]) -> None:
if type(result) == type and issubclass(result, Exception): # pyright: ignore[reportUnnecessaryIsInstance]
with pytest.raises(result):
parse_date(value)
else:
assert parse_date(value) == result
@pytest.mark.parametrize(
"value,result",
[
# Valid inputs
# values in seconds
("1494012444.883309", datetime(2017, 5, 5, 19, 27, 24, 883_309, tzinfo=timezone.utc)),
(1_494_012_444.883_309, datetime(2017, 5, 5, 19, 27, 24, 883_309, tzinfo=timezone.utc)),
("1494012444", datetime(2017, 5, 5, 19, 27, 24, tzinfo=timezone.utc)),
(b"1494012444", datetime(2017, 5, 5, 19, 27, 24, tzinfo=timezone.utc)),
(1_494_012_444, datetime(2017, 5, 5, 19, 27, 24, tzinfo=timezone.utc)),
# values in ms
("1494012444000.883309", datetime(2017, 5, 5, 19, 27, 24, 883, tzinfo=timezone.utc)),
("-1494012444000.883309", datetime(1922, 8, 29, 4, 32, 35, 999117, tzinfo=timezone.utc)),
(1_494_012_444_000, datetime(2017, 5, 5, 19, 27, 24, tzinfo=timezone.utc)),
("2012-04-23T09:15:00", datetime(2012, 4, 23, 9, 15)),
("2012-4-9 4:8:16", datetime(2012, 4, 9, 4, 8, 16)),
("2012-04-23T09:15:00Z", datetime(2012, 4, 23, 9, 15, 0, 0, timezone.utc)),
("2012-4-9 4:8:16-0320", datetime(2012, 4, 9, 4, 8, 16, 0, create_tz(-200))),
("2012-04-23T10:20:30.400+02:30", datetime(2012, 4, 23, 10, 20, 30, 400_000, create_tz(150))),
("2012-04-23T10:20:30.400+02", datetime(2012, 4, 23, 10, 20, 30, 400_000, create_tz(120))),
("2012-04-23T10:20:30.400-02", datetime(2012, 4, 23, 10, 20, 30, 400_000, create_tz(-120))),
(b"2012-04-23T10:20:30.400-02", datetime(2012, 4, 23, 10, 20, 30, 400_000, create_tz(-120))),
(datetime(2017, 5, 5), datetime(2017, 5, 5)),
(0, datetime(1970, 1, 1, 0, 0, 0, tzinfo=timezone.utc)),
# Invalid inputs
("x20120423091500", ValueError),
("2012-04-56T09:15:90", ValueError),
("2012-04-23T11:05:00-25:00", ValueError),
(19_999_999_999, datetime(2603, 10, 11, 11, 33, 19, tzinfo=timezone.utc)), # just before watershed
(20_000_000_001, datetime(1970, 8, 20, 11, 33, 20, 1000, tzinfo=timezone.utc)), # just after watershed
(1_549_316_052, datetime(2019, 2, 4, 21, 34, 12, 0, tzinfo=timezone.utc)), # nowish in s
(1_549_316_052_104, datetime(2019, 2, 4, 21, 34, 12, 104_000, tzinfo=timezone.utc)), # nowish in ms
(1_549_316_052_104_324, datetime(2019, 2, 4, 21, 34, 12, 104_324, tzinfo=timezone.utc)), # nowish in μs
(1_549_316_052_104_324_096, datetime(2019, 2, 4, 21, 34, 12, 104_324, tzinfo=timezone.utc)), # nowish in ns
("infinity", datetime(9999, 12, 31, 23, 59, 59, 999999)),
("inf", datetime(9999, 12, 31, 23, 59, 59, 999999)),
("inf ", datetime(9999, 12, 31, 23, 59, 59, 999999)),
(1e50, datetime(9999, 12, 31, 23, 59, 59, 999999)),
(float("inf"), datetime(9999, 12, 31, 23, 59, 59, 999999)),
("-infinity", datetime(1, 1, 1, 0, 0)),
("-inf", datetime(1, 1, 1, 0, 0)),
("nan", ValueError),
],
)
def test_datetime_parsing(value: Union[str, bytes, int, float], result: Union[datetime, Type[Exception]]) -> None:
if type(result) == type and issubclass(result, Exception): # pyright: ignore[reportUnnecessaryIsInstance]
with pytest.raises(result):
parse_datetime(value)
else:
assert parse_datetime(value) == result
Domain
Subdomains
Dependencies
- anthropic._utils
- datetime
- pytest
- typing
Source
Frequently Asked Questions
What does test_datetime_parse.py do?
test_datetime_parse.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, SyncAPI subdomain.
What functions are defined in test_datetime_parse.py?
test_datetime_parse.py defines 3 function(s): create_tz, test_date_parsing, test_datetime_parsing.
What does test_datetime_parse.py depend on?
test_datetime_parse.py imports 4 module(s): anthropic._utils, datetime, pytest, typing.
Where is test_datetime_parse.py in the architecture?
test_datetime_parse.py is located at tests/test_utils/test_datetime_parse.py (domain: AnthropicClient, subdomain: SyncAPI, directory: tests/test_utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free