def DetailedInfoTest(command, info):
     with patch(
             'ycm.vimsupport.WriteToPreviewWindow') as write_to_preview:
         request = CommandRequest([command])
         request._response = {'detailed_info': info}
         request.RunPostCommandActionsIfNeeded('topleft')
         write_to_preview.assert_called_with(info)
 def GoToTest(command, response):
     with patch('ycm.vimsupport.JumpToLocation') as jump_to_location:
         request = CommandRequest([command])
         request._response = response
         request.RunPostCommandActionsIfNeeded()
         jump_to_location.assert_called_with(response['filepath'],
                                             response['line_num'],
                                             response['column_num'])
    def FixItTest( command, response, chunks ):
      with patch( 'ycm.vimsupport.ReplaceChunks' ) as replace_chunks:
        with patch( 'ycm.vimsupport.EchoText' ) as echo_text:
          request = CommandRequest( [ command ] )
          request._response = response
          request.RunPostCommandActionsIfNeeded()

          replace_chunks.assert_called_with( chunks )
          echo_text.assert_not_called()
 def GoToTest( command, response ):
   with patch( 'ycm.vimsupport.JumpToLocation' ) as jump_to_location:
     request = CommandRequest( [ command ] )
     request._response = response
     request.RunPostCommandActionsIfNeeded()
     jump_to_location.assert_called_with(
         response[ 'filepath' ],
         response[ 'line_num' ],
         response[ 'column_num' ] )
        def FixItTest(command, response, chunks):
            with patch('ycm.vimsupport.ReplaceChunks') as replace_chunks:
                with patch('ycm.vimsupport.EchoText') as echo_text:
                    request = CommandRequest([command])
                    request._response = response
                    request.RunPostCommandActionsIfNeeded()

                    replace_chunks.assert_called_with(chunks)
                    echo_text.assert_not_called()
 def GoToListTest(command, response):
     # Note: the detail of these called are tested by
     # GoToResponse_QuickFix_test, so here we just check that the right call is
     # made
     with patch('ycm.vimsupport.SetQuickFixList') as set_qf_list:
         request = CommandRequest([command])
         request._response = response
         request.RunPostCommandActionsIfNeeded()
         ok_(set_qf_list.called)
 def GoToListTest( command, response ):
   # Note: the detail of these called are tested by
   # GoToResponse_QuickFix_test, so here we just check that the right call is
   # made
   with patch( 'ycm.vimsupport.SetQuickFixList' ) as set_qf_list:
     request = CommandRequest( [ command ] )
     request._response = response
     request.RunPostCommandActionsIfNeeded()
     ok_( set_qf_list.called )
        def EmptyFixItTest(command):
            with patch("ycm.vimsupport.ReplaceChunks") as replace_chunks:
                with patch("ycm.vimsupport.EchoText") as echo_text:
                    request = CommandRequest([command])
                    request._response = {"fixits": []}
                    request.RunPostCommandActionsIfNeeded()

                    echo_text.assert_called_with("No fixits found for current line")
                    replace_chunks.assert_not_called()
        def EmptyFixItTest(command):
            with patch('ycm.vimsupport.ReplaceChunks') as replace_chunks:
                with patch('ycm.vimsupport.EchoText') as echo_text:
                    request = CommandRequest([command])
                    request._response = {'fixits': []}
                    request.RunPostCommandActionsIfNeeded()

                    echo_text.assert_called_with(
                        'No fixits found for current line')
                    replace_chunks.assert_not_called()
    def FixItTest( command, response, chunks, selection ):
      with patch( 'ycm.vimsupport.ReplaceChunks' ) as replace_chunks:
        with patch( 'ycm.vimsupport.PostVimMessage' ) as post_vim_message:
          with patch( 'ycm.vimsupport.SelectFromList',
                      return_value = selection ):
            request = CommandRequest( [ command ] )
            request._response = response
            request.RunPostCommandActionsIfNeeded()

            replace_chunks.assert_called_with( chunks )
            post_vim_message.assert_not_called()
