openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
custom-code-from-generated-20260521

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
3fc6b983Alex Chang1 months 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"
e92f8182stainless-app[bot]1 years ago25
26
27def test_isinstance_does_not_error() -> None:
3fc6b983Alex Chang1 months ago28class MissingDepsProxy(LazyProxy[Any]):
e92f8182stainless-app[bot]1 years ago29@override
30def __load__(self) -> Any:
3fc6b983Alex Chang1 months ago31raise MissingDependencyError("Mocking missing dependency")
e92f8182stainless-app[bot]1 years ago32
3fc6b983Alex Chang1 months ago33proxy = MissingDepsProxy()
e92f8182stainless-app[bot]1 years ago34assert not isinstance(proxy, dict)
35assert isinstance(proxy, LazyProxy)