mirror of
https://github.com/httpie/cli.git
synced 2024-11-24 16:53:35 +01:00
Rework __main__.py
to follow best practices (#1124)
It also simplifies how the `main()` function could be tested.
This commit is contained in:
parent
c50e287c57
commit
4ff22defe4
@ -1,7 +1,6 @@
|
|||||||
"""The main entry point. Invoke as `http' or `python -m httpie'.
|
"""The main entry point. Invoke as `http' or `python -m httpie'.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -12,8 +11,9 @@ def main():
|
|||||||
from httpie.status import ExitStatus
|
from httpie.status import ExitStatus
|
||||||
exit_status = ExitStatus.ERROR_CTRL_C
|
exit_status = ExitStatus.ERROR_CTRL_C
|
||||||
|
|
||||||
sys.exit(exit_status.value)
|
return exit_status.value
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__': # pragma: nocover
|
||||||
main()
|
import sys
|
||||||
|
sys.exit(main())
|
||||||
|
@ -17,18 +17,14 @@ from .utils import HTTP_OK, MockEnvironment, StdinBytesIO, http
|
|||||||
def test_main_entry_point():
|
def test_main_entry_point():
|
||||||
# Patch stdin to bypass pytest capture
|
# Patch stdin to bypass pytest capture
|
||||||
with mock.patch.object(Environment, 'stdin', io.StringIO()):
|
with mock.patch.object(Environment, 'stdin', io.StringIO()):
|
||||||
with pytest.raises(SystemExit) as e:
|
assert httpie.__main__.main() == ExitStatus.ERROR.value
|
||||||
httpie.__main__.main()
|
|
||||||
assert e.value.code == ExitStatus.ERROR
|
|
||||||
|
|
||||||
|
|
||||||
@mock.patch('httpie.core.main')
|
@mock.patch('httpie.core.main')
|
||||||
def test_main_entry_point_keyboard_interrupt(main):
|
def test_main_entry_point_keyboard_interrupt(main):
|
||||||
main.side_effect = KeyboardInterrupt()
|
main.side_effect = KeyboardInterrupt()
|
||||||
with mock.patch.object(Environment, 'stdin', io.StringIO()):
|
with mock.patch.object(Environment, 'stdin', io.StringIO()):
|
||||||
with pytest.raises(SystemExit) as e:
|
assert httpie.__main__.main() == ExitStatus.ERROR_CTRL_C.value
|
||||||
httpie.__main__.main()
|
|
||||||
assert e.value.code == ExitStatus.ERROR_CTRL_C
|
|
||||||
|
|
||||||
|
|
||||||
def test_debug():
|
def test_debug():
|
||||||
|
Loading…
Reference in New Issue
Block a user