def _do_gather(self, context): self._ctx = VimUtilCtx(self.vim) parameters = {} parameters['wordToComplete'] = context['complete_str'] parameters['WantDocumentationForEveryCompletionResult'] = True response = getResponse(self._ctx, '/autocomplete', parameters, json=True) vim_completions = [] if response is not None: for completion in response: vim_completions.append({ 'word': completion['CompletionText'], 'menu': completion['DisplayText'], 'info': ((completion['Description'] or ' ').replace('\r\n', '\n')), 'dup': 1, }) return vim_completions
def test_get_bad_json_response(ctx, mocker): '''Malformed json response throws BadResponseError''' build_opener = mocker.patch('omnisharp.util.request.build_opener') expected_response = '{"foo": "bar"' if sys.version_info >= (3, 0): mocked_response = ('\xef\xbb\xbf' + expected_response).encode('utf-8') else: mocked_response = '\xef\xbb\xbf' + expected_response build_opener \ .return_value.open \ .return_value.read \ .return_value = mocked_response with pytest.raises(BadResponseError): getResponse(ctx, "http://my_endpoint", json=True)
def test_get_bad_json_response(ctx, mocker): '''Malformed json response throws BadResponseError''' build_opener = mocker.patch('omnisharp.util.request.build_opener') expected_response = '{"foo": "bar"' if sys.version_info >= (3, 0): mocked_response = ( '\xef\xbb\xbf' + expected_response).encode('utf-8') else: mocked_response = '\xef\xbb\xbf' + expected_response build_opener \ .return_value.open \ .return_value.read \ .return_value = mocked_response with pytest.raises(BadResponseError): getResponse(ctx, "http://my_endpoint", json=True)
def do_codecheck(logger, filename, host, cwd, translate, delimiter): ctx = UtilCtx( buffer_name=filename, translate_cygwin_wsl=translate, cwd=cwd, timeout=4, host=host, buffer=''.join(sys.stdin), ) response = getResponse(ctx, '/codecheck', json=True) quickfixes = quickfixes_from_response(ctx, response['QuickFixes']) keys = ['filename', 'lnum', 'col', 'type', 'subtype', 'text'] for item in quickfixes: print(delimiter.join([str(item.get(k, '')) for k in keys]))
def test_get_json_response_mocked_server(ctx, mocker): '''Test that we can get a response the server''' build_opener = mocker.patch('omnisharp.util.request.build_opener') expected_response = '{"foo": "bar"}' if sys.version_info >= (3, 0): mocked_response = ('\xef\xbb\xbf' + expected_response).encode('utf-8') else: mocked_response = '\xef\xbb\xbf' + expected_response build_opener \ .return_value.open \ .return_value.read \ .return_value = mocked_response response = getResponse(ctx, "http://my_endpoint", json=True) assert {'foo': 'bar'} == response
def test_get_response_mocked_server(ctx, mocker): '''Test that we can get a response the server''' build_opener = mocker.patch('omnisharp.util.request.build_opener') expected_response = 'Mocked response with UTF-8 BOM' if sys.version_info >= (3, 0): mocked_response = ('\xef\xbb\xbf' + expected_response).encode('utf-8') else: mocked_response = '\xef\xbb\xbf' + expected_response build_opener \ .return_value.open \ .return_value.read \ .return_value = mocked_response response = getResponse(ctx, "http://my_endpoint") assert expected_response == response
def test_get_json_response_mocked_server(ctx, mocker): '''Test that we can get a response the server''' build_opener = mocker.patch('omnisharp.util.request.build_opener') expected_response = '{"foo": "bar"}' if sys.version_info >= (3, 0): mocked_response = ( '\xef\xbb\xbf' + expected_response).encode('utf-8') else: mocked_response = '\xef\xbb\xbf' + expected_response build_opener \ .return_value.open \ .return_value.read \ .return_value = mocked_response response = getResponse(ctx, "http://my_endpoint", json=True) assert {'foo': 'bar'} == response
def test_get_response_mocked_server(ctx, mocker): '''Test that we can get a response the server''' build_opener = mocker.patch('omnisharp.util.request.build_opener') expected_response = 'Mocked response with UTF-8 BOM' if sys.version_info >= (3, 0): mocked_response = ( '\xef\xbb\xbf' + expected_response).encode('utf-8') else: mocked_response = '\xef\xbb\xbf' + expected_response build_opener \ .return_value.open \ .return_value.read \ .return_value = mocked_response response = getResponse(ctx, "http://my_endpoint") assert expected_response == response
def do_codecheck(logger, filename, host, cwd, translate, delimiter, encoding): ctx = UtilCtx( buffer_name=filename, translate_cygwin_wsl=translate, cwd=cwd, timeout=4, host=host, buffer=''.join(sys.stdin), ) response = getResponse(ctx, '/codecheck', json=True) quickfixes = quickfixes_from_response(ctx, response['QuickFixes']) keys = ['filename', 'lnum', 'col', 'type', 'subtype', 'text'] for item in quickfixes: s = delimiter.join([str(item.get(k, '')) for k in keys]) + '\n' if sys.version_info.major == 3: sys.stdout.buffer.write(s.encode(encoding)) elif sys.version_info.major == 2: sys.stdout.write(unicode(s).encode(encoding))
def _do_gather(self, context): self._ctx = VimUtilCtx(self.vim) parameters = {} parameters['wordToComplete'] = context['complete_str'] parameters['WantDocumentationForEveryCompletionResult'] = True response = getResponse(self._ctx, '/autocomplete', parameters, json=True) vim_completions = [] if response is not None: for completion in response: vim_completions.append({ 'word': completion['CompletionText'], 'menu': completion['DisplayText'], 'info': ((completion['Description'] or ' ') .replace('\r\n', '\n')), 'dup': 1, }) return vim_completions
def test_get_response_no_server(ctx): '''Test that the getResponse throws when there is no server''' port = find_free_port() with pytest.raises(ServerConnectionError): getResponse(ctx, "http://localhost:%d" % port)