Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

Commit

Permalink
Updates tests for langserver
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 #27
  • Loading branch information
ksdme committed Apr 5, 2018
1 parent 45df0f8 commit 9248c90
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
8 changes: 6 additions & 2 deletions tests/server.features/langserver.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ Feature: langserver module
When I send a initialize request to the server
Then it should return the response with textDocumentSync

# TODO: Add positive test case.
Scenario: Test serve_did_save
Scenario: Test negative serve_did_save
Given the LangServer instance
When I send a did_save request about a non-existed file to the server
Then it should send a publishDiagnostics request

Scenario: Test positive serve_did_save
Given the LangServer instance
When I send a did_save request about a existing file to the server
Then it should send a publishDiagnostics request
66 changes: 53 additions & 13 deletions tests/server.features/steps/langserver_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
# ----------------------------------------------------------------------------
# STEPS:
# ----------------------------------------------------------------------------
import os
import tempfile
from behave import given, when, then
from coala_langserver.jsonrpc import TCPReadWriter
from pyls.jsonrpc import streams
from coala_langserver.langserver import LangServer


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


@when('I send a initialize request to the server')
Expand All @@ -27,16 +28,26 @@ 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._passed = False

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

reader = streams.JsonRpcStreamReader(context.f)
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')
Expand All @@ -50,14 +61,43 @@ def step_impl(context):
},
'jsonrpc': '2.0'
}
context.langServer.handle(None, request)
context.langServer._endpoint.consume(request)
context._diagnosticsCount = 0

@when('I send a did_save request about a existing file to the server')
def step_impl(context):
thisfile = os.path.realpath(__file__)
thisdir = os.path.dirname(thisfile)
parturi = os.path.join(thisdir, "../../resources", "unqualified.py")

request = {
'method': 'textDocument/didSave',
'params': {
'textDocument': {
'uri': 'file://{}'.format(parturi)
}
},
'jsonrpc': '2.0'
}
context.langServer._endpoint.consume(request)
context._diagnosticsCount = 4

@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._passed = False

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

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

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

if not context._passed:
assert False

4 comments on commit 9248c90

@gitmate-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on 9248c90.

There are 21 results for the section python. They have been shortened and will not be shown inline because they are more than 10.

Message File Line
You do not use the preferred quotation marks. tests/server.features/steps/langserver_steps.py 71
You do not use the preferred quotation marks. tests/server.features/steps/langserver_steps.py 71
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 25
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 25
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 56
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 56
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 57
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 57
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 58
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 59
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 60
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 93
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 93
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 94
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 95
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 95
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 96
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 97
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 98
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 113
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 113

Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.

@gitmate-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on 9248c90.

There are 22 results for the section autopep8. They have been shortened and will not be shown inline because they are more than 10.

Message File Line
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 13
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 52
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 62
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 89
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 100
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 124
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 14
E111 indentation is not a multiple of four tests/server.features/steps/jsonrpc_steps.py 15
E114 indentation is not a multiple of four (comment) tests/server.features/steps/jsonrpc_steps.py 19
E111 indentation is not a multiple of four tests/server.features/steps/jsonrpc_steps.py 20
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 22
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 53
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 64
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 90
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 102
W391 blank line at end of file tests/server.features/steps/jsonrpc_steps.py 124
The code does not comply to PEP8. tests/server.features/steps/langserver_steps.py 66
The code does not comply to PEP8. tests/server.features/steps/langserver_steps.py 84
The code does not comply to PEP8. tests/server.features/steps/langserver_steps.py 93
E302 expected 2 blank lines, found 1 tests/server.features/steps/langserver_steps.py 67
E302 expected 2 blank lines, found 1 tests/server.features/steps/langserver_steps.py 85
E501 line too long (82 > 79 characters) tests/server.features/steps/langserver_steps.py 93

Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.

@gitmate-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on 9248c90.

There are 23 results for the section python. They have been shortened and will not be shown inline because they are more than 10.

Message File Line
You do not use the preferred quotation marks. tests/server.features/steps/langserver_steps.py 71
You do not use the preferred quotation marks. tests/server.features/steps/langserver_steps.py 71
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 25
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 25
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 56
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 56
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 57
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 57
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 58
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 59
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 60
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 93
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 93
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 94
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 95
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 95
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 96
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 97
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 98
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 113
You do not use the preferred quotation marks. tests/server.features/steps/jsonrpc_steps.py 113
You do not use the preferred quotation marks. coala_langserver/langserver.py 17
You do not use the preferred quotation marks. coala_langserver/langserver.py 114

Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.

@gitmate-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on 9248c90.

There are 25 results for the section autopep8. They have been shortened and will not be shown inline because they are more than 10.

Message File Line
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 13
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 52
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 62
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 89
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 100
The code does not comply to PEP8. tests/server.features/steps/jsonrpc_steps.py 124
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 14
E111 indentation is not a multiple of four tests/server.features/steps/jsonrpc_steps.py 15
E114 indentation is not a multiple of four (comment) tests/server.features/steps/jsonrpc_steps.py 19
E111 indentation is not a multiple of four tests/server.features/steps/jsonrpc_steps.py 20
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 22
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 53
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 64
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 90
E302 expected 2 blank lines, found 1 tests/server.features/steps/jsonrpc_steps.py 102
W391 blank line at end of file tests/server.features/steps/jsonrpc_steps.py 124
The code does not comply to PEP8. tests/server.features/steps/langserver_steps.py 66
The code does not comply to PEP8. tests/server.features/steps/langserver_steps.py 84
The code does not comply to PEP8. tests/server.features/steps/langserver_steps.py 93
E302 expected 2 blank lines, found 1 tests/server.features/steps/langserver_steps.py 67
E302 expected 2 blank lines, found 1 tests/server.features/steps/langserver_steps.py 85
E501 line too long (82 > 79 characters) tests/server.features/steps/langserver_steps.py 93
The code does not comply to PEP8. coala_langserver/langserver.py 126
E265 block comment should start with '# ' coala_langserver/langserver.py 40
E501 line too long (85 > 79 characters) coala_langserver/langserver.py 126

Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.

Please sign in to comment.