Skip to content

chore(internal): test updates #1602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/openai/_utils/_reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def assert_signatures_in_sync(

if custom_param.annotation != source_param.annotation:
errors.append(
f"types for the `{name}` param are do not match; source={repr(source_param.annotation)} checking={repr(source_param.annotation)}"
f"types for the `{name}` param are do not match; source={repr(source_param.annotation)} checking={repr(custom_param.annotation)}"
)
continue

Expand Down
7 changes: 5 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pydantic import ValidationError

from openai import OpenAI, AsyncOpenAI, APIResponseValidationError
from openai._types import Omit
from openai._models import BaseModel, FinalRequestOptions
from openai._constants import RAW_RESPONSE_HEADER
from openai._streaming import Stream, AsyncStream
Expand Down Expand Up @@ -328,7 +329,8 @@ def test_validate_headers(self) -> None:
assert request.headers.get("Authorization") == f"Bearer {api_key}"

with pytest.raises(OpenAIError):
client2 = OpenAI(base_url=base_url, api_key=None, _strict_response_validation=True)
with update_env(**{"OPENAI_API_KEY": Omit()}):
client2 = OpenAI(base_url=base_url, api_key=None, _strict_response_validation=True)
_ = client2

def test_default_query_option(self) -> None:
Expand Down Expand Up @@ -1103,7 +1105,8 @@ def test_validate_headers(self) -> None:
assert request.headers.get("Authorization") == f"Bearer {api_key}"

with pytest.raises(OpenAIError):
client2 = AsyncOpenAI(base_url=base_url, api_key=None, _strict_response_validation=True)
with update_env(**{"OPENAI_API_KEY": Omit()}):
client2 = AsyncOpenAI(base_url=base_url, api_key=None, _strict_response_validation=True)
_ = client2

def test_default_query_option(self) -> None:
Expand Down
10 changes: 7 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datetime import date, datetime
from typing_extensions import Literal, get_args, get_origin, assert_type

from openai._types import NoneType
from openai._types import Omit, NoneType
from openai._utils import (
is_dict,
is_list,
Expand Down Expand Up @@ -139,11 +139,15 @@ def _assert_list_type(type_: type[object], value: object) -> None:


@contextlib.contextmanager
def update_env(**new_env: str) -> Iterator[None]:
def update_env(**new_env: str | Omit) -> Iterator[None]:
old = os.environ.copy()

try:
os.environ.update(new_env)
for name, value in new_env.items():
if isinstance(value, Omit):
os.environ.pop(name, None)
else:
os.environ[name] = value

yield None
finally:
Expand Down