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

Function MockEventNotification

python/ycm/tests/event_notification_test.py:58–85  ·  view source on GitHub ↗

Mock out the EventNotification client request object, replacing the Response handler's JsonFromFuture with the supplied |response_method|. Additionally mock out YouCompleteMe's FiletypeCompleterExistsForFiletype method to return the supplied |native_filetype_completer| parameter, rather than

( response_method, native_filetype_completer = True )

Source from the content-addressed store, hash-verified

56
57@contextlib.contextmanager
58def MockEventNotification( response_method, native_filetype_completer = True ):
59 """Mock out the EventNotification client request object, replacing the
60 Response handler's JsonFromFuture with the supplied |response_method|.
61 Additionally mock out YouCompleteMe's FiletypeCompleterExistsForFiletype
62 method to return the supplied |native_filetype_completer| parameter, rather
63 than querying the server"""
64
65 # We don't want the event to actually be sent to the server, just have it
66 # return success
67 with patch( 'ycm.client.event_notification.EventNotification.'
68 'PostDataToHandlerAsync',
69 return_value = MagicMock( return_value=True ) ):
70
71 # We set up a fake a Response (as called by EventNotification.Response)
72 # which calls the supplied callback method. Generally this callback just
73 # raises an apropriate exception, otherwise it would have to return a mock
74 # future object.
75 with patch( 'ycm.client.base_request._JsonFromFuture',
76 side_effect = response_method ):
77
78 # Filetype available information comes from the server, so rather than
79 # relying on that request, we mock out the check. The caller decides if
80 # filetype completion is available
81 with patch(
82 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
83 return_value = native_filetype_completer ):
84
85 yield
86
87
88def _Check_FileReadyToParse_Diagnostic_Error( ycm ):

Calls

no outgoing calls

Tested by

no test coverage detected