1717import pytest
1818from pydantic import TypeAdapter
1919
20- from openapi_python_client .schema .openapi_schema_pydantic import Callback , Example , Header , Link , Parameter , PathItem , Reference , RequestBody , Response , Schema , SecurityScheme
21-
20+ from openapi_python_client .schema .openapi_schema_pydantic import (
21+ Callback ,
22+ Example ,
23+ Header ,
24+ Link ,
25+ Parameter ,
26+ PathItem ,
27+ Reference ,
28+ RequestBody ,
29+ Response ,
30+ Schema ,
31+ SecurityScheme ,
32+ )
2233
2334try :
2435 from openapi_python_client .schema .openapi_schema_pydantic .reference import ReferenceOr
@@ -34,10 +45,11 @@ def get_example(base_type):
3445 return schema ["examples" ][0 ]
3546 if "$defs" in schema :
3647 return schema ["$defs" ][base_type .__name__ ]["examples" ][0 ]
37- assert False , f"No example found for { base_type .__name__ } "
48+ raise TypeError (f"No example found for { base_type .__name__ } " )
49+
3850
3951def deannotate_type (t ):
40- while get_origin (t ) == Annotated :
52+ while get_origin (t ) is Annotated :
4153 t = get_args (t )[0 ]
4254 return t
4355
@@ -60,17 +72,18 @@ def deannotate_type(t):
6072def test_type (ref_or_type , get_example_fn ):
6173 base_type = None
6274 print (deannotate_type (ref_or_type ))
63- for base_type in get_args (deannotate_type (ref_or_type )):
64- base_type = deannotate_type (base_type )
65- if base_type != Reference :
75+ for maybe_annotated_type in get_args (deannotate_type (ref_or_type )):
76+ each_type = deannotate_type (maybe_annotated_type )
77+ if each_type is not Reference :
78+ base_type = each_type
6679 break
6780 assert base_type is not None
6881
6982 example = get_example_fn (base_type )
7083
7184 parsed = TypeAdapter (ref_or_type ).validate_python (example )
72- assert type (parsed ) == get_origin (base_type ) or base_type
85+ assert type (parsed ) is get_origin (base_type ) or base_type
7386
7487 example ["$ref" ] = "ref"
7588 parsed = TypeAdapter (ref_or_type ).validate_python (example )
76- assert type (parsed ) == Reference
89+ assert type (parsed ) is Reference
0 commit comments