コード例 #1
0
def LanguageServerConnection_AddNotificationToQueue_RingBuffer_test():
    connection = MockConnection()
    notifications = connection._notifications

    # Queue empty

    assert_that(calling(notifications.get_nowait), raises(queue.Empty))

    # Queue partially full, then drained

    connection._AddNotificationToQueue('one')

    assert_that(notifications.get_nowait(), equal_to('one'))
    assert_that(calling(notifications.get_nowait), raises(queue.Empty))

    # Queue full, then drained

    connection._AddNotificationToQueue('one')
    connection._AddNotificationToQueue('two')

    assert_that(notifications.get_nowait(), equal_to('one'))
    assert_that(notifications.get_nowait(), equal_to('two'))
    assert_that(calling(notifications.get_nowait), raises(queue.Empty))

    # Queue full, then new notification, then drained

    connection._AddNotificationToQueue('one')
    connection._AddNotificationToQueue('two')
    connection._AddNotificationToQueue('three')

    assert_that(notifications.get_nowait(), equal_to('two'))
    assert_that(notifications.get_nowait(), equal_to('three'))
    assert_that(calling(notifications.get_nowait), raises(queue.Empty))
コード例 #2
0
def LanguageServerConnection_CloseTwice_test():
    connection = MockConnection()
    with patch.object(connection,
                      'TryServerConnectionBlocking',
                      side_effect=RuntimeError):
        connection.Close()
        connection.Close()
コード例 #3
0
def LanguageServerConnection_ServerConnectionDies_test():
    connection = MockConnection()

    return_values = [IOError]

    with patch.object(connection, 'ReadData', side_effect=return_values):
        # No exception is thrown
        connection.run()
コード例 #4
0
def LanguageServerConnection_ConnectionTimeout_test():
  connection = MockConnection()
  with patch.object( connection,
                     'TryServerConnectionBlocking',
                     side_effect=RuntimeError ):
    connection.Start()
    assert_that( calling( connection.AwaitServerConnection ),
                 raises( lsc.LanguageServerConnectionTimeout ) )

  assert_that( connection.isAlive(), equal_to( False ) )
コード例 #5
0
def LanguageServerConnection_ServerConnectionDies_test():
  connection = MockConnection()

  return_values = [
    IOError
  ]

  with patch.object( connection, 'ReadData', side_effect = return_values ):
    # No exception is thrown
    connection.run()
コード例 #6
0
def LanguageServerConnection_ConnectionTimeout_test():
    connection = MockConnection()
    with patch.object(connection,
                      'TryServerConnectionBlocking',
                      side_effect=RuntimeError):
        connection.Start()
        assert_that(calling(connection.AwaitServerConnection),
                    raises(lsc.LanguageServerConnectionTimeout))

    assert_that(connection.isAlive(), equal_to(False))
コード例 #7
0
def LanguageServerConnection_AddNotificationToQueue_RingBuffer_test():
  connection = MockConnection()
  notifications = connection._notifications

  # Queue empty

  assert_that( calling( notifications.get_nowait ), raises( queue.Empty ) )

  # Queue partially full, then drained

  connection._AddNotificationToQueue( 'one' )

  assert_that( notifications.get_nowait(), equal_to( 'one' ) )
  assert_that( calling( notifications.get_nowait ), raises( queue.Empty ) )

  # Queue full, then drained

  connection._AddNotificationToQueue( 'one' )
  connection._AddNotificationToQueue( 'two' )

  assert_that( notifications.get_nowait(), equal_to( 'one' ) )
  assert_that( notifications.get_nowait(), equal_to( 'two' ) )
  assert_that( calling( notifications.get_nowait ), raises( queue.Empty ) )

  # Queue full, then new notification, then drained

  connection._AddNotificationToQueue( 'one' )
  connection._AddNotificationToQueue( 'two' )
  connection._AddNotificationToQueue( 'three' )

  assert_that( notifications.get_nowait(), equal_to( 'two' ) )
  assert_that( notifications.get_nowait(), equal_to( 'three' ) )
  assert_that( calling( notifications.get_nowait ), raises( queue.Empty ) )
コード例 #8
0
def LanguageServerConnection_RequestAbortAwait_test():
    connection = MockConnection()

    return_values = [lsc.LanguageServerConnectionStopped]

    with patch.object(connection, 'ReadData', side_effect=return_values):
        response = connection.GetResponseAsync(1, bytes(b'{"test":"test"}'))
        connection.run()
        assert_that(
            calling(response.AwaitResponse).with_args(10),
            raises(lsc.ResponseAbortedException))
コード例 #9
0
def LanguageServerConnection_RequestAbortCallback_test():
    connection = MockConnection()

    return_values = [lsc.LanguageServerConnectionStopped]

    with patch.object(connection, 'ReadData', side_effect=return_values):
        callback = MagicMock()
        response = connection.GetResponseAsync(1,
                                               bytes(b'{"test":"test"}'),
                                               response_callback=callback)
        connection.run()
        callback.assert_called_with(response, None)
