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

Commit

Permalink
tests: Add test cases for jsonrpc
Browse files Browse the repository at this point in the history
  • Loading branch information
gaocegege committed Feb 12, 2017
1 parent b82cca6 commit 5e9b8e1
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 56 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source = .
[report]
exclude_lines =
if self.debug:
pass
pragma: no cover
raise NotImplementedError
if __name__ == .__main__.:
Expand Down
53 changes: 0 additions & 53 deletions coala_langserver/fs.py

This file was deleted.

3 changes: 0 additions & 3 deletions coala_langserver/langserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import socketserver
import traceback

from .fs import LocalFileSystem
from .jsonrpc import JSONRPC2Connection, ReadWriter, TCPReadWriter
from .log import log
from .coalashim import run_coala_with_specific_file
Expand Down Expand Up @@ -32,8 +31,6 @@ class LangServer(JSONRPC2Connection):
def __init__(self, conn=None):
super().__init__(conn=conn)
self.root_path = None
self.symbol_cache = None
self.fs = LocalFileSystem()

def handle(self, _id, request):
'""Handle the request from language client.""'
Expand Down
File renamed without changes.
38 changes: 38 additions & 0 deletions tests/server.features/jsonrpc.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Feature: jsonrpc module
jsonrpc is a module of language-server.

Scenario: Test ReadWriter
Given the string
When I write it to ReadWriter
Then it should read from ReadWriter

Scenario: Test ReadWriter
Given the string
When I write it to ReadWriter
Then it should readline from ReadWriter

Scenario: Test TCPReadWriter
Given the string
When I write it to TCPReadWriter
Then it should read from TCPReadWriter

Scenario: Test TCPReadWriter
Given the string
When I write it to TCPReadWriter
Then it should readline from TCPReadWriter

Scenario: Test send_notification and read_message
Given the JSONRPC2Connection instance
When I write a notification to the JSONRPC2Connection
Then it should return the notification from JSONRPC2Connection

Scenario: Test write_response
Given the JSONRPC2Connection instance
When I write a response to the JSONRPC2Connection
Then it should return the response from JSONRPC2Connection

# TODO: block until we have generantee the unique request.
# Scenario: Test send_request
# Given the JSONRPC2Connection instance
# When I write a request to the JSONRPC2Connection with id
# Then it should return the request from JSONRPC2Connection with id
106 changes: 106 additions & 0 deletions tests/server.features/steps/jsonrpc_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# -*- coding: UTF-8 -*-

# @mark.steps
# ----------------------------------------------------------------------------
# STEPS:
# ----------------------------------------------------------------------------
import tempfile
import json
from behave import given, when, then
from coala_langserver.jsonrpc import ReadWriter, TCPReadWriter, JSONRPC2Connection


@given('the string')
def step_impl(context):
context.str = 'test-cases'


@when('I write it to ReadWriter')
def step_impl(context):
context.f = tempfile.TemporaryFile(mode='w+')
context.readWriter = ReadWriter(context.f, context.f)
context.readWriter.write(context.str)


@then('it should read from ReadWriter')
def step_impl(context):
context.f.seek(0)
assert context.readWriter.read(len(context.str)) is not ''
context.f.close()


@then('it should readline from ReadWriter')
def step_impl(context):
context.f.seek(0)
assert context.readWriter.readline() is not ''
context.f.close()


@when('I write it to TCPReadWriter')
def step_impl(context):
context.f = tempfile.TemporaryFile()
context.readWriter = TCPReadWriter(context.f, context.f)
context.readWriter.write(context.str)


@then('it should read from TCPReadWriter')
def step_impl(context):
context.f.seek(0)
assert context.readWriter.read(len(context.str)) is not ''
context.f.close()


@then('it should readline from TCPReadWriter')
def step_impl(context):
context.f.seek(0)
assert context.readWriter.readline() is not ''
context.f.close()


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


@when('I write a request to the JSONRPC2Connection with id')
def step_impl(context):
context.jsonConn.send_request('mockMethod', {
'mock': 'mock'
})


@then('it should return the request from JSONRPC2Connection with id')
def step_impl(context):
context.f.seek(0)
assert context.jsonConn.read_message() is not None
context.f.close()


@when('I write a notification to the JSONRPC2Connection')
def step_impl(context):
context.jsonConn.send_notification('mockMethod', {
'mock': 'mock'
})


@then('it should return the notification from JSONRPC2Connection')
def step_impl(context):
context.f.seek(0)
assert context.jsonConn.read_message() is not None
context.f.close()


@when('I write a response to the JSONRPC2Connection')
def step_impl(context):
context.ID = 1
context.jsonConn.write_response(context.ID, {
'mock': 'mock'
})


@then('it should return the response from JSONRPC2Connection')
def step_impl(context):
context.f.seek(0)
assert context.jsonConn.read_message(context.ID) is not None
context.f.close()

0 comments on commit 5e9b8e1

Please sign in to comment.