Example #11
0
    def FixItTest( command, response, chunks, selection, silent ):
      with patch( 'ycm.vimsupport.ReplaceChunks' ) as replace_chunks:
        with patch( 'ycm.vimsupport.PostVimMessage' ) as post_vim_message:
          with patch( 'ycm.vimsupport.SelectFromList',
                      return_value = selection ):
            request = CommandRequest( [ command ] )
            request._response = response
            request.RunPostCommandActionsIfNeeded( 'leftabove' )

            replace_chunks.assert_called_with( chunks, silent = silent )
            post_vim_message.assert_not_called()
        def EmptyFixItTest(command):
            with patch('ycm.vimsupport.ReplaceChunks') as replace_chunks:
                with patch(
                        'ycm.vimsupport.PostVimMessage') as post_vim_message:
                    request = CommandRequest([command])
                    request._response = {'fixits': []}
                    request.RunPostCommandActionsIfNeeded('botright')

                    post_vim_message.assert_called_with(
                        'No fixits found for current line', warning=False)
                    replace_chunks.assert_not_called()
    def EmptyFixItTest( command ):
      with patch( 'ycm.vimsupport.ReplaceChunks' ) as replace_chunks:
        with patch( 'ycm.vimsupport.PostVimMessage' ) as post_vim_message:
          request = CommandRequest( [ command ] )
          request._response = {
            'fixits': []
          }
          request.RunPostCommandActionsIfNeeded()

          post_vim_message.assert_called_with(
            'No fixits found for current line', warning = False )
          replace_chunks.assert_not_called()
class GoToResponse_QuickFix_test:
    """This class tests the generation of QuickFix lists for GoTo responses which
  return multiple locations, such as the Python completer and JavaScript
  completer. It mostly proves that we use 1-based indexing for the column
  number."""
    def setUp(self):
        self._request = CommandRequest(['GoToTest'])

    def tearDown(self):
        self._request = None

    def GoTo_EmptyList_test(self):
        self._CheckGoToList([], [])

    def GoTo_SingleItem_List_test(self):
        self._CheckGoToList([{
            'filepath': 'dummy_file',
            'line_num': 10,
            'column_num': 1,
            'description': 'this is some text',
        }], [{
            'filename': 'dummy_file',
            'text': 'this is some text',
            'lnum': 10,
            'col': 1
        }])

    def GoTo_MultiItem_List_test(self):
        self._CheckGoToList([{
            'filepath': 'dummy_file',
            'line_num': 10,
            'column_num': 1,
            'description': 'this is some other text',
        }, {
            'filepath': 'dummy_file2',
            'line_num': 1,
            'column_num': 21,
            'description': 'this is some text',
        }], [{
            'filename': 'dummy_file',
            'text': 'this is some other text',
            'lnum': 10,
            'col': 1
        }, {
            'filename': 'dummy_file2',
            'text': 'this is some text',
            'lnum': 1,
            'col': 21
        }])

    @patch('vim.eval')
    def _CheckGoToList(self, completer_response, expected_qf_list, vim_eval):
        self._request._response = completer_response

        self._request.RunPostCommandActionsIfNeeded()

        vim_eval.assert_has_calls([
            call('setqflist( {0} )'.format(json.dumps(expected_qf_list))),
            call('youcompleteme#OpenGoToList()'),
        ])
 def setup_method(self):
     self._request = CommandRequest(['GoToTest'])
