File: test_application_command_not_found.py

package info (click to toggle)
poetry 2.1.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 10,360 kB
  • sloc: python: 52,127; sh: 117; makefile: 94; ansic: 49
file content (62 lines) | stat: -rw-r--r-- 1,591 bytes parent folder | download | duplicates (2)
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
    )