File: test_interpreters.py

package info (click to toggle)
python-virtualenv 20.33.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,124 kB
  • sloc: python: 10,907; sh: 160; ansic: 61; csh: 47; makefile: 8
file content (32 lines) | stat: -rw-r--r-- 1,007 bytes parent folder | download | duplicates (3)
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
from __future__ import annotations

import sys
from uuid import uuid4

import pytest

from virtualenv.discovery.py_info import PythonInfo
from virtualenv.run import cli_run


@pytest.mark.slow
def test_failed_to_find_bad_spec():
    of_id = uuid4().hex
    with pytest.raises(RuntimeError) as context:
        cli_run(["-p", of_id])
    msg = repr(RuntimeError(f"failed to find interpreter for Builtin discover of python_spec={of_id!r}"))
    assert repr(context.value) == msg


SYSTEM = PythonInfo.current_system()


@pytest.mark.parametrize(
    "of_id",
    ({sys.executable} if sys.executable != SYSTEM.executable else set()) | {SYSTEM.implementation},
)
def test_failed_to_find_implementation(of_id, mocker):
    mocker.patch("virtualenv.run.plugin.creators.CreatorSelector._OPTIONS", return_value={})
    with pytest.raises(RuntimeError) as context:
        cli_run(["-p", of_id])
    assert repr(context.value) == repr(RuntimeError(f"No virtualenv implementation for {PythonInfo.current_system()}"))