File: test_base_embed.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 (65 lines) | stat: -rw-r--r-- 2,609 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import annotations

import sys
from typing import TYPE_CHECKING

import pytest

from virtualenv.run import session_via_cli

if TYPE_CHECKING:
    from pathlib import Path


@pytest.mark.parametrize(
    ("args", "download"),
    [([], False), (["--no-download"], False), (["--never-download"], False), (["--download"], True)],
)
def test_download_cli_flag(args, download, tmp_path):
    session = session_via_cli([*args, str(tmp_path)])
    assert session.seeder.download is download


@pytest.mark.skipif(sys.version_info[:2] == (3, 8), reason="We still bundle wheel for Python 3.8")
@pytest.mark.parametrize("flag", ["--no-wheel", "--wheel=none", "--wheel=embed", "--wheel=bundle"])
def test_wheel_cli_flags_do_nothing(tmp_path, flag):
    session = session_via_cli([flag, str(tmp_path)])
    if sys.version_info[:2] >= (3, 12):
        expected = {"pip": "bundle"}
    else:
        expected = {"pip": "bundle", "setuptools": "bundle"}
    assert session.seeder.distribution_to_versions() == expected


@pytest.mark.skipif(sys.version_info[:2] == (3, 8), reason="We still bundle wheel for Python 3.8")
@pytest.mark.parametrize("flag", ["--no-wheel", "--wheel=none", "--wheel=embed", "--wheel=bundle"])
def test_wheel_cli_flags_warn(tmp_path, flag, capsys):
    session_via_cli([flag, str(tmp_path)])
    out, err = capsys.readouterr()
    assert "The --no-wheel and --wheel options are deprecated." in out + err


@pytest.mark.skipif(sys.version_info[:2] == (3, 8), reason="We still bundle wheel for Python 3.8")
def test_unused_wheel_cli_flags_dont_warn(tmp_path, capsys):
    session_via_cli([str(tmp_path)])
    out, err = capsys.readouterr()
    assert "The --no-wheel and --wheel options are deprecated." not in out + err


@pytest.mark.skipif(sys.version_info[:2] != (3, 8), reason="We only bundle wheel for Python 3.8")
@pytest.mark.parametrize("flag", ["--no-wheel", "--wheel=none", "--wheel=embed", "--wheel=bundle"])
def test_wheel_cli_flags_dont_warn_on_38(tmp_path, flag, capsys):
    session_via_cli([flag, str(tmp_path)])
    out, err = capsys.readouterr()
    assert "The --no-wheel and --wheel options are deprecated." not in out + err


def test_embed_wheel_versions(tmp_path: Path) -> None:
    session = session_via_cli([str(tmp_path)])
    if sys.version_info[:2] >= (3, 12):
        expected = {"pip": "bundle"}
    elif sys.version_info[:2] >= (3, 9):
        expected = {"pip": "bundle", "setuptools": "bundle"}
    else:
        expected = {"pip": "bundle", "setuptools": "bundle", "wheel": "bundle"}
    assert session.seeder.distribution_to_versions() == expected