|
| 1 | +import sys |
| 2 | +from typing import Any, Callable |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from tests.lib import PipTestEnvironment, TestPipResult |
| 7 | + |
| 8 | +PipRunner = Callable[..., TestPipResult] |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture() |
| 12 | +def pip(script: PipTestEnvironment) -> PipRunner: |
| 13 | + def pip(*args: str, **kwargs: Any) -> TestPipResult: |
| 14 | + return script.pip(*args, "--use-feature=truststore", **kwargs) |
| 15 | + |
| 16 | + return pip |
| 17 | + |
| 18 | + |
| 19 | +@pytest.mark.skipif(sys.version_info >= (3, 10), reason="3.10 can run truststore") |
| 20 | +def test_truststore_error_on_old_python(pip: PipRunner) -> None: |
| 21 | + result = pip( |
| 22 | + "install", |
| 23 | + "--no-index", |
| 24 | + "does-not-matter", |
| 25 | + expect_error=True, |
| 26 | + ) |
| 27 | + assert "The truststore feature is only available for Python 3.10+" in result.stderr |
| 28 | + |
| 29 | + |
| 30 | +@pytest.mark.skipif(sys.version_info < (3, 10), reason="3.10+ required for truststore") |
| 31 | +def test_truststore_error_without_preinstalled(pip: PipRunner) -> None: |
| 32 | + result = pip( |
| 33 | + "install", |
| 34 | + "--no-index", |
| 35 | + "does-not-matter", |
| 36 | + expect_error=True, |
| 37 | + ) |
| 38 | + assert ( |
| 39 | + "To use the truststore feature, 'truststore' must be installed into " |
| 40 | + "pip's current environment." |
| 41 | + ) in result.stderr |
| 42 | + |
| 43 | + |
| 44 | +@pytest.mark.skipif(sys.version_info < (3, 10), reason="3.10+ required for truststore") |
| 45 | +@pytest.mark.network |
| 46 | +@pytest.mark.parametrize( |
| 47 | + "package", |
| 48 | + [ |
| 49 | + "INITools", |
| 50 | + "https://github.com/pypa/pip-test-package/archive/refs/heads/master.zip", |
| 51 | + ], |
| 52 | + ids=["PyPI", "GitHub"], |
| 53 | +) |
| 54 | +def test_trustore_can_install( |
| 55 | + script: PipTestEnvironment, |
| 56 | + pip: PipRunner, |
| 57 | + package: str, |
| 58 | +) -> None: |
| 59 | + script.pip("install", "truststore") |
| 60 | + result = pip("install", package) |
| 61 | + assert "Successfully installed" in result.stdout |
0 commit comments