Skip to content

Commit

Permalink
chore(internal): test updates (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Aug 9, 2024
1 parent 49f8e91 commit 366857b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ def test_validate_headers(self) -> None:
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
assert request.headers.get("X-Api-Key") == api_key

client2 = Anthropic(base_url=base_url, api_key=None, _strict_response_validation=True)
with update_env(**{"ANTHROPIC_API_KEY": Omit()}):
client2 = Anthropic(base_url=base_url, api_key=None, _strict_response_validation=True)

with pytest.raises(
TypeError,
Expand Down Expand Up @@ -1214,7 +1215,8 @@ def test_validate_headers(self) -> None:
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
assert request.headers.get("X-Api-Key") == api_key

client2 = AsyncAnthropic(base_url=base_url, api_key=None, _strict_response_validation=True)
with update_env(**{"ANTHROPIC_API_KEY": Omit()}):
client2 = AsyncAnthropic(base_url=base_url, api_key=None, _strict_response_validation=True)

with pytest.raises(
TypeError,
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 anthropic._types import NoneType
from anthropic._types import Omit, NoneType
from anthropic._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

0 comments on commit 366857b

Please sign in to comment.