diff --git a/tests/test_cli_ui.py b/tests/test_cli_ui.py index 658b7ea42b..e31a00ab3c 100644 --- a/tests/test_cli_ui.py +++ b/tests/test_cli_ui.py @@ -1,11 +1,19 @@ 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 @@ -13,9 +21,9 @@ 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 @@ -23,9 +31,9 @@ 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') @@ -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):