Skip to content

Commit c564f40

Browse files
committed
feat: change datetime parser to use python-dateutil
The datetime parser in DACITE_CONFIG has been updated to use python-dateutil's parse function instead of datetime.fromisoformat. This change provides more robust datetime parsing capabilities and better handles various datetime string formats. Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
1 parent 46c7ffe commit c564f40

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

barte/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
from datetime import datetime
33
from typing import Optional, List, Dict, Any
44
from dacite import Config
5+
from dateutil.parser import parse as parse_date
56

67
# Default config for dacite with datetime conversion
78
DACITE_CONFIG = Config(
89
type_hooks={
9-
datetime: lambda x: datetime.fromisoformat(x.replace("Z", "+00:00")) if isinstance(x, str) else x
10+
datetime: lambda x: parse_date(x) if isinstance(x, str) else x
1011
}
1112
)
1213

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pytest>=7.0.0
22
pytest-cov>=4.0.0
3-
requests-mock>=1.10.0
3+
requests-mock>=1.10.0
4+
python-dateutil>=2.8.0

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
packages=find_packages(),
1010
install_requires=[
1111
"requests>=2.25.0",
12-
"dacite>=1.8.0"
12+
"dacite>=1.8.0",
13+
"python-dateutil>=2.8.0"
1314
],
1415
python_requires=">=3.11",
1516
classifiers=[

tests/test_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ def test_pix_charge_get_qrcode(self, mock_get, mock_charge_response):
316316

317317
def test_client_singleton(self):
318318
"""Test client singleton pattern"""
319+
# Reset singleton for initial state
320+
BarteClient._instance = None
321+
322+
# Test uninitialized state
323+
with pytest.raises(RuntimeError) as exc_info:
324+
BarteClient.get_instance()
325+
assert "BarteClient not initialized" in str(exc_info.value)
326+
319327
# First initialization
320328
client1 = BarteClient(api_key="test_key", environment="sandbox")
321329
assert BarteClient.get_instance() == client1

0 commit comments

Comments
 (0)