1- """NOTE TO DEVELOPERS:
2-
3- These tests were generated with the assistance of AI and may require
4- additional review or adjustments. Please verify that all test cases
5- properly cover the expected behavior of the custom types, especially
6- regarding edge cases and integration with `Pydantic`.
7- """
8-
91import pytest
10- from pydantic import AnyHttpUrl , BaseModel , ValidationError , TypeAdapter
2+ from pydantic import AnyHttpUrl , BaseModel , TypeAdapter , ValidationError
113
124from faceit .models .custom_types import (
135 FaceitID ,
@@ -26,7 +18,7 @@ def lang_adapter() -> TypeAdapter[LangFormattedAnyHttpUrl]:
2618
2719
2820@pytest .mark .parametrize (
29- "input_value, expected" ,
21+ ( "input_value" , " expected") ,
3022 [
3123 (f"https://example.com/{ langph } /docs" , "https://example.com/docs" ),
3224 (f"http://{ langph } /foo/bar" , "http://foo/bar" ),
@@ -39,7 +31,9 @@ def lang_adapter() -> TypeAdapter[LangFormattedAnyHttpUrl]:
3931 ("" , "" ),
4032 ],
4133)
42- def test_validate_success (input_value , expected , lang_adapter ):
34+ def test_validate_success (
35+ input_value : str , expected : str , lang_adapter : TypeAdapter [LangFormattedAnyHttpUrl ]
36+ ) -> None :
4337 if expected == "" or expected .startswith ("http" ):
4438 assert (
4539 input_value == expected
@@ -52,33 +46,24 @@ def test_validate_success(input_value, expected, lang_adapter):
5246
5347
5448class TestFaceitID :
55- def test_valid_uuid (self , valid_uuid ):
56- # Test with a valid UUID string
57- valid_uuid = valid_uuid
49+ def test_valid_uuid (self , valid_uuid : str ) -> None :
5850 faceit_id = FaceitID ._validate (valid_uuid )
5951 assert isinstance (faceit_id , FaceitID )
6052 assert str (faceit_id ) == valid_uuid
6153
62- def test_invalid_uuid (self ):
63- # Test with an invalid UUID string
54+ def test_invalid_uuid (self ) -> None :
6455 with pytest .raises (ValueError , match = "Invalid FaceitID:" ):
6556 FaceitID ._validate ("not-a-uuid" )
6657
67- # Test with a non-string, non-UUID value
6858 with pytest .raises (AttributeError ):
6959 FaceitID (123 )
7060
71- def test_suffix_handling (self , valid_uuid ):
72- # Test that the 'gui' suffix is NOT automatically handled
73- # We need to manually remove it before validation
74- valid_uuid = valid_uuid
61+ def test_suffix_handling (self , valid_uuid : str ) -> None :
7562 suffixed_uuid = f"{ valid_uuid } gui"
7663
77- # This should fail because the suffix makes it an invalid UUID
7864 with pytest .raises (ValueError , match = "is not a valid UUID format" ):
7965 FaceitID ._validate (suffixed_uuid )
8066
81- # Manual handling of suffix
8267 if suffixed_uuid .endswith ("gui" ):
8368 cleaned_uuid = suffixed_uuid [:- 3 ]
8469 faceit_id_from_cleaned = FaceitID ._validate (cleaned_uuid )
@@ -87,41 +72,29 @@ def test_suffix_handling(self, valid_uuid):
8772
8873
8974class TestFaceitTeamID :
90- def test_valid_team_id (self , valid_uuid ):
91- # Test with a valid team ID (prefix + UUID)
92- valid_uuid = valid_uuid
75+ def test_valid_team_id (self , valid_uuid : str ) -> None :
9376 valid_team_id = f"team-{ valid_uuid } "
9477
9578 team_id = FaceitTeamID ._validate (valid_team_id )
9679 assert isinstance (team_id , FaceitTeamID )
9780 assert str (team_id ) == valid_team_id
9881
99- def test_missing_prefix (self , valid_uuid ):
100- # Test with a UUID without the required prefix
101- valid_uuid = valid_uuid
102-
82+ def test_missing_prefix (self , valid_uuid : str ) -> None :
10383 with pytest .raises (ValueError , match = "must start with 'team-'" ):
10484 FaceitTeamID ._validate (valid_uuid )
10585
106- def test_invalid_uuid_part (self ):
107- # Test with an invalid UUID part
86+ def test_invalid_uuid_part (self ) -> None :
10887 with pytest .raises (ValueError , match = "contains invalid UUID part" ):
10988 FaceitTeamID ._validate ("team-not-a-valid-uuid" )
11089
111- def test_suffix_handling (self , valid_uuid ):
112- # Test that the 'gui' suffix is NOT automatically handled
113- valid_uuid = valid_uuid
90+ def test_suffix_handling (self , valid_uuid : str ) -> None :
11491 valid_team_id = f"team-{ valid_uuid } "
11592 suffixed_team_id = f"{ valid_team_id } gui"
93+ _ = FaceitTeamID ._validate (valid_team_id )
11694
117- # This should work
118- team_id = FaceitTeamID ._validate (valid_team_id )
119-
120- # This should fail because the suffix makes the UUID part invalid
12195 with pytest .raises (ValueError , match = "contains invalid UUID part" ):
12296 FaceitTeamID ._validate (suffixed_team_id )
12397
124- # Manual handling of suffix
12598 if suffixed_team_id .endswith ("gui" ):
12699 cleaned_team_id = suffixed_team_id [:- 3 ]
127100 team_id_from_cleaned = FaceitTeamID ._validate (cleaned_team_id )
@@ -130,119 +103,89 @@ def test_suffix_handling(self, valid_uuid):
130103
131104
132105class TestFaceitMatchID :
133- def test_valid_match_id (self , valid_uuid ):
134- # Test with a valid match ID (prefix + UUID)
135- valid_uuid = valid_uuid
106+ def test_valid_match_id (self , valid_uuid : str ) -> None :
136107 valid_match_id = f"1-{ valid_uuid } "
137108
138109 match_id = FaceitMatchID ._validate (valid_match_id )
139110 assert isinstance (match_id , FaceitMatchID )
140111 assert str (match_id ) == valid_match_id
141112
142- def test_missing_prefix (self , valid_uuid ):
143- # Test with a UUID without the required prefix
144- valid_uuid = valid_uuid
145-
113+ def test_missing_prefix (self , valid_uuid : str ) -> None :
146114 with pytest .raises (ValueError , match = "must start with '1-'" ):
147115 FaceitMatchID ._validate (valid_uuid )
148116
149- def test_invalid_uuid_part (self ):
150- # Test with an invalid UUID part
117+ def test_invalid_uuid_part (self ) -> None :
151118 with pytest .raises (ValueError , match = "contains invalid UUID part" ):
152119 FaceitMatchID ._validate ("1-not-a-valid-uuid" )
153120
154- def test_suffix_handling (self , valid_uuid ):
155- # Test that the 'gui' suffix is NOT automatically handled
156- valid_uuid = valid_uuid
121+ def test_suffix_handling (self , valid_uuid : str ) -> None :
157122 valid_match_id = f"1-{ valid_uuid } "
158123 suffixed_match_id = f"{ valid_match_id } gui"
124+ _ = FaceitMatchID ._validate (valid_match_id )
159125
160- # This should work
161- match_id = FaceitMatchID ._validate (valid_match_id )
162-
163- # This should fail because the suffix makes the UUID part invalid
164126 with pytest .raises (ValueError , match = "contains invalid UUID part" ):
165127 FaceitMatchID ._validate (suffixed_match_id )
166128
167- # Manual handling of suffix
168129 if suffixed_match_id .endswith ("gui" ):
169130 cleaned_match_id = suffixed_match_id [:- 3 ]
170131 match_id_from_cleaned = FaceitMatchID ._validate (cleaned_match_id )
171132 assert isinstance (match_id_from_cleaned , FaceitMatchID )
172133 assert str (match_id_from_cleaned ) == valid_match_id
173134
174135
175- # Test Pydantic integration
176136class TestPydanticIntegration :
177- def test_faceit_id_in_model (self , valid_uuid ) :
137+ def test_faceit_id_in_model (self , valid_uuid : str ) -> None :
178138 class UserModel (BaseModel ):
179139 id : FaceitID
180140
181- # Valid UUID
182- valid_uuid = valid_uuid
183141 user = UserModel (id = valid_uuid )
184142 assert isinstance (user .id , FaceitID )
185143 assert str (user .id ) == valid_uuid
186144
187- # UUID with suffix - Pydantic automatically handles this
188145 suffixed_uuid = f"{ valid_uuid } gui"
189146 user = UserModel (id = suffixed_uuid )
190147 assert isinstance (user .id , FaceitID )
191- # The suffix should be automatically removed
192148 assert str (user .id ) == valid_uuid
193149
194- # Invalid UUID
195150 with pytest .raises (ValidationError ):
196151 UserModel (id = "not-a-uuid" )
197152
198- def test_faceit_team_id_in_model (self , valid_uuid ) :
153+ def test_faceit_team_id_in_model (self , valid_uuid : str ) -> None :
199154 class TeamModel (BaseModel ):
200155 id : FaceitTeamID
201156
202- # Valid team ID
203- valid_uuid = valid_uuid
204157 valid_team_id = f"team-{ valid_uuid } "
205158 team = TeamModel (id = valid_team_id )
206159 assert isinstance (team .id , FaceitTeamID )
207160 assert str (team .id ) == valid_team_id
208161
209- # Team ID with suffix - Pydantic automatically handles this
210162 suffixed_team_id = f"{ valid_team_id } gui"
211163 team = TeamModel (id = suffixed_team_id )
212164 assert isinstance (team .id , FaceitTeamID )
213- # The suffix should be automatically removed
214165 assert str (team .id ) == valid_team_id
215166
216- # Missing prefix
217167 with pytest .raises (ValidationError ):
218168 TeamModel (id = valid_uuid )
219169
220- # Invalid UUID part
221170 with pytest .raises (ValidationError ):
222171 TeamModel (id = "team-not-a-valid-uuid" )
223172
224- def test_faceit_match_id_in_model (self , valid_uuid ) :
173+ def test_faceit_match_id_in_model (self , valid_uuid : str ) -> None :
225174 class MatchModel (BaseModel ):
226175 id : FaceitMatchID
227176
228- # Valid match ID
229- valid_uuid = valid_uuid
230177 valid_match_id = f"1-{ valid_uuid } "
231178 match = MatchModel (id = valid_match_id )
232179 assert isinstance (match .id , FaceitMatchID )
233180 assert str (match .id ) == valid_match_id
234181
235- # Match ID with suffix - Pydantic automatically handles this
236182 suffixed_match_id = f"{ valid_match_id } gui"
237183 match = MatchModel (id = suffixed_match_id )
238184 assert isinstance (match .id , FaceitMatchID )
239- # The suffix should be automatically removed
240185 assert str (match .id ) == valid_match_id
241186
242- # Missing prefix
243187 with pytest .raises (ValidationError ):
244188 MatchModel (id = valid_uuid )
245189
246- # Invalid UUID part
247190 with pytest .raises (ValidationError ):
248191 MatchModel (id = "1-not-a-valid-uuid" )
0 commit comments