|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import pytest |
| 4 | +import pytest_cases |
| 5 | + |
| 6 | +from tests.helpers import run_command |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.order(after="test_venv_activate.py::test_venv_activate") |
| 10 | +@pytest_cases.parametrize("yes", ["y", "yes", "Y", "Yes", "YES"]) |
| 11 | +@pytest_cases.parametrize("activated", [False, True]) |
| 12 | +def test_venv_delete_ask_confirmation_yes(activated: bool, yes: str, tmp_path: Path): |
| 13 | + venv_path = tmp_path / ".venv" |
| 14 | + |
| 15 | + # Execute: Create, then delete, the virtual environment |
| 16 | + run_command("venv delete", command_input=yes, cwd=tmp_path, activated=activated) |
| 17 | + |
| 18 | + # Verify: check that the virtual environment directory no longer exists |
| 19 | + assert not venv_path.is_dir() |
| 20 | + |
| 21 | + # Test that trying to delete again doesn't cause an error |
| 22 | + run_command("venv delete", command_input=yes, cwd=tmp_path, activated=activated) |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.order(after="test_venv_activate.py::test_venv_activate") |
| 26 | +@pytest_cases.parametrize("no", ["", "n", "N", "No", "NO", "asd"]) |
| 27 | +@pytest_cases.parametrize("activated", [False, True]) |
| 28 | +def test_venv_delete_ask_confirmation_no(activated: bool, no: str, tmp_path: Path): |
| 29 | + venv_path = tmp_path / ".venv" |
| 30 | + |
| 31 | + # Execute: Create, then try to delete, the virtual environment, but say no |
| 32 | + run_command("venv delete", command_input=no, cwd=tmp_path, activated=activated) |
| 33 | + |
| 34 | + if activated: |
| 35 | + # Verify: check that the virtual environment directory still exists (if it was created) |
| 36 | + assert venv_path.is_dir() |
| 37 | + |
| 38 | + |
| 39 | +@pytest.mark.order(after="test_venv_activate.py::test_venv_activate") |
| 40 | +@pytest_cases.parametrize("activated", [False, True]) |
| 41 | +def test_venv_delete_no_confirmation(activated: bool, tmp_path: Path): |
| 42 | + venv_path = tmp_path / ".venv" |
| 43 | + |
| 44 | + # Execute: Create, then delete, the virtual environment |
| 45 | + run_command("venv delete -y", cwd=tmp_path, activated=activated) |
| 46 | + |
| 47 | + # Verify: check that the virtual environment directory no longer exists |
| 48 | + assert not venv_path.is_dir() |
| 49 | + |
| 50 | + # Test that trying to delete again doesn't cause an error |
| 51 | + run_command("venv delete -y", cwd=tmp_path, activated=activated) |
0 commit comments