1
0
mirror of https://github.com/httpie/cli.git synced 2026-04-24 19:53:55 +02:00

Rework __main__.py to follow best practices (#1124)

It also simplifies how the `main()` function could be tested.
This commit is contained in:
Mickaël Schoentgen
2021-08-06 16:57:19 +02:00
committed by GitHub
parent c50e287c57
commit 4ff22defe4
2 changed files with 6 additions and 10 deletions
+2 -6
View File
@@ -17,18 +17,14 @@ from .utils import HTTP_OK, MockEnvironment, StdinBytesIO, http
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
assert httpie.__main__.main() == ExitStatus.ERROR.value
@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
assert httpie.__main__.main() == ExitStatus.ERROR_CTRL_C.value
def test_debug():