|
17 | 17 | import typing
|
18 | 18 | import urllib.request
|
19 | 19 | from collections import defaultdict
|
20 |
| -from collections.abc import Generator, Iterable, Mapping, MutableMapping, Sequence |
| 20 | +from collections.abc import Callable, Generator, Iterable, Mapping, MutableMapping, Sequence |
21 | 21 | from dataclasses import dataclass
|
22 | 22 | from enum import Enum
|
23 | 23 | from functools import lru_cache, total_ordering
|
|
36 | 36 | from packaging.version import Version
|
37 | 37 | from platformdirs import user_cache_path
|
38 | 38 |
|
| 39 | +from . import errors |
39 | 40 | from ._compat import tomllib
|
40 | 41 | from .architecture import Architecture
|
41 | 42 | from .errors import FatalError
|
|
66 | 67 |
|
67 | 68 | free_thread_enable_313: Final[Path] = resources_dir / "free-threaded-enable-313.xml"
|
68 | 69 |
|
69 |
| -test_fail_cwd_file: Final[Path] = resources_dir / "testing_temp_dir_file.py" |
70 |
| - |
71 | 70 |
|
72 | 71 | class EnableGroups(enum.Enum):
|
73 | 72 | """
|
@@ -425,6 +424,42 @@ def move_file(src_file: Path, dst_file: Path) -> Path:
|
425 | 424 | return Path(resulting_file).resolve(strict=True)
|
426 | 425 |
|
427 | 426 |
|
| 427 | +def copy_into_local(src: Path, dst: PurePath) -> None: |
| 428 | + """Copy a path from src to dst, regardless of whether it's a file or a directory.""" |
| 429 | + # Ensure the target folder location exists |
| 430 | + Path(dst.parent).mkdir(exist_ok=True, parents=True) |
| 431 | + |
| 432 | + if src.is_dir(): |
| 433 | + shutil.copytree(src, dst) |
| 434 | + else: |
| 435 | + shutil.copy(src, dst) |
| 436 | + |
| 437 | + |
| 438 | +def copy_test_sources( |
| 439 | + test_sources: list[str], |
| 440 | + package_dir: Path, |
| 441 | + test_dir: PurePath, |
| 442 | + copy_into: Callable[[Path, PurePath], None] = copy_into_local, |
| 443 | +) -> None: |
| 444 | + """Copy the list of test sources from the package to the test directory. |
| 445 | +
|
| 446 | + :param test_sources: A list of test paths, relative to the package_dir. |
| 447 | + :param package_dir: The root of the package directory. |
| 448 | + :param test_dir: The folder where test sources should be placed. |
| 449 | + :param copy_info: The copy function to use. By default, does a local |
| 450 | + filesystem copy; but an OCIContainer.copy_info method (or equivalent) |
| 451 | + can be provided. |
| 452 | + """ |
| 453 | + for test_path in test_sources: |
| 454 | + source = package_dir.resolve() / test_path |
| 455 | + |
| 456 | + if not source.exists(): |
| 457 | + msg = f"Test source {test_path} does not exist." |
| 458 | + raise errors.FatalError(msg) |
| 459 | + |
| 460 | + copy_into(source, test_dir / test_path) |
| 461 | + |
| 462 | + |
428 | 463 | class DependencyConstraints:
|
429 | 464 | def __init__(self, base_file_path: Path):
|
430 | 465 | assert base_file_path.exists()
|
|
0 commit comments