File: test_specifiers.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 (113 lines) | stat: -rw-r--r-- 3,225 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import pytest

from pdm.models.specifiers import PySpecSet


@pytest.mark.filterwarnings("ignore::FutureWarning")
@pytest.mark.parametrize(
    "original,normalized",
    [
        (">=3.6", ">=3.6"),
        ("<3.8", "<3.8"),
        ("~=2.7.0", "~=2.7.0"),
        ("", ""),
        (">=3.6,<3.8", "<3.8,>=3.6"),
        (">3.6", ">3.6"),
        ("<=3.7", "<=3.7"),
        (">=3.4.*", ">=3.4.0"),
        (">3.4.*", ">=3.4.0"),
        ("<=3.4.*", "<3.4.0"),
        ("<3.4.*", "<3.4.0"),
        (">=3.0+g1234", ">=3.0"),
        ("<3.0+g1234", "<3.0"),
        ("<3.10.0a6", "<3.10.0a6"),
        ("<3.10.2a3", "<3.10.2a3"),
    ],
)
def test_normalize_pyspec(original, normalized):
    spec = PySpecSet(original)
    assert str(spec) == normalized


@pytest.mark.parametrize(
    "left,right,result",
    [
        (">=3.6", ">=3.0", ">=3.6"),
        (">=3.6", "<3.8", "<3.8,>=3.6"),
        ("", ">=3.6", ">=3.6"),
        (">=3.6", "<3.2", "<empty>"),
        (">=2.7,!=3.0.*", "!=3.1.*", "!=3.0.*,!=3.1.*,>=2.7"),
        (">=3.11.0a2", "<3.11.0b", ">=3.11.0a2,<3.11.0b0"),
        ("<3.11.0a2", ">3.11.0b", "<empty>"),
    ],
)
def test_pyspec_and_op(left, right, result):
    left = PySpecSet(left)
    right = PySpecSet(right)
    assert left & right == PySpecSet(result)


@pytest.mark.parametrize(
    "left,right,result",
    [
        (">=3.6", ">=3.0", ">=3.0"),
        ("", ">=3.6", ""),
        (">=3.6", "<3.7", ""),
        (">=3.6,<3.8", ">=3.4,<3.7", "<3.8,>=3.4"),
        ("~=2.7", ">=3.6", "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7"),
        ("<2.7.15", ">=3.0", "!=2.7.15,!=2.7.16,!=2.7.17,!=2.7.18"),
        (">3.11.0a2", ">3.11.0b", ">3.11.0a2"),
    ],
)
def test_pyspec_or_op(left, right, result):
    left = PySpecSet(left)
    right = PySpecSet(right)
    assert str(left | right) == result


def test_impossible_pyspec():
    spec = PySpecSet(">=3.6,<3.4")
    a = PySpecSet(">=2.7")
    assert spec.is_empty()
    assert (spec & a).is_empty()
    assert spec | a == a


@pytest.mark.filterwarnings("ignore::FutureWarning")
@pytest.mark.parametrize(
    "left,right",
    [
        ("~=2.7", ">=2.7"),
        (">=3.6", ""),
        (">=3.7", ">=3.6,<4.0"),
        (">=2.7,<3.0", ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"),
        (">=3.6", ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"),
        (
            ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*",
            ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*",
        ),
        (">=3.11.*", ">=3.11.0rc"),
    ],
)
def test_pyspec_is_subset_superset(left, right):
    left = PySpecSet(left)
    right = PySpecSet(right)
    assert left.is_subset(right), f"{left}, {right}"
    assert right.is_superset(left), f"{left}, {right}"


@pytest.mark.parametrize(
    "left,right",
    [
        ("~=2.7", ">=2.6,<2.7.15"),
        (">=3.7", ">=3.6,<3.9"),
        (">=3.7,<3.6", "==2.7"),
        (">=3.0,!=3.4.*", ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"),
        (">=3.11.0", "<3.11.0a"),
    ],
)
def test_pyspec_isnot_subset_superset(left, right):
    left = PySpecSet(left)
    right = PySpecSet(right)
    assert not left.is_subset(right), f"{left}, {right}"
    assert not left.is_superset(right), f"{left}, {right}"