File: conftest.py

package info (click to toggle)
python-virtualenv 20.38.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,216 kB
  • sloc: python: 12,110; sh: 177; ansic: 61; csh: 53; makefile: 8
file content (35 lines) | stat: -rw-r--r-- 1,154 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from __future__ import annotations

from typing import TYPE_CHECKING

import pytest

from virtualenv.create.via_global_ref.builtin.cpython.cpython3 import CPython3Posix

if TYPE_CHECKING:
    from collections.abc import Callable
    from pathlib import Path

    from pytest_mock import MockerFixture

    from tests.types import MakeInterpreter
    from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest

    CollectSources = Callable[[dict[str, object]], list[PathRefToDest]]


@pytest.fixture
def collect_sources(tmp_path: Path, make_interpreter: MakeInterpreter, mocker: MockerFixture) -> CollectSources:
    def _collect(sysconfig_vars: dict[str, object]) -> list[PathRefToDest]:
        interpreter = make_interpreter(
            sysconfig_vars={**sysconfig_vars, "PYTHONFRAMEWORK": ""},
            prefix=str(tmp_path),
        )
        interpreter.system_executable = str(tmp_path / "bin" / "python3")
        mocker.patch(
            "virtualenv.create.via_global_ref.builtin.cpython.cpython3.Path.exists",
            return_value=True,
        )
        return list(CPython3Posix.sources(interpreter))

    return _collect