class GoToResponse_QuickFix_test:
    """This class tests the generation of QuickFix lists for GoTo responses which
  return multiple locations, such as the Python completer and JavaScript
  completer. It mostly proves that we use 1-based indexing for the column
  number."""
    def setup_method(self):
        self._request = CommandRequest(['GoToTest'])

    def teardown_method(self):
        self._request = None

    def GoTo_EmptyList_test(self):
        self._CheckGoToList([], [])

    def GoTo_SingleItem_List_test(self):
        self._CheckGoToList([{
            'filepath': 'dummy_file',
            'line_num': 10,
            'column_num': 1,
            'description': 'this is some text',
        }], [{
            'filename': 'dummy_file',
            'text': 'this is some text',
            'lnum': 10,
            'col': 1
        }])

    def GoTo_MultiItem_List_test(self):
        self._CheckGoToList([{
            'filepath': 'dummy_file',
            'line_num': 10,
            'column_num': 1,
            'description': 'this is some other text',
        }, {
            'filepath': 'dummy_file2',
            'line_num': 1,
            'column_num': 21,
            'description': 'this is some text',
        }], [{
            'filename': 'dummy_file',
            'text': 'this is some other text',
            'lnum': 10,
            'col': 1
        }, {
            'filename': 'dummy_file2',
            'text': 'this is some text',
            'lnum': 1,
            'col': 21
        }])

    @patch('ycm.vimsupport.VariableExists', return_value=True)
    @patch('ycm.vimsupport.SetFittingHeightForCurrentWindow')
    @patch('vim.command', new_callable=ExtendedMock)
    @patch('vim.eval', new_callable=ExtendedMock)
    def _CheckGoToList(self, completer_response, expected_qf_list, vim_eval,
                       vim_command, set_fitting_height, variable_exists):
        self._request._response = completer_response

        self._request.RunPostCommandActionsIfNeeded('aboveleft')

        vim_eval.assert_has_exact_calls(
            [call('setqflist( {0} )'.format(json.dumps(expected_qf_list)))])
        vim_command.assert_has_exact_calls([
            call('botright copen'),
            call('augroup ycmquickfix'),
            call('autocmd! * <buffer>'),
            call('autocmd WinLeave <buffer> '
                 'if bufnr( "%" ) == expand( "<abuf>" ) | q | endif '
                 '| autocmd! ycmquickfix'),
            call('augroup END'),
            call('doautocmd User YcmQuickFixOpened')
        ])
        set_fitting_height.assert_called_once_with()
 def MessageTest(command, message):
     with patch('ycm.vimsupport.PostVimMessage') as post_vim_message:
         request = CommandRequest([command])
         request._response = {'message': message}
         request.RunPostCommandActionsIfNeeded('rightbelow')
         post_vim_message.assert_called_with(message, warning=False)
 def _BasicResponseTest(command, response):
     with patch('vim.command') as vim_command:
         request = CommandRequest([command])
         request._response = response
         request.RunPostCommandActionsIfNeeded('belowright')
         vim_command.assert_called_with("echo '{0}'".format(response))
 def MessageTest( command, message ):
   with patch( 'ycm.vimsupport.PostVimMessage' ) as post_vim_message:
     request = CommandRequest( [ command ] )
     request._response = { 'message': message }
     request.RunPostCommandActionsIfNeeded()
     post_vim_message.assert_called_with( message, warning = False )
 def MessageTest(command, message):
     with patch('ycm.vimsupport.EchoText') as echo_text:
         request = CommandRequest([command])
         request._response = {'message': message}
         request.RunPostCommandActionsIfNeeded()
         echo_text.assert_called_with(message)
 def DetailedInfoTest( command, info ):
   with patch( 'ycm.vimsupport.WriteToPreviewWindow' ) as write_to_preview:
     request = CommandRequest( [ command ] )
     request._response = { 'detailed_info': info }
     request.RunPostCommandActionsIfNeeded()
     write_to_preview.assert_called_with( info )
 def MessageTest( command, message ):
   with patch( 'ycm.vimsupport.EchoText' ) as echo_text:
     request = CommandRequest( [ command ] )
     request._response = { 'message': message }
     request.RunPostCommandActionsIfNeeded()
     echo_text.assert_called_with( message )
 def _BasicResponseTest( command, response ):
   with patch( 'vim.command' ) as vim_command:
     request = CommandRequest( [ command ] )
     request._response = response
     request.RunPostCommandActionsIfNeeded()
     vim_command.assert_called_with( "echom '{0}'".format( response ) )
 def setUp(self):
     self._request = CommandRequest(['GoToTest'])