anyformat 0.1.2__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- anyformat-0.2.0/.release-please-manifest.json +3 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/CHANGELOG.md +18 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/PKG-INFO +1 -1
- {anyformat-0.1.2 → anyformat-0.2.0}/pyproject.toml +1 -1
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_files.py +53 -3
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/__init__.py +0 -1
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_utils.py +0 -15
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_version.py +1 -1
- anyformat-0.2.0/tests/test_files.py +148 -0
- anyformat-0.1.2/.release-please-manifest.json +0 -3
- anyformat-0.1.2/tests/test_deepcopy.py +0 -58
- anyformat-0.1.2/tests/test_files.py +0 -51
- {anyformat-0.1.2 → anyformat-0.2.0}/.gitignore +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/CONTRIBUTING.md +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/LICENSE +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/README.md +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/SECURITY.md +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/api.md +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/bin/check-release-environment +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/bin/publish-pypi +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/examples/.keep +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/release-please-config.json +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/requirements-dev.lock +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/__init__.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_base_client.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_client.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_compat.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_constants.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_exceptions.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_models.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_qs.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_resource.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_response.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_streaming.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_types.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_compat.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_datetime_parse.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_json.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_logs.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_path.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_proxy.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_reflection.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_resources_proxy.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_streams.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_sync.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_transform.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/_utils/_typing.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/lib/.keep +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/py.typed +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/resources/__init__.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/resources/files.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/resources/health.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/resources/webhooks.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/resources/workflows.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/__init__.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/file_create_params.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/file_create_response.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/file_list_params.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/file_list_response.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/webhook_create_params.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/webhook_create_response.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/webhook_list_response.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/workflow.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/workflow_list_params.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/workflow_list_response.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/workflow_list_runs_params.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/workflow_list_runs_response.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/workflow_results_params.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/workflow_run_params.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/workflow_run_response.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/workflow_upload_params.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/src/anyformat/types/workflow_upload_response.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/__init__.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/api_resources/__init__.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/api_resources/test_files.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/api_resources/test_health.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/api_resources/test_webhooks.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/api_resources/test_workflows.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/conftest.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/sample_file.txt +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_client.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_extract_files.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_models.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_qs.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_required_args.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_response.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_streaming.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_transform.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_utils/test_datetime_parse.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_utils/test_json.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_utils/test_path.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_utils/test_proxy.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/test_utils/test_typing.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/tests/utils.py +0 -0
- {anyformat-0.1.2 → anyformat-0.2.0}/uv.lock +0 -0
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0 (2026-04-18)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [v0.1.2...v0.2.0](https://github.com/anyformat-ai/anyformat-python/compare/v0.1.2...v0.2.0)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* **api:** rename anyformat-ai-mcp to anyformat-mcp ([1088738](https://github.com/anyformat-ai/anyformat-python/commit/10887383a482a459098ca2647bb549db77bc0461))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Performance Improvements
|
|
13
|
+
|
|
14
|
+
* **client:** optimize file structure copying in multipart requests ([352741e](https://github.com/anyformat-ai/anyformat-python/commit/352741eaf6df138f58aabe0db3d286c2845232cb))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Chores
|
|
18
|
+
|
|
19
|
+
* configure new SDK language ([9808ea5](https://github.com/anyformat-ai/anyformat-python/commit/9808ea5a96eae3c76548a57115ef40a592d56fc3))
|
|
20
|
+
|
|
3
21
|
## 0.1.2 (2026-04-13)
|
|
4
22
|
|
|
5
23
|
Full Changelog: [v0.1.1...v0.1.2](https://github.com/anyformat-ai/anyformat-python/compare/v0.1.1...v0.1.2)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: anyformat
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: The official Python library for the anyformat API
|
|
5
5
|
Project-URL: Homepage, https://github.com/anyformat-ai/anyformat-python
|
|
6
6
|
Project-URL: Repository, https://github.com/anyformat-ai/anyformat-python
|
|
@@ -3,8 +3,8 @@ from __future__ import annotations
|
|
|
3
3
|
import io
|
|
4
4
|
import os
|
|
5
5
|
import pathlib
|
|
6
|
-
from typing import overload
|
|
7
|
-
from typing_extensions import TypeGuard
|
|
6
|
+
from typing import Sequence, cast, overload
|
|
7
|
+
from typing_extensions import TypeVar, TypeGuard
|
|
8
8
|
|
|
9
9
|
import anyio
|
|
10
10
|
|
|
@@ -17,7 +17,9 @@ from ._types import (
|
|
|
17
17
|
HttpxFileContent,
|
|
18
18
|
HttpxRequestFiles,
|
|
19
19
|
)
|
|
20
|
-
from ._utils import is_tuple_t, is_mapping_t, is_sequence_t
|
|
20
|
+
from ._utils import is_list, is_mapping, is_tuple_t, is_mapping_t, is_sequence_t
|
|
21
|
+
|
|
22
|
+
_T = TypeVar("_T")
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]:
|
|
@@ -121,3 +123,51 @@ async def async_read_file_content(file: FileContent) -> HttpxFileContent:
|
|
|
121
123
|
return await anyio.Path(file).read_bytes()
|
|
122
124
|
|
|
123
125
|
return file
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]]) -> _T:
|
|
129
|
+
"""Copy only the containers along the given paths.
|
|
130
|
+
|
|
131
|
+
Used to guard against mutation by extract_files without copying the entire structure.
|
|
132
|
+
Only dicts and lists that lie on a path are copied; everything else
|
|
133
|
+
is returned by reference.
|
|
134
|
+
|
|
135
|
+
For example, given paths=[["foo", "files", "file"]] and the structure:
|
|
136
|
+
{
|
|
137
|
+
"foo": {
|
|
138
|
+
"bar": {"baz": {}},
|
|
139
|
+
"files": {"file": <content>}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
The root dict, "foo", and "files" are copied (they lie on the path).
|
|
143
|
+
"bar" and "baz" are returned by reference (off the path).
|
|
144
|
+
"""
|
|
145
|
+
return _deepcopy_with_paths(item, paths, 0)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]], index: int) -> _T:
|
|
149
|
+
if not paths:
|
|
150
|
+
return item
|
|
151
|
+
if is_mapping(item):
|
|
152
|
+
key_to_paths: dict[str, list[Sequence[str]]] = {}
|
|
153
|
+
for path in paths:
|
|
154
|
+
if index < len(path):
|
|
155
|
+
key_to_paths.setdefault(path[index], []).append(path)
|
|
156
|
+
|
|
157
|
+
# if no path continues through this mapping, it won't be mutated and copying it is redundant
|
|
158
|
+
if not key_to_paths:
|
|
159
|
+
return item
|
|
160
|
+
|
|
161
|
+
result = dict(item)
|
|
162
|
+
for key, subpaths in key_to_paths.items():
|
|
163
|
+
if key in result:
|
|
164
|
+
result[key] = _deepcopy_with_paths(result[key], subpaths, index + 1)
|
|
165
|
+
return cast(_T, result)
|
|
166
|
+
if is_list(item):
|
|
167
|
+
array_paths = [path for path in paths if index < len(path) and path[index] == "<array>"]
|
|
168
|
+
|
|
169
|
+
# if no path expects a list here, nothing will be mutated inside it - return by reference
|
|
170
|
+
if not array_paths:
|
|
171
|
+
return cast(_T, item)
|
|
172
|
+
return cast(_T, [_deepcopy_with_paths(entry, array_paths, index + 1) for entry in item])
|
|
173
|
+
return item
|
|
@@ -24,7 +24,6 @@ from ._utils import (
|
|
|
24
24
|
coerce_integer as coerce_integer,
|
|
25
25
|
file_from_path as file_from_path,
|
|
26
26
|
strip_not_given as strip_not_given,
|
|
27
|
-
deepcopy_minimal as deepcopy_minimal,
|
|
28
27
|
get_async_library as get_async_library,
|
|
29
28
|
maybe_coerce_float as maybe_coerce_float,
|
|
30
29
|
get_required_header as get_required_header,
|
|
@@ -177,21 +177,6 @@ def is_iterable(obj: object) -> TypeGuard[Iterable[object]]:
|
|
|
177
177
|
return isinstance(obj, Iterable)
|
|
178
178
|
|
|
179
179
|
|
|
180
|
-
def deepcopy_minimal(item: _T) -> _T:
|
|
181
|
-
"""Minimal reimplementation of copy.deepcopy() that will only copy certain object types:
|
|
182
|
-
|
|
183
|
-
- mappings, e.g. `dict`
|
|
184
|
-
- list
|
|
185
|
-
|
|
186
|
-
This is done for performance reasons.
|
|
187
|
-
"""
|
|
188
|
-
if is_mapping(item):
|
|
189
|
-
return cast(_T, {k: deepcopy_minimal(v) for k, v in item.items()})
|
|
190
|
-
if is_list(item):
|
|
191
|
-
return cast(_T, [deepcopy_minimal(entry) for entry in item])
|
|
192
|
-
return item
|
|
193
|
-
|
|
194
|
-
|
|
195
180
|
# copied from https://github.com/Rapptz/RoboDanny
|
|
196
181
|
def human_join(seq: Sequence[str], *, delim: str = ", ", final: str = "or") -> str:
|
|
197
182
|
size = len(seq)
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import anyio
|
|
4
|
+
import pytest
|
|
5
|
+
from dirty_equals import IsDict, IsList, IsBytes, IsTuple
|
|
6
|
+
|
|
7
|
+
from anyformat._files import to_httpx_files, deepcopy_with_paths, async_to_httpx_files
|
|
8
|
+
from anyformat._utils import extract_files
|
|
9
|
+
|
|
10
|
+
readme_path = Path(__file__).parent.parent.joinpath("README.md")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_pathlib_includes_file_name() -> None:
|
|
14
|
+
result = to_httpx_files({"file": readme_path})
|
|
15
|
+
print(result)
|
|
16
|
+
assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_tuple_input() -> None:
|
|
20
|
+
result = to_httpx_files([("file", readme_path)])
|
|
21
|
+
print(result)
|
|
22
|
+
assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes())))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.mark.asyncio
|
|
26
|
+
async def test_async_pathlib_includes_file_name() -> None:
|
|
27
|
+
result = await async_to_httpx_files({"file": readme_path})
|
|
28
|
+
print(result)
|
|
29
|
+
assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.mark.asyncio
|
|
33
|
+
async def test_async_supports_anyio_path() -> None:
|
|
34
|
+
result = await async_to_httpx_files({"file": anyio.Path(readme_path)})
|
|
35
|
+
print(result)
|
|
36
|
+
assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@pytest.mark.asyncio
|
|
40
|
+
async def test_async_tuple_input() -> None:
|
|
41
|
+
result = await async_to_httpx_files([("file", readme_path)])
|
|
42
|
+
print(result)
|
|
43
|
+
assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes())))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_string_not_allowed() -> None:
|
|
47
|
+
with pytest.raises(TypeError, match="Expected file types input to be a FileContent type or to be a tuple"):
|
|
48
|
+
to_httpx_files(
|
|
49
|
+
{
|
|
50
|
+
"file": "foo", # type: ignore
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def assert_different_identities(obj1: object, obj2: object) -> None:
|
|
56
|
+
assert obj1 == obj2
|
|
57
|
+
assert obj1 is not obj2
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class TestDeepcopyWithPaths:
|
|
61
|
+
def test_copies_top_level_dict(self) -> None:
|
|
62
|
+
original = {"file": b"data", "other": "value"}
|
|
63
|
+
result = deepcopy_with_paths(original, [["file"]])
|
|
64
|
+
assert_different_identities(result, original)
|
|
65
|
+
|
|
66
|
+
def test_file_value_is_same_reference(self) -> None:
|
|
67
|
+
file_bytes = b"contents"
|
|
68
|
+
original = {"file": file_bytes}
|
|
69
|
+
result = deepcopy_with_paths(original, [["file"]])
|
|
70
|
+
assert_different_identities(result, original)
|
|
71
|
+
assert result["file"] is file_bytes
|
|
72
|
+
|
|
73
|
+
def test_list_popped_wholesale(self) -> None:
|
|
74
|
+
files = [b"f1", b"f2"]
|
|
75
|
+
original = {"files": files, "title": "t"}
|
|
76
|
+
result = deepcopy_with_paths(original, [["files", "<array>"]])
|
|
77
|
+
assert_different_identities(result, original)
|
|
78
|
+
result_files = result["files"]
|
|
79
|
+
assert isinstance(result_files, list)
|
|
80
|
+
assert_different_identities(result_files, files)
|
|
81
|
+
|
|
82
|
+
def test_nested_array_path_copies_list_and_elements(self) -> None:
|
|
83
|
+
elem1 = {"file": b"f1", "extra": 1}
|
|
84
|
+
elem2 = {"file": b"f2", "extra": 2}
|
|
85
|
+
original = {"items": [elem1, elem2]}
|
|
86
|
+
result = deepcopy_with_paths(original, [["items", "<array>", "file"]])
|
|
87
|
+
assert_different_identities(result, original)
|
|
88
|
+
result_items = result["items"]
|
|
89
|
+
assert isinstance(result_items, list)
|
|
90
|
+
assert_different_identities(result_items, original["items"])
|
|
91
|
+
assert_different_identities(result_items[0], elem1)
|
|
92
|
+
assert_different_identities(result_items[1], elem2)
|
|
93
|
+
|
|
94
|
+
def test_empty_paths_returns_same_object(self) -> None:
|
|
95
|
+
original = {"foo": "bar"}
|
|
96
|
+
result = deepcopy_with_paths(original, [])
|
|
97
|
+
assert result is original
|
|
98
|
+
|
|
99
|
+
def test_multiple_paths(self) -> None:
|
|
100
|
+
f1 = b"file1"
|
|
101
|
+
f2 = b"file2"
|
|
102
|
+
original = {"a": f1, "b": f2, "c": "unchanged"}
|
|
103
|
+
result = deepcopy_with_paths(original, [["a"], ["b"]])
|
|
104
|
+
assert_different_identities(result, original)
|
|
105
|
+
assert result["a"] is f1
|
|
106
|
+
assert result["b"] is f2
|
|
107
|
+
assert result["c"] is original["c"]
|
|
108
|
+
|
|
109
|
+
def test_extract_files_does_not_mutate_original_top_level(self) -> None:
|
|
110
|
+
file_bytes = b"contents"
|
|
111
|
+
original = {"file": file_bytes, "other": "value"}
|
|
112
|
+
|
|
113
|
+
copied = deepcopy_with_paths(original, [["file"]])
|
|
114
|
+
extracted = extract_files(copied, paths=[["file"]])
|
|
115
|
+
|
|
116
|
+
assert extracted == [("file", file_bytes)]
|
|
117
|
+
assert original == {"file": file_bytes, "other": "value"}
|
|
118
|
+
assert copied == {"other": "value"}
|
|
119
|
+
|
|
120
|
+
def test_extract_files_does_not_mutate_original_nested_array_path(self) -> None:
|
|
121
|
+
file1 = b"f1"
|
|
122
|
+
file2 = b"f2"
|
|
123
|
+
original = {
|
|
124
|
+
"items": [
|
|
125
|
+
{"file": file1, "extra": 1},
|
|
126
|
+
{"file": file2, "extra": 2},
|
|
127
|
+
],
|
|
128
|
+
"title": "example",
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
copied = deepcopy_with_paths(original, [["items", "<array>", "file"]])
|
|
132
|
+
extracted = extract_files(copied, paths=[["items", "<array>", "file"]])
|
|
133
|
+
|
|
134
|
+
assert extracted == [("items[][file]", file1), ("items[][file]", file2)]
|
|
135
|
+
assert original == {
|
|
136
|
+
"items": [
|
|
137
|
+
{"file": file1, "extra": 1},
|
|
138
|
+
{"file": file2, "extra": 2},
|
|
139
|
+
],
|
|
140
|
+
"title": "example",
|
|
141
|
+
}
|
|
142
|
+
assert copied == {
|
|
143
|
+
"items": [
|
|
144
|
+
{"extra": 1},
|
|
145
|
+
{"extra": 2},
|
|
146
|
+
],
|
|
147
|
+
"title": "example",
|
|
148
|
+
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
from anyformat._utils import deepcopy_minimal
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def assert_different_identities(obj1: object, obj2: object) -> None:
|
|
5
|
-
assert obj1 == obj2
|
|
6
|
-
assert id(obj1) != id(obj2)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def test_simple_dict() -> None:
|
|
10
|
-
obj1 = {"foo": "bar"}
|
|
11
|
-
obj2 = deepcopy_minimal(obj1)
|
|
12
|
-
assert_different_identities(obj1, obj2)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def test_nested_dict() -> None:
|
|
16
|
-
obj1 = {"foo": {"bar": True}}
|
|
17
|
-
obj2 = deepcopy_minimal(obj1)
|
|
18
|
-
assert_different_identities(obj1, obj2)
|
|
19
|
-
assert_different_identities(obj1["foo"], obj2["foo"])
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def test_complex_nested_dict() -> None:
|
|
23
|
-
obj1 = {"foo": {"bar": [{"hello": "world"}]}}
|
|
24
|
-
obj2 = deepcopy_minimal(obj1)
|
|
25
|
-
assert_different_identities(obj1, obj2)
|
|
26
|
-
assert_different_identities(obj1["foo"], obj2["foo"])
|
|
27
|
-
assert_different_identities(obj1["foo"]["bar"], obj2["foo"]["bar"])
|
|
28
|
-
assert_different_identities(obj1["foo"]["bar"][0], obj2["foo"]["bar"][0])
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def test_simple_list() -> None:
|
|
32
|
-
obj1 = ["a", "b", "c"]
|
|
33
|
-
obj2 = deepcopy_minimal(obj1)
|
|
34
|
-
assert_different_identities(obj1, obj2)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def test_nested_list() -> None:
|
|
38
|
-
obj1 = ["a", [1, 2, 3]]
|
|
39
|
-
obj2 = deepcopy_minimal(obj1)
|
|
40
|
-
assert_different_identities(obj1, obj2)
|
|
41
|
-
assert_different_identities(obj1[1], obj2[1])
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
class MyObject: ...
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def test_ignores_other_types() -> None:
|
|
48
|
-
# custom classes
|
|
49
|
-
my_obj = MyObject()
|
|
50
|
-
obj1 = {"foo": my_obj}
|
|
51
|
-
obj2 = deepcopy_minimal(obj1)
|
|
52
|
-
assert_different_identities(obj1, obj2)
|
|
53
|
-
assert obj1["foo"] is my_obj
|
|
54
|
-
|
|
55
|
-
# tuples
|
|
56
|
-
obj3 = ("a", "b")
|
|
57
|
-
obj4 = deepcopy_minimal(obj3)
|
|
58
|
-
assert obj3 is obj4
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
|
|
3
|
-
import anyio
|
|
4
|
-
import pytest
|
|
5
|
-
from dirty_equals import IsDict, IsList, IsBytes, IsTuple
|
|
6
|
-
|
|
7
|
-
from anyformat._files import to_httpx_files, async_to_httpx_files
|
|
8
|
-
|
|
9
|
-
readme_path = Path(__file__).parent.parent.joinpath("README.md")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def test_pathlib_includes_file_name() -> None:
|
|
13
|
-
result = to_httpx_files({"file": readme_path})
|
|
14
|
-
print(result)
|
|
15
|
-
assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def test_tuple_input() -> None:
|
|
19
|
-
result = to_httpx_files([("file", readme_path)])
|
|
20
|
-
print(result)
|
|
21
|
-
assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes())))
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@pytest.mark.asyncio
|
|
25
|
-
async def test_async_pathlib_includes_file_name() -> None:
|
|
26
|
-
result = await async_to_httpx_files({"file": readme_path})
|
|
27
|
-
print(result)
|
|
28
|
-
assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@pytest.mark.asyncio
|
|
32
|
-
async def test_async_supports_anyio_path() -> None:
|
|
33
|
-
result = await async_to_httpx_files({"file": anyio.Path(readme_path)})
|
|
34
|
-
print(result)
|
|
35
|
-
assert result == IsDict({"file": IsTuple("README.md", IsBytes())})
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
@pytest.mark.asyncio
|
|
39
|
-
async def test_async_tuple_input() -> None:
|
|
40
|
-
result = await async_to_httpx_files([("file", readme_path)])
|
|
41
|
-
print(result)
|
|
42
|
-
assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes())))
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def test_string_not_allowed() -> None:
|
|
46
|
-
with pytest.raises(TypeError, match="Expected file types input to be a FileContent type or to be a tuple"):
|
|
47
|
-
to_httpx_files(
|
|
48
|
-
{
|
|
49
|
-
"file": "foo", # type: ignore
|
|
50
|
-
}
|
|
51
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|