1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
from cleo.testers.application_tester import ApplicationTester
from poetry.console.application import Application
if TYPE_CHECKING:
from tests.types import CommandFactory
@pytest.fixture
def tester() -> ApplicationTester:
return ApplicationTester(Application())
@pytest.mark.parametrize(
("command", "suggested"),
[
("en", ["env activate", "env info", "env list", "env remove", "env use"]),
("sou", ["source add", "source remove", "source show"]),
],
)
def test_application_command_not_found_messages(
command: str,
suggested: list[str] | None,
tester: ApplicationTester,
command_factory: CommandFactory,
) -> None:
tester.execute(f"{command}")
assert tester.status_code != 0
stderr = tester.io.fetch_error()
assert f"The requested command {command} does not exist." in stderr
if suggested is None:
assert "Did you mean one of these perhaps?" not in stderr
else:
for suggestion in suggested:
assert suggestion in stderr
@pytest.mark.parametrize(
"namespace",
["cache", "debug", "env", "self", "source"],
)
def test_application_namespaced_command_not_found_messages(
namespace: str,
tester: ApplicationTester,
command_factory: CommandFactory,
) -> None:
tester.execute(f"{namespace} xxx")
assert tester.status_code != 0
stderr = tester.io.fetch_error()
assert (
f"The requested command does not exist in the {namespace} namespace." in stderr
)
|