1010import osparc
1111import pytest
1212from _utils import skip_if_no_dev_features
13- from conftest import _KB
1413from memory_profiler import memory_usage
15- from typing import Final , List
14+ from typing import Final , List , Callable
15+ from pydantic import ByteSize
16+
17+ _KB : ByteSize = ByteSize (1024 ) # in bytes
18+ _MB : ByteSize = ByteSize (_KB * 1024 ) # in bytes
19+ _GB : ByteSize = ByteSize (_MB * 1024 ) # in bytes
1620
1721
1822def _hash_file (file : Path ) -> str :
@@ -27,10 +31,12 @@ def _hash_file(file: Path) -> str:
2731 return sha256 .hexdigest ()
2832
2933
30- @skip_if_no_dev_features
31- def test_upload_file (tmp_file : Path , api_client : osparc .ApiClient ) -> None :
32- """Test that we can upload a file via the multipart upload"""
34+ def test_upload_file (
35+ create_tmp_file : Callable [[ByteSize ], Path ], api_client : osparc .ApiClient
36+ ) -> None :
37+ """Test that we can upload a file via the multipart upload and download it again. Also check RAM usage of upload/download fcns"""
3338 _allowed_ram_usage_in_mb : Final [int ] = 300 # 300MB
39+ tmp_file = create_tmp_file (ByteSize (1 * _GB ))
3440 assert (
3541 tmp_file .stat ().st_size > _allowed_ram_usage_in_mb * 1024 * 1024
3642 ), "For this test to make sense, file size must be larger than allowed ram usage."
@@ -46,7 +52,7 @@ def max_diff(data: List[int]) -> int:
4652 )
4753 assert (
4854 max_diff (upload_ram_usage_in_mb ) < _allowed_ram_usage_in_mb
49- ), f"Used more than { _allowed_ram_usage_in_mb = } to upload file of size { tmp_file .stat ().st_size = } "
55+ ), f"Used more than { _allowed_ram_usage_in_mb = } to upload file of size { create_tmp_file .stat ().st_size = } "
5056 uploaded_file2 : osparc .File = files_api .upload_file (tmp_file )
5157 assert (
5258 uploaded_file1 .id == uploaded_file2 .id
@@ -72,8 +78,12 @@ def max_diff(data: List[int]) -> int:
7278@pytest .mark .parametrize ("use_checksum" , [True , False ])
7379@pytest .mark .parametrize ("use_id" , [True , False ])
7480def test_search_files (
75- tmp_file : Path , api_client : osparc .ApiClient , use_checksum : bool , use_id : bool
81+ create_tmp_file : Callable [[ByteSize ], Path ],
82+ api_client : osparc .ApiClient ,
83+ use_checksum : bool ,
84+ use_id : bool ,
7685) -> None :
86+ tmp_file = create_tmp_file (ByteSize (1 * _GB ))
7787 checksum : str = _hash_file (tmp_file )
7888 results : osparc .PaginationGenerator
7989 files_api : osparc .FilesApi = osparc .FilesApi (api_client = api_client )
0 commit comments