Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/manage/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,13 +841,19 @@ def execute(self):
class HelpWithErrorCommand(HelpCommand):
CMD = "__help_with_error"

def __init__(self, args, root=None):
# Essentially disable argument processing for this command
super().__init__(args[:1], root)
self.args = args[1:]

def execute(self):
LOGGER.print(f"!R!Unknown command: {EXE_NAME} {' '.join(self.args)}!W!")
args = [EXE_NAME, *self.args]
LOGGER.print(f"!R!Unknown command: {' '.join(args)}!W!")
LOGGER.print(COPYRIGHT)
self.show_welcome(copyright=False)
LOGGER.print(BaseCommand.usage_text())
LOGGER.print(BaseCommand.subcommands_list())
LOGGER.print(f"The command !R!{EXE_NAME} {' '.join(self.args)}!W! was not recognized.")
LOGGER.print(f"The command !R!{' '.join(args)}!W! was not recognized.")


class DefaultConfig(BaseCommand):
Expand Down
28 changes: 24 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,31 @@
LOGGER.level = DEBUG

class LogCaptureHandler(list):
def skip_until(self, pattern, args=()):
return ('until', pattern, args)

def __call__(self, *cmp):
for x, y in zip(self, cmp):
assert re.match(y[0], x[0])
assert x[1] == y[1]
assert len(self) == len(cmp)
it1 = iter(self)
for y in cmp:
if not isinstance(y, tuple):
op, pat, args = None, y, []
elif len(y) == 3:
op, pat, args = y
elif len(y) == 2:
op = None
pat, args = y

while True:
try:
x = next(it1)
except StopIteration:
pytest.fail(f"Not enough elements were logged looking for {pat}")

Check warning on line 42 in tests/conftest.py

View check run for this annotation

Codecov / codecov/patch

tests/conftest.py#L41-L42

Added lines #L41 - L42 were not covered by tests
if op == 'until' and not re.match(pat, x[0]):
continue
assert re.match(pat, x[0])
assert tuple(x[1]) == tuple(args)
break


@pytest.fixture
def assert_log():
Expand Down
19 changes: 19 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
import secrets
from manage import commands


def test_help_with_error_command(assert_log, monkeypatch):
expect = secrets.token_hex(16)
cmd = commands.HelpWithErrorCommand(
[commands.HelpWithErrorCommand.CMD, expect, "-v", "-q"],
None
)
monkeypatch.setattr(commands, "EXE_NAME", "pymanager-test")
monkeypatch.setattr(commands, "WELCOME", "")
cmd.execute()
assert_log(
assert_log.skip_until(rf".*Unknown command: pymanager-test {expect} -v -q.*"),
r"Python installation manager \d+\.\d+.*",
assert_log.skip_until(rf"The command .*?pymanager-test {expect} -v -q.*"),
)