openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.97.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/test_utils/test_proxy.py

35lines · modeblame

2e7e897aStainless Bot2 years ago1import operator
2from typing import Any
3from typing_extensions import override
4
5from openai._utils import LazyProxy
08d67adfBruno Alla1 years ago6from openai._extras._common import MissingDependencyError
2e7e897aStainless Bot2 years ago7
8
9class RecursiveLazyProxy(LazyProxy[Any]):
10@override
11def __load__(self) -> Any:
12return self
13
14def __call__(self, *_args: Any, **_kwds: Any) -> Any:
15raise RuntimeError("This should never be called!")
16
17
18def test_recursive_proxy() -> None:
19proxy = RecursiveLazyProxy()
20assert repr(proxy) == "RecursiveLazyProxy"
21assert str(proxy) == "RecursiveLazyProxy"
22assert dir(proxy) == []
e967f5a5Stainless Bot2 years ago23assert type(proxy).__name__ == "RecursiveLazyProxy"
2e7e897aStainless Bot2 years ago24assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy"
08d67adfBruno Alla1 years ago25
26
e2417755stainless-app[bot]1 years ago27def test_isinstance_does_not_error() -> None:
08d67adfBruno Alla1 years ago28class MissingDepsProxy(LazyProxy[Any]):
29@override
30def __load__(self) -> Any:
31raise MissingDependencyError("Mocking missing dependency")
32
33proxy = MissingDepsProxy()
34assert not isinstance(proxy, dict)
35assert isinstance(proxy, LazyProxy)