| 1 |
import os |
| 2 |
import shutil |
| 3 |
import sys |
| 4 |
from pathlib import Path |
| 5 |
|
| 6 |
import pytest |
| 7 |
|
| 8 |
|
| 9 |
def _win32_longpath(path): |
| 10 |
""" |
| 11 |
Helper function to add the long path prefix for Windows, so that shutil.copytree |
| 12 |
won't fail while working with paths with 255+ chars. |
| 13 |
""" |
| 14 |
if sys.platform == "win32": |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
return "\\\\?\\" + os.path.normpath(path) |
| 20 |
else: |
| 21 |
return path |
| 22 |
|
| 23 |
|
| 24 |
@pytest.fixture |
| 25 |
def shared_datadir(request, tmp_path): |
| 26 |
original_shared_path = os.path.join(request.fspath.dirname, "data") |
| 27 |
temp_path = tmp_path / "data" |
| 28 |
shutil.copytree( |
| 29 |
_win32_longpath(original_shared_path), _win32_longpath(str(temp_path)) |
| 30 |
) |
| 31 |
return temp_path |
| 32 |
|
| 33 |
|
| 34 |
@pytest.fixture |
| 35 |
def original_datadir(request): |
| 36 |
return Path(os.path.splitext(request.module.__file__)[0]) |
| 37 |
|
| 38 |
|
| 39 |
@pytest.fixture |
| 40 |
def datadir(original_datadir, tmp_path): |
| 41 |
result = tmp_path / original_datadir.stem |
| 42 |
if original_datadir.is_dir(): |
| 43 |
shutil.copytree( |
| 44 |
_win32_longpath(str(original_datadir)), _win32_longpath(str(result)) |
| 45 |
) |
| 46 |
else: |
| 47 |
result.mkdir() |
| 48 |
return result |