mirror of
https://github.com/httpie/cli.git
synced 2024-11-07 16:34:35 +01:00
Improved failed test output
This commit is contained in:
parent
564670566c
commit
66e168b2af
@ -12,12 +12,12 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
|
||||
* Added ``Content-Type`` of files uploaded in ``multipart/form-data`` requests
|
||||
* Added ``--ssl=<PROTOCOL>`` to specify the desired SSL/TLS protocol version
|
||||
to use for HTTPS requests.
|
||||
* Added JSON detection with ``--json, -j`` to work around incorrect
|
||||
``Content-Type``
|
||||
* Added ``--show-redirects, -R`` to show intermediate responses with ``--follow``
|
||||
* Added ``--max-redirects`` (default 30)
|
||||
* Added ``-A`` as short name for ``--auth-type``
|
||||
* Added ``-F`` as short name for ``--follow``
|
||||
* Added JSON detection with ``--json, -j`` to work around incorrect
|
||||
``Content-Type``
|
||||
* Redirected ``stdout`` doesn't trigger an error anymore when ``--output FILE``
|
||||
is set.
|
||||
* Changed the default ``--style`` back to ``solarized`` for better support
|
||||
|
@ -18,3 +18,10 @@ class ExitStatus:
|
||||
ERROR_HTTP_3XX = 3
|
||||
ERROR_HTTP_4XX = 4
|
||||
ERROR_HTTP_5XX = 5
|
||||
|
||||
|
||||
EXIT_STATUS_LABELS = dict(
|
||||
(value, key)
|
||||
for key, value in ExitStatus.__dict__.items()
|
||||
if key.isupper()
|
||||
)
|
||||
|
@ -1,3 +1,2 @@
|
||||
[pytest]
|
||||
addopts = --tb=native
|
||||
norecursedirs = tests/fixtures
|
||||
|
@ -6,7 +6,7 @@ import time
|
||||
import json
|
||||
import tempfile
|
||||
|
||||
import httpie
|
||||
from httpie import ExitStatus, EXIT_STATUS_LABELS
|
||||
from httpie.context import Environment
|
||||
from httpie.core import main
|
||||
from httpie.compat import bytes, str
|
||||
@ -135,6 +135,10 @@ class StrCLIResponse(str, BaseCLIResponse):
|
||||
return self._json
|
||||
|
||||
|
||||
class ExitStatusException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def http(*args, **kwargs):
|
||||
# noinspection PyUnresolvedReferences
|
||||
"""
|
||||
@ -205,7 +209,7 @@ def http(*args, **kwargs):
|
||||
time.sleep(.5)
|
||||
except SystemExit:
|
||||
if error_exit_ok:
|
||||
exit_status = httpie.ExitStatus.ERROR
|
||||
exit_status = ExitStatus.ERROR
|
||||
else:
|
||||
dump_stderr()
|
||||
raise
|
||||
@ -214,9 +218,15 @@ def http(*args, **kwargs):
|
||||
sys.stderr.write(stderr.read())
|
||||
raise
|
||||
else:
|
||||
if exit_status != httpie.ExitStatus.OK and not error_exit_ok:
|
||||
if not error_exit_ok and exit_status != ExitStatus.OK:
|
||||
dump_stderr()
|
||||
raise Exception('Unexpected exit status: %s', exit_status)
|
||||
raise ExitStatusException(
|
||||
'httpie.core.main() unexpectedly returned'
|
||||
' a non-zero exit status: {0} ({1})'.format(
|
||||
exit_status,
|
||||
EXIT_STATUS_LABELS[exit_status]
|
||||
)
|
||||
)
|
||||
|
||||
stdout.seek(0)
|
||||
stderr.seek(0)
|
||||
@ -232,7 +242,7 @@ def http(*args, **kwargs):
|
||||
r.stderr = stderr.read()
|
||||
r.exit_status = exit_status
|
||||
|
||||
if r.exit_status != httpie.ExitStatus.OK:
|
||||
if r.exit_status != ExitStatus.OK:
|
||||
sys.stderr.write(r.stderr)
|
||||
|
||||
return r
|
||||
|
Loading…
Reference in New Issue
Block a user