-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the naked invocation display a compacted help
- Loading branch information
1 parent
37ef670
commit d14e054
Showing
2 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import pytest | ||
import shutil | ||
import os | ||
from tests.utils import http | ||
|
||
NAKED_HELP_MESSAGE = """\ | ||
usage: | ||
http [METHOD] URL [REQUEST_ITEM ...] | ||
error: | ||
the following arguments are required: URL | ||
For more information try with --help or visit the https://pie.co/docs | ||
""" | ||
|
||
NAKED_HELP_MESSAGE_PRETTY_WITH_NO_ARG = """\ | ||
usage: | ||
http [--pretty {all,colors,format,none}] [METHOD] URL [REQUEST_ITEM ...] | ||
error: | ||
argument --pretty: expected one argument | ||
For more information try with --help or visit the https://pie.co/docs | ||
""" | ||
|
||
NAKED_HELP_MESSAGE_PRETTY_WITH_INVALID_ARG = """\ | ||
usage: | ||
http [--pretty {all,colors,format,none}] [METHOD] URL [REQUEST_ITEM ...] | ||
error: | ||
argument --pretty: invalid choice: '$invalid' (choose from 'all', 'colors', 'format', 'none') | ||
For more information try with --help or visit the https://pie.co/docs | ||
""" | ||
|
||
|
||
PREDEFINED_TERMINAL_SIZE = (160, 80) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def ignore_terminal_size(monkeypatch): | ||
"""Some tests wrap/crop the output depending on the | ||
size of the executed terminal, which might not be consistent | ||
through all runs. | ||
This fixture ensures every run uses the same exact configuration. | ||
""" | ||
|
||
def fake_terminal_size(*args, **kwargs): | ||
return os.terminal_size(PREDEFINED_TERMINAL_SIZE) | ||
|
||
monkeypatch.setattr(shutil, "get_terminal_size", fake_terminal_size) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args, expected_msg", [ | ||
([], NAKED_HELP_MESSAGE), | ||
(["--pretty"], NAKED_HELP_MESSAGE_PRETTY_WITH_NO_ARG), | ||
(["pie.dev", "--pretty"], NAKED_HELP_MESSAGE_PRETTY_WITH_NO_ARG), | ||
(["--pretty", "$invalid"], NAKED_HELP_MESSAGE_PRETTY_WITH_INVALID_ARG), | ||
] | ||
) | ||
def test_naked_invocation(ignore_terminal_size, args, expected_msg): | ||
result = http(*args, tolerate_error_exit_status=True) | ||
assert result.stderr == expected_msg |