Mock out the CompletionRequest, replacing the response handler JsonFromFuture with the |response_method| parameter.
( response_method )
| 36 | |
| 37 | @contextlib.contextmanager |
| 38 | def MockCompletionRequest( response_method ): |
| 39 | """Mock out the CompletionRequest, replacing the response handler |
| 40 | JsonFromFuture with the |response_method| parameter.""" |
| 41 | |
| 42 | # We don't want the requests to actually be sent to the server, just have it |
| 43 | # return success. |
| 44 | with patch( 'ycm.client.completer_available_request.' |
| 45 | 'CompleterAvailableRequest.PostDataToHandler', |
| 46 | return_value = True ): |
| 47 | with patch( 'ycm.client.completion_request.CompletionRequest.' |
| 48 | 'PostDataToHandlerAsync', |
| 49 | return_value = MagicMock( return_value=True ) ): |
| 50 | |
| 51 | # We set up a fake response. |
| 52 | with patch( 'ycm.client.base_request._JsonFromFuture', |
| 53 | side_effect = response_method ): |
| 54 | yield |
| 55 | |
| 56 | |
| 57 | @contextlib.contextmanager |
no outgoing calls
no test coverage detected