openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/test_utils/test_proxy.py
23lines · modeblame
2e7e897aStainless Bot2 years ago | 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) == [] | |
e967f5a5Stainless Bot2 years ago | 22 | assert type(proxy).__name__ == "RecursiveLazyProxy" |
2e7e897aStainless Bot2 years ago | 23 | assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy" |