Files

56 lines
1.9 KiB
Python
Raw Permalink Normal View History

2020-06-18 02:00:30 +02:00
from pathlib import Path
2025-03-10 21:45:54 +00:00
import pytest
2025-01-27 20:35:56 +01:00
from cibuildwheel.util.packaging import DependencyConstraints
2021-01-06 13:50:58 -05:00
2020-02-15 11:57:31 +00:00
2025-03-10 21:45:54 +00:00
def test_defaults(tmp_path: Path) -> None:
dependency_constraints = DependencyConstraints.pinned()
2020-06-18 02:00:30 +02:00
project_root = Path(__file__).parents[1]
2021-05-03 11:45:43 -04:00
resources_dir = project_root / "cibuildwheel" / "resources"
2025-03-10 21:45:54 +00:00
assert dependency_constraints.base_file_path
2021-05-03 11:45:43 -04:00
assert dependency_constraints.base_file_path.samefile(resources_dir / "constraints.txt")
2025-03-10 21:45:54 +00:00
constraints_file = dependency_constraints.get_for_python_version(
version="3.99", tmp_dir=tmp_path
2021-04-30 17:56:34 -04:00
)
2025-03-10 21:45:54 +00:00
assert constraints_file
assert constraints_file.samefile(resources_dir / "constraints.txt")
constraints_file = dependency_constraints.get_for_python_version(
version="3.9", tmp_dir=tmp_path
2021-04-30 17:56:34 -04:00
)
2025-03-10 21:45:54 +00:00
assert constraints_file
assert constraints_file.samefile(resources_dir / "constraints-python39.txt")
constraints_file = dependency_constraints.get_for_python_version(
version="3.13", tmp_dir=tmp_path
2021-04-30 17:56:34 -04:00
)
2025-03-10 21:45:54 +00:00
assert constraints_file
assert constraints_file.samefile(resources_dir / "constraints-python313.txt")
def test_inline_packages(tmp_path: Path) -> None:
dependency_constraints = DependencyConstraints(
base_file_path=None,
packages=["foo==1.2.3", "bar==4.5.6"],
)
constraint_file = dependency_constraints.get_for_python_version(version="x.x", tmp_dir=tmp_path)
assert constraint_file
constraints_file_contents = constraint_file.read_text()
assert constraints_file_contents == "foo==1.2.3\nbar==4.5.6"
@pytest.mark.parametrize("config_string", ["", "latest", "packages:"])
def test_empty_constraints(config_string: str) -> None:
dependency_constraints = DependencyConstraints.from_config_string(config_string)
assert not dependency_constraints.packages
assert not dependency_constraints.base_file_path
assert dependency_constraints == DependencyConstraints.latest()