Skip to content
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
17 changes: 17 additions & 0 deletions tests/lib/test_old_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

import openai
from openai.lib._old_api import APIRemovedInV1


def test_basic_attribute_access_works() -> None:
for attr in dir(openai):
dir(getattr(openai, attr))


def test_helpful_error_is_raised() -> None:
with pytest.raises(APIRemovedInV1):
openai.Completion.create() # type: ignore

with pytest.raises(APIRemovedInV1):
openai.ChatCompletion.create() # type: ignore
23 changes: 23 additions & 0 deletions tests/test_utils/test_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import operator
from typing import Any
from typing_extensions import override

from openai._utils import LazyProxy


class RecursiveLazyProxy(LazyProxy[Any]):
@override
def __load__(self) -> Any:
return self

def __call__(self, *_args: Any, **_kwds: Any) -> Any:
raise RuntimeError("This should never be called!")


def test_recursive_proxy() -> None:
proxy = RecursiveLazyProxy()
assert repr(proxy) == "RecursiveLazyProxy"
assert str(proxy) == "RecursiveLazyProxy"
assert dir(proxy) == []
assert getattr(type(proxy), "__name__") == "RecursiveLazyProxy"
assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy"