|
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
| 7 | +from poetry.core.constraints.version.version import Version |
| 8 | + |
7 | 9 | from poetry.console.exceptions import PoetryRuntimeError |
8 | 10 | from poetry.utils.env.python.installer import PythonDownloadNotFoundError |
9 | 11 | from poetry.utils.env.python.installer import PythonInstallationError |
|
15 | 17 | from cleo.testers.command_tester import CommandTester |
16 | 18 | from pytest_mock import MockerFixture |
17 | 19 |
|
| 20 | + from poetry.config.config import Config |
18 | 21 | from tests.types import CommandTesterFactory |
19 | 22 |
|
20 | 23 |
|
@@ -89,19 +92,32 @@ def test_install_failure(tester: CommandTester, mock_installer: MagicMock) -> No |
89 | 92 | assert "foo\n" in tester.io.fetch_error() |
90 | 93 |
|
91 | 94 |
|
92 | | -def test_install_corrupt(tester: CommandTester, mock_installer: MagicMock) -> None: |
| 95 | +@pytest.mark.parametrize("clean", [False, True]) |
| 96 | +def test_install_corrupt( |
| 97 | + tester: CommandTester, mock_installer: MagicMock, config: Config, clean: bool |
| 98 | +) -> None: |
| 99 | + def create_install_dir() -> None: |
| 100 | + (config.python_installation_dir / "cpython@3.11.9").mkdir(parents=True) |
| 101 | + |
93 | 102 | mock_installer.return_value.exists.side_effect = [False, PoetryRuntimeError("foo")] |
| 103 | + mock_installer.return_value.install.side_effect = create_install_dir |
| 104 | + mock_installer.return_value.version = Version.parse("3.11.9") |
94 | 105 |
|
95 | 106 | with pytest.raises(PoetryRuntimeError): |
96 | | - tester.execute("3.11") |
| 107 | + clean_opt = "-c " if clean else "" |
| 108 | + tester.execute(f"{clean_opt}3.11") |
97 | 109 |
|
98 | 110 | mock_installer.assert_called_once_with("3.11", "cpython", False) |
99 | 111 | mock_installer.return_value.install.assert_called_once() |
100 | 112 |
|
101 | | - assert tester.io.fetch_output() == ( |
| 113 | + expected = ( |
102 | 114 | "Downloading and installing 3.11 (cpython) ... Done\n" |
103 | 115 | "Testing 3.11 (cpython) ... Failed\n" |
104 | 116 | ) |
| 117 | + if clean: |
| 118 | + expected += "Removing installation 3.11.9 (cpython) ... Done\n" |
| 119 | + |
| 120 | + assert tester.io.fetch_output() == expected |
105 | 121 |
|
106 | 122 |
|
107 | 123 | def test_install_success(tester: CommandTester, mock_installer: MagicMock) -> None: |
|
0 commit comments