mirror of
https://github.com/thinking-machines-lab/tinker.git
synced 2026-04-19 12:58:01 +00:00
Publish Python SDK
Hello world! Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
This commit is contained in:
commit
829c151ba7
192 changed files with 25717 additions and 0 deletions
34
tests/test_utils/test_proxy.py
Normal file
34
tests/test_utils/test_proxy.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import operator
|
||||
from typing import Any
|
||||
from typing_extensions import override
|
||||
|
||||
from tinker._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 type(proxy).__name__ == "RecursiveLazyProxy"
|
||||
assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy"
|
||||
|
||||
|
||||
def test_isinstance_does_not_error() -> None:
|
||||
class AlwaysErrorProxy(LazyProxy[Any]):
|
||||
@override
|
||||
def __load__(self) -> Any:
|
||||
raise RuntimeError("Mocking missing dependency")
|
||||
|
||||
proxy = AlwaysErrorProxy()
|
||||
assert not isinstance(proxy, dict)
|
||||
assert isinstance(proxy, LazyProxy)
|
||||
Loading…
Add table
Add a link
Reference in a new issue