Skip to content

Commit 71a13d0

Browse files
chore(internal): add tests for proxy change (#899)
1 parent db029a5 commit 71a13d0

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tests/lib/test_old_api.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
import openai
4+
from openai.lib._old_api import APIRemovedInV1
5+
6+
7+
def test_basic_attribute_access_works() -> None:
8+
for attr in dir(openai):
9+
dir(getattr(openai, attr))
10+
11+
12+
def test_helpful_error_is_raised() -> None:
13+
with pytest.raises(APIRemovedInV1):
14+
openai.Completion.create() # type: ignore
15+
16+
with pytest.raises(APIRemovedInV1):
17+
openai.ChatCompletion.create() # type: ignore

tests/test_utils/test_proxy.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import operator
2+
from typing import Any
3+
from typing_extensions import override
4+
5+
from openai._utils import LazyProxy
6+
7+
8+
class RecursiveLazyProxy(LazyProxy[Any]):
9+
@override
10+
def __load__(self) -> Any:
11+
return self
12+
13+
def __call__(self, *_args: Any, **_kwds: Any) -> Any:
14+
raise RuntimeError("This should never be called!")
15+
16+
17+
def test_recursive_proxy() -> None:
18+
proxy = RecursiveLazyProxy()
19+
assert repr(proxy) == "RecursiveLazyProxy"
20+
assert str(proxy) == "RecursiveLazyProxy"
21+
assert dir(proxy) == []
22+
assert getattr(type(proxy), "__name__") == "RecursiveLazyProxy"
23+
assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy"

0 commit comments

Comments
 (0)