File: test_project.py

package info (click to toggle)
python-nox 2025.11.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,880 kB
  • sloc: python: 10,199; makefile: 204; sh: 6
file content (100 lines) | stat: -rw-r--r-- 3,087 bytes parent folder | download
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
import re

import pytest

from nox.project import dependency_groups, python_versions


def test_classifiers() -> None:
    pyproject = {
        "project": {
            "classifiers": [
                "Programming Language :: Python :: 3.7",
                "Programming Language :: Python :: 3.9",
                "Programming Language :: Python :: 3.12",
                "Programming Language :: Python",
                "Programming Language :: Python :: 3 :: Only",
                "Topic :: Software Development :: Testing",
            ],
            "requires-python": ">=3.10",
        }
    }

    assert python_versions(pyproject) == ["3.7", "3.9", "3.12"]


def test_no_classifiers() -> None:
    pyproject = {"project": {"requires-python": ">=3.9"}}
    with pytest.raises(ValueError, match="No Python version classifiers"):
        python_versions(pyproject)


def test_no_requires_python() -> None:
    pyproject = {"project": {"classifiers": ["Programming Language :: Python :: 3.12"]}}
    with pytest.raises(
        ValueError, match=re.escape('No "project.requires-python" value set')
    ):
        python_versions(pyproject, max_version="3.13")


def test_python_range() -> None:
    pyproject = {
        "project": {
            "classifiers": [
                "Programming Language :: Python :: 3.7",
                "Programming Language :: Python :: 3.9",
                "Programming Language :: Python :: 3.12",
                "Programming Language :: Python",
                "Programming Language :: Python :: 3 :: Only",
                "Topic :: Software Development :: Testing",
            ],
            "requires-python": ">=3.10",
        }
    }

    assert python_versions(pyproject, max_version="3.12") == ["3.10", "3.11", "3.12"]
    assert python_versions(pyproject, max_version="3.11") == ["3.10", "3.11"]


def test_python_range_gt() -> None:
    pyproject = {"project": {"requires-python": ">3.2.1,<3.3"}}

    assert python_versions(pyproject, max_version="3.4") == ["3.2", "3.3", "3.4"]


def test_python_range_no_min() -> None:
    pyproject = {"project": {"requires-python": "==3.3.1"}}

    with pytest.raises(ValueError, match="No minimum version found"):
        python_versions(pyproject, max_version="3.5")


def test_dependency_groups() -> None:
    example = {
        "dependency-groups": {
            "test": ["pytest", "coverage"],
            "docs": ["sphinx", "sphinx-rtd-theme"],
            "typing": ["mypy", "types-requests"],
            "typing-test": [
                {"include-group": "typing"},
                {"include-group": "test"},
                "useful-types",
            ],
        }
    }

    assert dependency_groups(example, "test") == ("pytest", "coverage")
    assert dependency_groups(example, "typing-test") == (
        "mypy",
        "types-requests",
        "pytest",
        "coverage",
        "useful-types",
    )
    assert dependency_groups(example, "typing_test") == (
        "mypy",
        "types-requests",
        "pytest",
        "coverage",
        "useful-types",
    )