<s> import mock <EOL> from pytest import raises <EOL> from requests import Request , Timeout <EOL> from requests . exceptions import ConnectionError <EOL> from httpie import ExitStatus <EOL> from httpie . core import main <EOL> error_msg = None <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_error ( get_response ) : <EOL> def error ( msg , * args , ** kwargs ) : <EOL> global error_msg <EOL> error_msg = msg % args <EOL> exc = ConnectionError ( '<STR_LIT>' ) <EOL> exc . request = Request ( method = '<STR_LIT:GET>' , url = '<STR_LIT>' ) <EOL> get_response . side_effect = exc <EOL> ret = main ( [ '<STR_LIT>' , '<STR_LIT>' ] , custom_log_error = error ) <EOL> assert ret == ExitStatus . ERROR <EOL> assert error_msg == ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_error_traceback ( get_response ) : <EOL> exc = ConnectionError ( '<STR_LIT>' ) <EOL> exc . request = Request ( method = '<STR_LIT:GET>' , url = '<STR_LIT>' ) <EOL> get_response . side_effect = exc <EOL> with raises ( ConnectionError ) : <EOL> main ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_timeout ( get_response ) : <EOL> def error ( msg , * args , ** kwargs ) : <EOL> global error_msg <EOL> error_msg = msg % args <EOL> exc = Timeout ( '<STR_LIT>' ) <EOL> exc . request = Request ( method = '<STR_LIT:GET>' , url = '<STR_LIT>' ) <EOL> get_response . side_effect = exc <EOL> ret = main ( [ '<STR_LIT>' , '<STR_LIT>' ] , custom_log_error = error ) <EOL> assert ret == ExitStatus . ERROR_TIMEOUT <EOL> assert error_msg == '<STR_LIT>' </s>
