11from datetime import date , datetime , time , timedelta
22from decimal import Decimal
3+ from os import getcwd
4+ from pathlib import Path
35from urllib .parse import ParseResult
46
57import pytest
@@ -83,6 +85,21 @@ def test_decimal():
8385 assert float (parser .parse (3.14 )) == 3.14
8486
8587
88+ def test_path ():
89+ expected = getcwd ()
90+
91+ parser = TypeParser (data = {}, value = {"$type" : "path" })
92+ actual = parser .parse ("." )
93+
94+ assert isinstance (actual , Path )
95+ assert expected == str (actual )
96+
97+ with pytest .raises (ValueError ) as e :
98+ parser .parse (1 )
99+
100+ assert "ValueError: Failed to convert 1 to path: expected str, bytes or os.PathLike object, not int" in e .exconly ()
101+
102+
86103def test_datetime ():
87104 parser = TypeParser (data = {}, value = {"$type" : "datetime" })
88105
@@ -106,23 +123,23 @@ def test_datetime_invalid():
106123def test_date ():
107124 parser = TypeParser (data = {}, value = {"$type" : "date" })
108125
109- # Test string to date
110- date_obj = parser . parse ( "2023-01-01" )
111- assert isinstance (date_obj , date )
112- assert date_obj .year == 2023
113- assert date_obj .month == 1
114- assert date_obj .day == 1
126+ actual = parser . parse ( "2023-01-01" )
127+
128+ assert isinstance (actual , date )
129+ assert actual .year == 2023
130+ assert actual .month == 1
131+ assert actual .day == 1
115132
116133
117134def test_time ():
118135 parser = TypeParser (data = {}, value = {"$type" : "time" })
119136
120- # Test string to time
121- time_obj = parser . parse ( "12:30:45" )
122- assert isinstance (time_obj , time )
123- assert time_obj .hour == 12
124- assert time_obj .minute == 30
125- assert time_obj .second == 45
137+ actual = parser . parse ( "12:30:45" )
138+
139+ assert isinstance (actual , time )
140+ assert actual .hour == 12
141+ assert actual .minute == 30
142+ assert actual .second == 45
126143
127144
128145def test_timedelta ():
@@ -164,13 +181,13 @@ def test_timedelta():
164181def test_url ():
165182 parser = TypeParser (data = {}, value = {"$type" : "url" })
166183
167- # Test URL parsing
168- result = parser . parse ( "https://example.com/path?query=1" )
169- assert isinstance (result , ParseResult )
170- assert result .scheme == "https"
171- assert result .netloc == "example.com"
172- assert result .path == "/path"
173- assert result .query == "query=1"
184+ actual = parser . parse ( "https://example.com/path?query=1" )
185+
186+ assert isinstance (actual , ParseResult )
187+ assert actual .scheme == "https"
188+ assert actual .netloc == "example.com"
189+ assert actual .path == "/path"
190+ assert actual .query == "query=1"
174191
175192
176193def test_invalid_type ():
0 commit comments