openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.24.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/test_files.py

51lines · modeblame

08b8179aDavid Schnurr2 years ago1from pathlib import Path
2
3import anyio
4import pytest
5from dirty_equals import IsDict, IsList, IsBytes, IsTuple
6
7from openai._files import to_httpx_files, async_to_httpx_files
8
9readme_path = Path(__file__).parent.parent.joinpath("README.md")
10
11
12def test_pathlib_includes_file_name() -> None:
13result = to_httpx_files({"file": readme_path})
14print(result)
15assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
16
17
18def test_tuple_input() -> None:
19result = to_httpx_files([("file", readme_path)])
20print(result)
21assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes())))
22
23
24@pytest.mark.asyncio
25async def test_async_pathlib_includes_file_name() -> None:
26result = await async_to_httpx_files({"file": readme_path})
27print(result)
28assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
29
30
31@pytest.mark.asyncio
32async def test_async_supports_anyio_path() -> None:
33result = await async_to_httpx_files({"file": anyio.Path(readme_path)})
34print(result)
35assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
36
37
38@pytest.mark.asyncio
39async def test_async_tuple_input() -> None:
40result = await async_to_httpx_files([("file", readme_path)])
41print(result)
42assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes())))
43
44
45def test_string_not_allowed() -> None:
46with pytest.raises(TypeError, match="Expected file types input to be a FileContent type or to be a tuple"):
47to_httpx_files(
48{
49"file": "foo", # type: ignore
50}
51)