mirror of
https://github.com/httpie/cli.git
synced 2024-11-21 17:16:30 +02:00
ff6f1887b0
* Refactor tests to use a text-based standard output. (#1318) * Implement new style `--help` (#1316) * Implement man page generation (#1317) * Implement rich progress bars. (#1324) * Man page deployment & isolation. (#1325) * Remove all unsorted usages in the CLI docs * Implement isolated mode for man page generation * Add a CI job for autogenerated files * Distribute man pages through PyPI * Pin the date for man pages. (#1326) * Hide suppressed arguments from --help/man pages (#1329) * Change download spinner to line (#1328) * Regenerate autogenerated files when pushed against to master. (#1339) * Highlight options (#1340) * Additional man page enhancements (#1341) * Group options by the parent category & highlight -o/--o * Display (and underline) the METAVAR on man pages. * Make help message processing more robust (#1342) * Inherit `help` from `short_help` * Don't mirror short_help directly. * Fixup the serialization * Use `pager` and `man` on `--manual` when applicable (#1343) * Run `man $program` on --manual * Page the output of `--manual` for systems that lack man pages * Improvements over progress bars (separate bar, status line, etc.) (#1346) * Redesign the --help layout. * Make our usage of rich compatible with 9.10.0 * Add `HTTPIE_NO_MAN_PAGES` * Make tests also patch os.get_terminal_size * Generate CLI spec from HTTPie & Man Page Hook (#1354) * Generate CLI spec from HTTPie & add man page hook * Use the full command space for the option headers
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
import pytest
|
|
import shutil
|
|
import os
|
|
from tests.utils import http
|
|
|
|
NAKED_BASE_TEMPLATE = """\
|
|
usage:
|
|
http {extra_args}[METHOD] URL [REQUEST_ITEM ...]
|
|
|
|
error:
|
|
{error_msg}
|
|
|
|
for more information:
|
|
run 'http --help' or visit https://httpie.io/docs/cli
|
|
|
|
"""
|
|
|
|
NAKED_HELP_MESSAGE = NAKED_BASE_TEMPLATE.format(
|
|
extra_args="",
|
|
error_msg="the following arguments are required: URL"
|
|
)
|
|
|
|
NAKED_HELP_MESSAGE_PRETTY_WITH_NO_ARG = NAKED_BASE_TEMPLATE.format(
|
|
extra_args="--pretty {all, colors, format, none} ",
|
|
error_msg="argument --pretty: expected one argument"
|
|
)
|
|
|
|
NAKED_HELP_MESSAGE_PRETTY_WITH_INVALID_ARG = NAKED_BASE_TEMPLATE.format(
|
|
extra_args="--pretty {all, colors, format, none} ",
|
|
error_msg="argument --pretty: invalid choice: '$invalid' (choose from 'all', 'colors', 'format', 'none')"
|
|
)
|
|
|
|
|
|
PREDEFINED_TERMINAL_SIZE = (200, 100)
|
|
|
|
|
|
@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)
|
|
|
|
# Setting COLUMNS as an env var is required for 3.8<
|
|
monkeypatch.setitem(os.environ, 'COLUMNS', str(PREDEFINED_TERMINAL_SIZE[0]))
|
|
monkeypatch.setattr(shutil, 'get_terminal_size', fake_terminal_size)
|
|
monkeypatch.setattr(os, '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
|