|
1 | 1 | import os |
| 2 | +import tempfile |
| 3 | +from shutil import copyfile, copytree |
2 | 4 | from sys import platform |
3 | 5 |
|
4 | 6 |
|
@@ -26,7 +28,49 @@ def dev_config(): |
26 | 28 |
|
27 | 29 | def test_config(path): |
28 | 30 | default_config() |
29 | | - print(f"{os.path.dirname(__file__)=}", flush=True) |
30 | | - os.environ["DATA_FOLDER_PATH"] = os.path.join(path, "data") |
31 | 31 |
|
32 | | - print(f"{os.environ.get('DATA_FOLDER_PATH')=}", flush=True) |
| 32 | + tmp_data_root = tempfile.mkdtemp(prefix="ogw_test_data_") |
| 33 | + os.environ["DATA_FOLDER_PATH"] = tmp_data_root |
| 34 | + |
| 35 | + src_data = os.path.join(path, "data") |
| 36 | + if not os.path.isdir(src_data): |
| 37 | + raise FileNotFoundError(f"Test data folder not found: {src_data}") |
| 38 | + |
| 39 | + test_ids = ["123456789", "12345678"] |
| 40 | + valid_exts = {".vtp", ".vti", ".vtu", ".vtm"} |
| 41 | + |
| 42 | + project_uuid = "test-project-uuid" |
| 43 | + data_uuid = "test-data-uuid" |
| 44 | + uploads_directory = os.path.join(tmp_data_root, project_uuid, "uploads") |
| 45 | + structure_directory = os.path.join(tmp_data_root, project_uuid, data_uuid) |
| 46 | + |
| 47 | + for directory in [ |
| 48 | + *test_ids, |
| 49 | + uploads_directory, |
| 50 | + structure_directory, |
| 51 | + ]: # create directories for tests |
| 52 | + os.makedirs( |
| 53 | + ( |
| 54 | + os.path.join(tmp_data_root, directory) |
| 55 | + if isinstance(directory, str) |
| 56 | + else directory |
| 57 | + ), |
| 58 | + exist_ok=True, |
| 59 | + ) |
| 60 | + |
| 61 | + for root, directories, files in os.walk(src_data): |
| 62 | + for directory in directories: |
| 63 | + dst = os.path.join(tmp_data_root, test_ids[0], directory) |
| 64 | + copytree(os.path.join(root, directory), dst, dirs_exist_ok=True) |
| 65 | + |
| 66 | + for file in files: |
| 67 | + if os.path.splitext(file)[1].lower() not in valid_exts: |
| 68 | + continue |
| 69 | + |
| 70 | + src = os.path.join(root, file) |
| 71 | + for test_id in test_ids: |
| 72 | + copyfile(src, os.path.join(tmp_data_root, test_id, file)) |
| 73 | + copyfile(src, os.path.join(structure_directory, file)) |
| 74 | + copyfile(src, os.path.join(uploads_directory, file)) |
| 75 | + |
| 76 | + print(f"\nDATA_FOLDER_PATH set to: {tmp_data_root}", flush=True) |
0 commit comments