diff --git a/httpie/__init__.py b/httpie/__init__.py index 0725cc15..f4b9b042 100644 --- a/httpie/__init__.py +++ b/httpie/__init__.py @@ -8,8 +8,8 @@ __licence__ = 'BSD' class ExitStatus: - """Exit status code constants.""" - OK = 0 + """Program exit code constants.""" + SUCCESS = 0 ERROR = 1 PLUGIN_ERROR = 7 diff --git a/httpie/core.py b/httpie/core.py index 8442d614..8ad0e2a6 100644 --- a/httpie/core.py +++ b/httpie/core.py @@ -43,7 +43,7 @@ def get_exit_status(http_status, follow=False): # Server Error return ExitStatus.ERROR_HTTP_5XX else: - return ExitStatus.OK + return ExitStatus.SUCCESS def print_debug_info(env): @@ -82,7 +82,7 @@ def program(args, env, log_error): :return: status code """ - exit_status = ExitStatus.OK + exit_status = ExitStatus.SUCCESS downloader = None show_traceback = args.debug or args.traceback @@ -109,7 +109,7 @@ def program(args, env, log_error): http_status=response.status_code, follow=args.follow ) - if not env.stdout_isatty and exit_status != ExitStatus.OK: + if not env.stdout_isatty and exit_status != ExitStatus.SUCCESS: log_error( 'HTTP %s %s', response.raw.status, response.raw.reason, level='warning' @@ -143,7 +143,7 @@ def program(args, env, log_error): else: raise - if downloader and exit_status == ExitStatus.OK: + if downloader and exit_status == ExitStatus.SUCCESS: # Last response body download. download_stream, download_to = downloader.start(final_response) write_stream( @@ -202,9 +202,9 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None): if include_debug_info: print_debug_info(env) if args == ['--debug']: - return ExitStatus.OK + return ExitStatus.SUCCESS - exit_status = ExitStatus.OK + exit_status = ExitStatus.SUCCESS try: parsed_args = parser.parse_args(args=args, env=env) @@ -214,7 +214,7 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None): raise exit_status = ExitStatus.ERROR_CTRL_C except SystemExit as e: - if e.code != ExitStatus.OK: + if e.code != ExitStatus.SUCCESS: env.stderr.write('\n') if include_traceback: raise @@ -232,7 +232,7 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None): raise exit_status = ExitStatus.ERROR_CTRL_C except SystemExit as e: - if e.code != ExitStatus.OK: + if e.code != ExitStatus.SUCCESS: env.stderr.write('\n') if include_traceback: raise diff --git a/tests/test_exit_status.py b/tests/test_exit_status.py index 119b8d12..02e9bd73 100644 --- a/tests/test_exit_status.py +++ b/tests/test_exit_status.py @@ -21,13 +21,13 @@ def test_keyboard_interrupt_in_program_exit_status(httpbin): def test_ok_response_exits_0(httpbin): r = http('GET', httpbin.url + '/get') assert HTTP_OK in r - assert r.exit_status == ExitStatus.OK + assert r.exit_status == ExitStatus.SUCCESS def test_error_response_exits_0_without_check_status(httpbin): r = http('GET', httpbin.url + '/status/500') - assert '500 INTERNAL SERVER ERRO' in r - assert r.exit_status == ExitStatus.OK + assert '500 INTERNAL SERVER ERROR' in r + assert r.exit_status == ExitStatus.SUCCESS assert not r.stderr @@ -55,7 +55,7 @@ def test_3xx_check_status_redirects_allowed_exits_0(httpbin): error_exit_ok=True) # The redirect will be followed so 200 is expected. assert HTTP_OK in r - assert r.exit_status == ExitStatus.OK + assert r.exit_status == ExitStatus.SUCCESS def test_4xx_check_status_exits_4(httpbin): diff --git a/tests/test_httpie.py b/tests/test_httpie.py index 5fb045b9..c6bf0019 100644 --- a/tests/test_httpie.py +++ b/tests/test_httpie.py @@ -10,19 +10,19 @@ import httpie def test_debug(): r = http('--debug') - assert r.exit_status == httpie.ExitStatus.OK + assert r.exit_status == httpie.ExitStatus.SUCCESS assert 'HTTPie %s' % httpie.__version__ in r.stderr def test_help(): r = http('--help', error_exit_ok=True) - assert r.exit_status == httpie.ExitStatus.OK + assert r.exit_status == httpie.ExitStatus.SUCCESS assert 'https://github.com/jakubroztocil/httpie/issues' in r def test_version(): r = http('--version', error_exit_ok=True) - assert r.exit_status == httpie.ExitStatus.OK + assert r.exit_status == httpie.ExitStatus.SUCCESS # FIXME: py3 has version in stdout, py2 in stderr assert httpie.__version__ == r.stderr.strip() + r.strip() diff --git a/tests/test_output.py b/tests/test_output.py index d57e891c..26cbae96 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -161,7 +161,7 @@ class TestLineEndings: def test_CRLF_formatted_response(self, httpbin): r = http('--pretty=format', 'GET', httpbin.url + '/get') - assert r.exit_status == ExitStatus.OK + assert r.exit_status == ExitStatus.SUCCESS self._validate_crlf(r) def test_CRLF_ugly_request(self, httpbin): diff --git a/tests/utils.py b/tests/utils.py index 0c31c966..c9b3575e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -219,7 +219,7 @@ def http(*args, **kwargs): sys.stderr.write(stderr.read()) raise else: - if not error_exit_ok and exit_status != ExitStatus.OK: + if not error_exit_ok and exit_status != ExitStatus.SUCCESS: dump_stderr() raise ExitStatusError( 'httpie.core.main() unexpectedly returned' @@ -243,7 +243,7 @@ def http(*args, **kwargs): r.stderr = stderr.read() r.exit_status = exit_status - if r.exit_status != ExitStatus.OK: + if r.exit_status != ExitStatus.SUCCESS: sys.stderr.write(r.stderr) return r