adding first tests
This commit is contained in:
parent
ac17709700
commit
0d7bfb4ea9
@ -1,9 +0,0 @@
|
||||
import pylspclient
|
||||
from pytest_mock import mocker
|
||||
|
||||
# content of test_sample.py
|
||||
def func(x):
|
||||
return x + 1
|
||||
|
||||
def test_answer():
|
||||
assert func(3) == 5
|
45
tests/test_json_rpc_endpoint.py
Normal file
45
tests/test_json_rpc_endpoint.py
Normal file
@ -0,0 +1,45 @@
|
||||
import pylspclient
|
||||
from pytest_mock import mocker
|
||||
|
||||
|
||||
class StdinMock(object):
|
||||
def write(self, s):
|
||||
pass
|
||||
|
||||
def flush(self):
|
||||
pass
|
||||
|
||||
|
||||
def test_sanity(mocker):
|
||||
stdin_mock = StdinMock();
|
||||
mocker.patch.object(stdin_mock, 'write')
|
||||
json_rpc_endpoint = pylspclient.JsonRpcEndpoint(stdin_mock, None)
|
||||
json_rpc_endpoint.send_request({"key_num":1, "key_str":"some_string"})
|
||||
stdin_mock.write.assert_called()
|
||||
|
||||
assert(stdin_mock.write.call_args not in [
|
||||
'''Content-Length: 40\r\n\r\n{"key_str": "some_string", "key_num": 1}\r\n\r\n'''.encode("utf-8"),
|
||||
'''Content-Length: 40\r\n\r\n{"key_num": 1, "key_str": "some_string"}\r\n\r\n'''.encode("utf-8")
|
||||
])
|
||||
|
||||
|
||||
def test_class(mocker):
|
||||
class RpcClass(object):
|
||||
def __init__(self, value_num, value_str):
|
||||
self.key_num = value_num
|
||||
self.key_str = value_str
|
||||
|
||||
stdin_mock = StdinMock();
|
||||
mocker.patch.object(stdin_mock, 'write')
|
||||
json_rpc_endpoint = pylspclient.JsonRpcEndpoint(stdin_mock, None)
|
||||
json_rpc_endpoint.send_request(RpcClass(1, "some_string"))
|
||||
stdin_mock.write.assert_called()
|
||||
|
||||
assert(stdin_mock.write.call_args not in [
|
||||
'''Content-Length: 40\r\n\r\n{"key_str": "some_string", "key_num": 1}\r\n\r\n'''.encode("utf-8"),
|
||||
'''Content-Length: 40\r\n\r\n{"key_num": 1, "key_str": "some_string"}\r\n\r\n'''.encode("utf-8")
|
||||
])
|
||||
|
||||
# content of test_sample.py
|
||||
def func(x):
|
||||
return x + 1
|
Loading…
Reference in New Issue
Block a user