Skip to content

Commit 3efca3d

Browse files
committed
Fix tests
1 parent 0138621 commit 3efca3d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tests/test_models.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from openai._utils import PropertyInfo
1111
from openai._compat import PYDANTIC_V1, parse_obj, model_dump, model_json
12-
from openai._models import BaseModel, construct_type
12+
from openai._models import BaseModel, construct_type, _DISCRIMINATOR_CACHE
1313

1414

1515
class BasicModel(BaseModel):
@@ -809,7 +809,7 @@ class B(BaseModel):
809809

810810
UnionType = cast(Any, Union[A, B])
811811

812-
assert not hasattr(UnionType, "__discriminator__")
812+
assert _DISCRIMINATOR_CACHE.get(UnionType) is None
813813

814814
m = construct_type(
815815
value={"type": "b", "data": "foo"}, type_=cast(Any, Annotated[UnionType, PropertyInfo(discriminator="type")])
@@ -818,7 +818,8 @@ class B(BaseModel):
818818
assert m.type == "b"
819819
assert m.data == "foo" # type: ignore[comparison-overlap]
820820

821-
discriminator = UnionType.__discriminator__
821+
discriminator = _DISCRIMINATOR_CACHE.get(UnionType)
822+
822823
assert discriminator is not None
823824

824825
m = construct_type(
@@ -830,7 +831,7 @@ class B(BaseModel):
830831

831832
# if the discriminator details object stays the same between invocations then
832833
# we hit the cache
833-
assert UnionType.__discriminator__ is discriminator
834+
assert _DISCRIMINATOR_CACHE.get(UnionType) is discriminator
834835

835836

836837
@pytest.mark.skipif(PYDANTIC_V1, reason="TypeAliasType is not supported in Pydantic v1")

0 commit comments

Comments
 (0)