Skip to content

Commit

Permalink
langserver_steps.py: Updates behave tests
Browse files Browse the repository at this point in the history
The behave tests have been updated to reflect
the new jsonrpc handling mechanism. The scope
of the tests remains unchanged.

Related to coala#27,
coala#32
  • Loading branch information
ksdme committed Mar 28, 2018
1 parent 59605c2 commit 63b9f75
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions tests/server.features/steps/langserver_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
# ----------------------------------------------------------------------------
import tempfile
from behave import given, when, then
from coala_langserver.jsonrpc import TCPReadWriter
from coala_langserver.jsonrpc import streams
from coala_langserver.langserver import LangServer

import logging
logging.propagate = False

@given('the LangServer instance')
def step_impl(context):
context.f = tempfile.TemporaryFile()
context.langServer = LangServer(conn=TCPReadWriter(context.f, context.f))
context.file = tempfile.TemporaryFile()
context.langServer = LangServer(context.file, context.file)


@when('I send a initialize request to the server')
Expand All @@ -27,17 +29,27 @@ def step_impl(context):
'id': 1,
'jsonrpc': '2.0'
}
context.langServer.handle(1, request)

context.langServer._endpoint.consume(request)


@then('it should return the response with textDocumentSync')
def step_impl(context):
context.f.seek(0)
response = context.langServer.read_message(1)
assert response is not None
assert response['result']['capabilities']['textDocumentSync'] is 1
context.f.close()
context.file.seek(0)
context._passed = False

def consumer(response):
assert response is not None
assert response['result']['capabilities']['textDocumentSync'] == 1
context.file.close()
context._passed = True

reader = streams.JsonRpcStreamReader(context.file)
reader.listen(consumer)
reader.close()

if not context._passed:
assert False

@when('I send a did_save request about a non-existed file to the server')
def step_impl(context):
Expand All @@ -50,14 +62,25 @@ def step_impl(context):
},
'jsonrpc': '2.0'
}
context.langServer.handle(None, request)
context.langServer._endpoint.consume(request)


@then('it should send a publishDiagnostics request')
def step_impl(context):
context.f.seek(0)
response = context.langServer.read_message()
assert response is not None
assert response['method'] == 'textDocument/publishDiagnostics'
assert len(response['params']['diagnostics']) is 0
context.f.close()
context.file.seek(0)
context._passed = False

def consumer(response):
assert response is not None
assert response['method'] == 'textDocument/publishDiagnostics'
assert len(response['params']['diagnostics']) is 0

context.file.close()
context._passed = True

reader = streams.JsonRpcStreamReader(context.file)
reader.listen(consumer)
reader.close()

if not context._passed:
assert False

0 comments on commit 63b9f75

Please sign in to comment.