Skip to content

Commit

Permalink
Set COLUMNS to the PREDEFINED_TERMINAL_SIZE for 3.7 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical committed Feb 21, 2022
1 parent d14e054 commit 9e80206
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions tests/test_cli_ui.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
import pytest
import shutil
import os
import sys
from tests.utils import http

NAKED_HELP_MESSAGE = """\

if sys.version_info >= (3, 9):
REQUEST_ITEM_MSG = "[REQUEST_ITEM ...]"
else:
REQUEST_ITEM_MSG = "[REQUEST_ITEM [REQUEST_ITEM ...]]"


NAKED_HELP_MESSAGE = f"""\
usage:
http [METHOD] URL [REQUEST_ITEM ...]
http [METHOD] URL {REQUEST_ITEM_MSG}
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 = """\
NAKED_HELP_MESSAGE_PRETTY_WITH_NO_ARG = f"""\
usage:
http [--pretty {all,colors,format,none}] [METHOD] URL [REQUEST_ITEM ...]
http [--pretty {{all,colors,format,none}}] [METHOD] URL {REQUEST_ITEM_MSG}
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 = """\
NAKED_HELP_MESSAGE_PRETTY_WITH_INVALID_ARG = f"""\
usage:
http [--pretty {all,colors,format,none}] [METHOD] URL [REQUEST_ITEM ...]
http [--pretty {{all,colors,format,none}}] [METHOD] URL {REQUEST_ITEM_MSG}
error:
argument --pretty: invalid choice: '$invalid' (choose from 'all', 'colors', 'format', 'none')
Expand All @@ -49,15 +57,17 @@ def ignore_terminal_size(monkeypatch):
def fake_terminal_size(*args, **kwargs):
return os.terminal_size(PREDEFINED_TERMINAL_SIZE)

monkeypatch.setattr(shutil, "get_terminal_size", fake_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)


@pytest.mark.parametrize(
"args, expected_msg", [
'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),
(['--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):
Expand Down

0 comments on commit 9e80206

Please sign in to comment.