MCPcopy Create free account
hub / github.com/ycm-core/YouCompleteMe / MockAsyncServerResponseException

Function MockAsyncServerResponseException

python/ycm/tests/mock_utils.py:96–109  ·  view source on GitHub ↗

Return a fake future object that is complete, but raises an exception. Suitable for mocking a response future within a client request. For example: with MockVimBuffers( [ current_buffer ], [ current_buffer ], ( 1, 1 ) ) as v: mock_response = MockAsyncServerResponseException( exception )

( exception )

Source from the content-addressed store, hash-verified

94
95
96def MockAsyncServerResponseException( exception ):
97 """Return a fake future object that is complete, but raises an exception.
98 Suitable for mocking a response future within a client request. For example:
99
100 with MockVimBuffers( [ current_buffer ], [ current_buffer ], ( 1, 1 ) ) as v:
101 mock_response = MockAsyncServerResponseException( exception )
102 with patch.dict( ycm._message_poll_requests, {} ):
103 ycm._message_poll_requests[ filetype ] = MessagesPoll( v.current.buffer )
104 ycm._message_poll_requests[ filetype ]._response_future = mock_response
105 # Needed to keep a reference to the mocked dictionary
106 mock_future = ycm._message_poll_requests[ filetype ]._response_future
107 ycm.OnPeriodicTick() # Uses ycm._message_poll_requests[ filetype ] ...
108 """
109 return mock.MagicMock( wraps = FakeFuture( True, None, exception ) )
110
111
112# TODO: In future, implement MockServerResponse and MockServerResponseException

Calls 1

FakeFutureClass · 0.85