|
18 | 18 | from packaging.version import Version
|
19 | 19 | from pydantic import ByteSize
|
20 | 20 | from typing import NamedTuple, Final
|
21 |
| -from tempfile import TemporaryDirectory |
22 | 21 |
|
23 | 22 | try:
|
24 | 23 | from osparc._settings import ConfigurationEnvVars
|
@@ -113,8 +112,8 @@ def api_client() -> Iterable[osparc.ApiClient]:
|
113 | 112 |
|
114 | 113 |
|
115 | 114 | @pytest.fixture(scope="session")
|
116 |
| -def files_api(api_client: osparc.ApiClient) -> Iterable[osparc.FilesApi]: |
117 |
| - yield osparc.FilesApi(api_client=api_client) |
| 115 | +def files_api(api_client: osparc.ApiClient) -> osparc.FilesApi: |
| 116 | + return osparc.FilesApi(api_client=api_client) |
118 | 117 |
|
119 | 118 |
|
120 | 119 | @pytest.fixture
|
@@ -144,25 +143,28 @@ class ServerFile(NamedTuple):
|
144 | 143 |
|
145 | 144 |
|
146 | 145 | @pytest.fixture(scope="session")
|
147 |
| -def large_server_file(files_api: osparc.FilesApi) -> Iterable[ServerFile]: |
| 146 | +def large_server_file( |
| 147 | + files_api: osparc.FilesApi, tmp_path_factory |
| 148 | +) -> Iterable[ServerFile]: |
148 | 149 | _file_size: Final[ByteSize] = ByteSize(1 * _GB)
|
149 |
| - with TemporaryDirectory() as tmp_path: |
150 |
| - tmp_path = Path(tmp_path) |
151 |
| - tmp_file = tmp_path / "large_test_file.txt" |
152 |
| - ss: random.SeedSequence = random.SeedSequence() |
153 |
| - logging.info("Entropy used to generate random file: %s", f"{ss.entropy}") |
154 |
| - rng: random.Generator = random.default_rng(ss) |
155 |
| - tmp_file.write_bytes(rng.bytes(1000)) |
156 |
| - with open(tmp_file, "wb") as f: |
157 |
| - f.truncate(_file_size) |
158 |
| - assert ( |
159 |
| - tmp_file.stat().st_size == _file_size |
160 |
| - ), f"Could not create file of size: {_file_size}" |
161 |
| - uploaded_file: osparc.File = files_api.upload_file(tmp_file) |
162 |
| - |
163 |
| - yield ServerFile(local_file=tmp_file, server_file=uploaded_file) |
164 |
| - |
165 |
| - files_api.delete_file(uploaded_file.id) |
| 150 | + tmp_file = ( |
| 151 | + tmp_path_factory.mktemp(basename=large_server_file.__name__) |
| 152 | + / "large_test_file.txt" |
| 153 | + ) |
| 154 | + ss: random.SeedSequence = random.SeedSequence() |
| 155 | + logging.info("Entropy used to generate random file: %s", f"{ss.entropy}") |
| 156 | + rng: random.Generator = random.default_rng(ss) |
| 157 | + tmp_file.write_bytes(rng.bytes(1000)) |
| 158 | + with open(tmp_file, "wb") as f: |
| 159 | + f.truncate(_file_size) |
| 160 | + assert ( |
| 161 | + tmp_file.stat().st_size == _file_size |
| 162 | + ), f"Could not create file of size: {_file_size}" |
| 163 | + uploaded_file: osparc.File = files_api.upload_file(tmp_file) |
| 164 | + |
| 165 | + yield ServerFile(local_file=tmp_file, server_file=uploaded_file) |
| 166 | + |
| 167 | + files_api.delete_file(uploaded_file.id) |
166 | 168 |
|
167 | 169 |
|
168 | 170 | @pytest.fixture
|
|
0 commit comments