mirror of
https://github.com/thinking-machines-lab/tinker.git
synced 2026-04-28 17:29:33 +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
51
tests/test_files.py
Normal file
51
tests/test_files.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
from pathlib import Path
|
||||
|
||||
import anyio
|
||||
import pytest
|
||||
from dirty_equals import IsDict, IsList, IsBytes, IsTuple
|
||||
|
||||
from tinker._files import to_httpx_files, async_to_httpx_files
|
||||
|
||||
readme_path = Path(__file__).parent.parent.joinpath("README.md")
|
||||
|
||||
|
||||
def test_pathlib_includes_file_name() -> None:
|
||||
result = to_httpx_files({"file": readme_path})
|
||||
print(result)
|
||||
assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
|
||||
|
||||
|
||||
def test_tuple_input() -> None:
|
||||
result = to_httpx_files([("file", readme_path)])
|
||||
print(result)
|
||||
assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes())))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_pathlib_includes_file_name() -> None:
|
||||
result = await async_to_httpx_files({"file": readme_path})
|
||||
print(result)
|
||||
assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_supports_anyio_path() -> None:
|
||||
result = await async_to_httpx_files({"file": anyio.Path(readme_path)})
|
||||
print(result)
|
||||
assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_tuple_input() -> None:
|
||||
result = await async_to_httpx_files([("file", readme_path)])
|
||||
print(result)
|
||||
assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes())))
|
||||
|
||||
|
||||
def test_string_not_allowed() -> None:
|
||||
with pytest.raises(TypeError, match="Expected file types input to be a FileContent type or to be a tuple"):
|
||||
to_httpx_files(
|
||||
{
|
||||
"file": "foo", # type: ignore
|
||||
}
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue