diff --git a/tests/test_httpie.py b/tests/test_httpie.py index cd634c0c..252b0a17 100644 --- a/tests/test_httpie.py +++ b/tests/test_httpie.py @@ -1,6 +1,11 @@ """High-level tests.""" +import io +from unittest import mock + import pytest +import httpie.__main__ +from httpie.context import Environment from httpie.status import ExitStatus from httpie.cli.exceptions import ParseError from utils import MockEnvironment, http, HTTP_OK @@ -9,6 +14,23 @@ from fixtures import FILE_PATH, FILE_CONTENT import httpie +def test_main_entry_point(): + # Patch stdin to bypass pytest capture + with mock.patch.object(Environment, 'stdin', io.StringIO()): + with pytest.raises(SystemExit) as e: + httpie.__main__.main() + assert e.value.code == ExitStatus.ERROR + + +@mock.patch('httpie.core.main') +def test_main_entry_point_keyboard_interrupt(main): + main.side_effect = KeyboardInterrupt() + with mock.patch.object(Environment, 'stdin', io.StringIO()): + with pytest.raises(SystemExit) as e: + httpie.__main__.main() + assert e.value.code == ExitStatus.ERROR_CTRL_C + + def test_debug(): r = http('--debug') assert r.exit_status == ExitStatus.SUCCESS