File: test_marker.py

package info (click to toggle)
pdm 2.23.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,552 kB
  • sloc: python: 24,995; javascript: 34; makefile: 24
file content (54 lines) | stat: -rw-r--r-- 2,190 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pytest

from pdm.models.markers import EnvSpec, get_marker
from pdm.models.specifiers import PySpecSet


@pytest.mark.parametrize(
    "original,marker,py_spec",
    [
        ("python_version > '3'", "", ">=3.1"),
        ("python_version > '3.8'", "", ">=3.9"),
        ("python_version != '3.8'", "", "!=3.8.*"),
        ("python_version == '3.7'", "", "==3.7.*"),
        ("python_version in '3.6 3.7'", "", ">=3.6.0,<3.8.0"),
        ("python_full_version >= '3.6.0'", "", ">=3.6"),
        ("python_full_version not in '3.8.3'", "", "!=3.8.3"),
        # mixed marker and python version
        ("python_version > '3.7' and os_name == 'nt'", 'os_name == "nt"', ">=3.8"),
        (
            "python_version > '3.7' or os_name == 'nt'",
            'python_version > "3.7" or os_name == "nt"',
            "",
        ),
    ],
)
def test_split_pyspec(original, marker, py_spec):
    m = get_marker(original)
    a, b = m.split_pyspec()
    assert marker == str(a)
    assert b == PySpecSet(py_spec)


@pytest.mark.parametrize(
    "marker,env_spec,expected",
    [
        ("os_name == 'nt'", EnvSpec.from_spec(">=3.10", "windows"), True),
        ("os_name == 'nt'", EnvSpec.from_spec(">=3.10"), True),
        ("os_name != 'nt'", EnvSpec.from_spec(">=3.10", "windows"), False),
        ("python_version >= '3.7' and os_name == 'nt'", EnvSpec.from_spec(">=3.10"), True),
        ("python_version < '3.7' and os_name == 'nt'", EnvSpec.from_spec(">=3.10"), False),
        ("python_version < '3.7' or os_name == 'nt'", EnvSpec.from_spec(">=3.10"), False),
        ("python_version >= '3.7' and os_name == 'nt'", EnvSpec.from_spec(">=3.10", "linux"), False),
        ("python_version >= '3.7' or os_name == 'nt'", EnvSpec.from_spec(">=3.10", "linux"), True),
        ("python_version >= '3.7' and implementation_name == 'pypy'", EnvSpec.from_spec(">=3.10"), True),
        (
            "python_version >= '3.7' and implementation_name == 'pypy'",
            EnvSpec.from_spec(">=3.10", implementation="cpython"),
            False,
        ),
    ],
)
def test_match_env_spec(marker, env_spec, expected):
    m = get_marker(marker)
    assert m.matches(env_spec) is expected