def test_api_error_version_mismatch(self, mock_logging): with pytest.raises(errors.ConnectionError): with handle_connection_errors(mock.Mock(api_version='1.22')): raise APIError(None, None, b"client is newer than server") _, args, _ = mock_logging.error.mock_calls[0] assert "Docker Engine of version 1.10.0 or greater" in args[0]
def test_api_error_version_other(self, mock_logging): msg = b"Something broke!" with pytest.raises(errors.ConnectionError): with handle_connection_errors(mock.Mock(api_version='1.22')): raise APIError(None, None, msg) mock_logging.error.assert_called_once_with(msg)
def test_windows_pipe_error_no_data(self, mock_logging): import pywintypes with pytest.raises(errors.ConnectionError): with handle_connection_errors(mock.Mock(api_version='1.22')): raise pywintypes.error(232, 'WriteFile', 'The pipe is being closed.') _, args, _ = mock_logging.error.mock_calls[0] assert "The current Compose file version is not compatible with your engine version." in args[0]
def test_windows_pipe_error_encoding_issue(self, mock_logging): import pywintypes with pytest.raises(errors.ConnectionError): with handle_connection_errors(mock.Mock(api_version='1.22')): raise pywintypes.error(9999, 'WriteFile', 'I use weird characters \xe9') _, args, _ = mock_logging.error.mock_calls[0] assert 'Windows named pipe error: I use weird characters \xe9 (code: 9999)' == args[0]
def test_windows_pipe_error_misc(self, mock_logging): import pywintypes with pytest.raises(errors.ConnectionError): with handle_connection_errors(mock.Mock(api_version='1.22')): raise pywintypes.error(231, 'WriteFile', 'The pipe is busy.') _, args, _ = mock_logging.error.mock_calls[0] assert "Windows named pipe error: The pipe is busy. (code: 231)" == args[0]
def test_generic_connection_error(self, mock_logging): with pytest.raises(errors.ConnectionError): with patch_find_executable(['/bin/docker', None]): with handle_connection_errors(mock.Mock()): raise ConnectionError() _, args, _ = mock_logging.error.mock_calls[0] assert "Couldn't connect to Docker daemon" in args[0]
def test_generic_connection_error(self, mock_logging): with pytest.raises(errors.ConnectionError): with patch_call_silently([0, 1]): with handle_connection_errors(mock.Mock()): raise ConnectionError() _, args, _ = mock_logging.error.mock_calls[0] assert "Couldn't connect to Docker daemon at" in args[0]
def perform_command(options, handler, command_options): if options['COMMAND'] in ('help', 'version'): # Skip looking up the compose file. handler(command_options).run() return project = project_from_options('.', options) command = handler(project=project, options=command_options) with errors.handle_connection_errors(project.client): command.run()
def test_windows_pipe_error_encoding_issue(self, mock_logging): import pywintypes with pytest.raises(errors.ConnectionError): with handle_connection_errors(mock.Mock(api_version='1.22')): raise pywintypes.error(9999, 'WriteFile', 'I use weird characters \xe9') _, args, _ = mock_logging.error.mock_calls[0] assert 'Windows named pipe error: I use weird characters \xe9 (code: 9999)' == args[ 0]
def test_custom_timeout_error(self): os.environ['COMPOSE_HTTP_TIMEOUT'] = '123' client = docker_client(os.environ, version=DEFAULT_DOCKER_API_VERSION) with mock.patch('compose.cli.errors.log') as fake_log: with pytest.raises(errors.ConnectionError): with errors.handle_connection_errors(client): raise errors.RequestsConnectionError( errors.ReadTimeoutError(None, None, None)) assert fake_log.error.call_count == 1 assert '123' in fake_log.error.call_args[0][0] with mock.patch('compose.cli.errors.log') as fake_log: with pytest.raises(errors.ConnectionError): with errors.handle_connection_errors(client): raise errors.ReadTimeout() assert fake_log.error.call_count == 1 assert '123' in fake_log.error.call_args[0][0]
def test_custom_timeout_error(self): os.environ['COMPOSE_HTTP_TIMEOUT'] = '123' client = docker_client(os.environ) with mock.patch('compose.cli.errors.log') as fake_log: with pytest.raises(errors.ConnectionError): with errors.handle_connection_errors(client): raise errors.RequestsConnectionError( errors.ReadTimeoutError(None, None, None)) assert fake_log.error.call_count == 1 assert '123' in fake_log.error.call_args[0][0] with mock.patch('compose.cli.errors.log') as fake_log: with pytest.raises(errors.ConnectionError): with errors.handle_connection_errors(client): raise errors.ReadTimeout() assert fake_log.error.call_count == 1 assert '123' in fake_log.error.call_args[0][0]
def perform_command(options, handler, command_options, base_dir): if options['COMMAND'] in ('help', 'version'): # Skip looking up the compose file. handler(command_options) return if options['COMMAND'] == 'config': command = TopLevelCommand(None) handler(command, options, command_options) return #project = project_from_options('.', options) project = project_from_options(base_dir, options) command = TopLevelCommand(project) with errors.handle_connection_errors(project.client): return handler(command, command_options)