コード例 #10
0
def LanguageServerConnection_ReadPartialMessage_test():
    connection = MockConnection()

    return_values = [
        bytes(b'Content-Length: 10\n\n{"abc":'),
        bytes(b'""}'), lsc.LanguageServerConnectionStopped
    ]

    with patch.object(connection, 'ReadData', side_effect=return_values):
        with patch.object(connection, '_DispatchMessage') as dispatch_message:
            connection.run()
            dispatch_message.assert_called_with({'abc': ''})
コード例 #11
0
def LanguageServerConnection_RequestAbortAwait_test():
  connection = MockConnection()

  return_values = [
    lsc.LanguageServerConnectionStopped
  ]

  with patch.object( connection, 'ReadData', side_effect = return_values ):
    response = connection.GetResponseAsync( 1,
                                            bytes( b'{"test":"test"}' ) )
    connection.run()
    assert_that( calling( response.AwaitResponse ).with_args( 10 ),
                 raises( lsc.ResponseAbortedException ) )
コード例 #12
0
def LanguageServerConnection_ReadPartialMessage_test():
  connection = MockConnection()

  return_values = [
    bytes( b'Content-Length: 10\n\n{"abc":' ),
    bytes( b'""}' ),
    lsc.LanguageServerConnectionStopped
  ]

  with patch.object( connection, 'ReadData', side_effect = return_values ):
    with patch.object( connection, '_DispatchMessage' ) as dispatch_message:
      connection.run()
      dispatch_message.assert_called_with( { 'abc': '' } )
コード例 #13
0
def LanguageServerConnection_RequestAbortCallback_test():
  connection = MockConnection()

  return_values = [
    lsc.LanguageServerConnectionStopped
  ]

  with patch.object( connection, 'ReadData', side_effect = return_values ):
    callback = MagicMock()
    response = connection.GetResponseAsync( 1,
                                            bytes( b'{"test":"test"}' ),
                                            response_callback = callback )
    connection.run()
    callback.assert_called_with( response, None )
コード例 #14
0
    def __init__(self, custom_options={}):
        user_options = handlers._server_state._user_options.copy()
        user_options.update(custom_options)
        super(MockCompleter, self).__init__(user_options)

        self._connection = MockConnection()
        self._started = False
コード例 #15
0
  def __init__( self, custom_options = {} ):
    user_options = handlers._server_state._user_options.copy()
    user_options.update( custom_options )
    super().__init__( user_options )

    self._connection = MockConnection(
        lambda request: self.WorkspaceConfigurationResponse( request ) )
    self._started = False
コード例 #16
0
def LanguageServerConnection_MissingHeader_test():
    connection = MockConnection()

    return_values = [
        bytes(b'Content-NOTLENGTH: 10\n\n{"abc":'),
        bytes(b'""}'), lsc.LanguageServerConnectionStopped
    ]

    with patch.object(connection, 'ReadData', side_effect=return_values):
        assert_that(calling(connection._ReadMessages), raises(ValueError))
def LanguageServerConnection_RejectUnsupportedRequest_test():
    connection = MockConnection()

    return_values = [
        bytes(b'Content-Length: 26\r\n\r\n{"id":"1","method":"test"}'),
        lsc.LanguageServerConnectionStopped
    ]

    expected_response = bytes(b'Content-Length: 79\r\n\r\n'
                              b'{"error":{'
                              b'"code":-32601,'
                              b'"message":"Method not found"'
                              b'},'
                              b'"id":"1",'
                              b'"jsonrpc":"2.0"}')

    with patch.object(connection, 'ReadData', side_effect=return_values):
        with patch.object(connection, 'WriteData') as write_data:
            connection.run()
            write_data.assert_called_with(expected_response)
コード例 #18
0
def LanguageServerConnection_RejectUnsupportedRequest_test():
  connection = MockConnection()

  return_values = [
    bytes( b'Content-Length: 26\r\n\r\n{"id":"1","method":"test"}' ),
    lsc.LanguageServerConnectionStopped
  ]

  expected_response = bytes( b'Content-Length: 104\r\n\r\n'
                             b'{"error": {'
                               b'"code": -32601, '
                               b'"reason": "Method not found"'
                             b'}, '
                             b'"id": "1", '
                             b'"jsonrpc": "2.0", '
                             b'"method": "test"}' )

  with patch.object( connection, 'ReadData', side_effect = return_values ):
    with patch.object( connection, 'WriteData' ) as write_data:
      connection.run()
      write_data.assert_called_with( expected_response )
コード例 #19
0
 def __init__( self ):
   self._connection = MockConnection()
   super( MockCompleter, self ).__init__(
     handlers._server_state._user_options )