|
2 | 2 | from unittest.mock import patch |
3 | 3 |
|
4 | 4 | import pytest |
| 5 | +from packaging.specifiers import SpecifierSet |
5 | 6 | from packaging.version import Version |
6 | 7 |
|
7 | 8 | from spec0_action.parsing import read_schedule, read_toml |
@@ -89,3 +90,121 @@ def test_update_all_noop_when_not_set(patch_datetime_now): |
89 | 90 | with patch.object(spec0_action, "_get_oldest_version_in_window") as mock_pypi: |
90 | 91 | update_pyproject_toml(pyproject, schedule) |
91 | 92 | mock_pypi.assert_not_called() |
| 93 | + |
| 94 | + |
| 95 | +def test_requires_python_preserves_existing_restrictions(patch_datetime_now): |
| 96 | + pyproject = _minimal_pyproject() |
| 97 | + pyproject["project"]["requires-python"] = ">=3.9,<3.14,!=3.13.*" |
| 98 | + schedule = read_schedule("tests/test_data/test_schedule.json") |
| 99 | + |
| 100 | + update_pyproject_toml(pyproject, schedule) |
| 101 | + |
| 102 | + assert SpecifierSet(pyproject["project"]["requires-python"]) == SpecifierSet( |
| 103 | + ">=3.12,<3.14,!=3.13.*" |
| 104 | + ) |
| 105 | + |
| 106 | + |
| 107 | +def test_canonical_package_names_match_schedule(patch_datetime_now): |
| 108 | + pyproject = _minimal_pyproject("Numpy>=1.20", "scikit_learn>=1.0") |
| 109 | + schedule = read_schedule("tests/test_data/test_schedule.json") |
| 110 | + |
| 111 | + update_pyproject_toml(pyproject, schedule) |
| 112 | + |
| 113 | + assert pyproject["project"]["dependencies"] == [ |
| 114 | + "Numpy>=2.0.0", |
| 115 | + "scikit_learn>=1.4.0", |
| 116 | + ] |
| 117 | + |
| 118 | + |
| 119 | +def test_optional_dependencies_and_dependency_groups_are_updated(patch_datetime_now): |
| 120 | + pyproject = _minimal_pyproject() |
| 121 | + pyproject["project"]["optional-dependencies"] = { |
| 122 | + "test": ["Numpy>=1.20"], |
| 123 | + } |
| 124 | + pyproject["dependency-groups"] = { |
| 125 | + "dev": ["numpy>=1.20", {"include-group": "test"}], |
| 126 | + } |
| 127 | + schedule = read_schedule("tests/test_data/test_schedule.json") |
| 128 | + |
| 129 | + update_pyproject_toml(pyproject, schedule) |
| 130 | + |
| 131 | + assert pyproject["project"]["optional-dependencies"]["test"] == ["Numpy>=2.0.0"] |
| 132 | + assert pyproject["dependency-groups"]["dev"] == [ |
| 133 | + "numpy>=2.0.0", |
| 134 | + {"include-group": "test"}, |
| 135 | + ] |
| 136 | + |
| 137 | + |
| 138 | +def test_missing_project_dependencies_is_noop(patch_datetime_now): |
| 139 | + pyproject = {"project": {"requires-python": ">=3.9"}} |
| 140 | + schedule = read_schedule("tests/test_data/test_schedule.json") |
| 141 | + |
| 142 | + update_pyproject_toml(pyproject, schedule) |
| 143 | + |
| 144 | + assert SpecifierSet(pyproject["project"]["requires-python"]) == SpecifierSet( |
| 145 | + ">=3.12" |
| 146 | + ) |
| 147 | + |
| 148 | + |
| 149 | +def test_pixi_feature_pypi_dependencies_and_non_version_tables(patch_datetime_now): |
| 150 | + pyproject = _minimal_pyproject() |
| 151 | + pyproject["tool"] = { |
| 152 | + "pixi": { |
| 153 | + "dependencies": { |
| 154 | + "scikit-learn": {"git": "https://example.invalid/scikit-learn.git"} |
| 155 | + }, |
| 156 | + "feature": { |
| 157 | + "test": { |
| 158 | + "pypi-dependencies": {"Numpy": ">=1.20"}, |
| 159 | + "dependencies": { |
| 160 | + "xarray": {"url": "https://example.invalid/pkg.whl"} |
| 161 | + }, |
| 162 | + } |
| 163 | + }, |
| 164 | + } |
| 165 | + } |
| 166 | + schedule = read_schedule("tests/test_data/test_schedule.json") |
| 167 | + |
| 168 | + update_pyproject_toml(pyproject, schedule) |
| 169 | + |
| 170 | + assert ( |
| 171 | + pyproject["tool"]["pixi"]["feature"]["test"]["pypi-dependencies"]["Numpy"] |
| 172 | + == ">=2.0.0" |
| 173 | + ) |
| 174 | + assert pyproject["tool"]["pixi"]["dependencies"]["scikit-learn"] == { |
| 175 | + "git": "https://example.invalid/scikit-learn.git" |
| 176 | + } |
| 177 | + assert pyproject["tool"]["pixi"]["feature"]["test"]["dependencies"]["xarray"] == { |
| 178 | + "url": "https://example.invalid/pkg.whl" |
| 179 | + } |
| 180 | + |
| 181 | + |
| 182 | +def test_update_all_uses_version_release_date_not_new_file_upload( |
| 183 | + patch_datetime_now, |
| 184 | +): |
| 185 | + class Response: |
| 186 | + def raise_for_status(self): |
| 187 | + pass |
| 188 | + |
| 189 | + def json(self): |
| 190 | + return { |
| 191 | + "files": [ |
| 192 | + { |
| 193 | + "filename": "example-1.0.0.tar.gz", |
| 194 | + "upload-time": "2020-01-01T00:00:00Z", |
| 195 | + }, |
| 196 | + { |
| 197 | + "filename": "example-1.0.0-py3-none-any.whl", |
| 198 | + "upload-time": "2025-01-01T00:00:00Z", |
| 199 | + }, |
| 200 | + { |
| 201 | + "filename": "example-2.0.0-py3-none-any.whl", |
| 202 | + "upload-time": "2024-01-01T00:00:00Z", |
| 203 | + }, |
| 204 | + ] |
| 205 | + } |
| 206 | + |
| 207 | + with patch.object(spec0_action.requests, "get", return_value=Response()): |
| 208 | + assert spec0_action._get_oldest_version_in_window("example", 2) == Version( |
| 209 | + "2.0.0" |
| 210 | + ) |
0 commit comments