1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-09-07 07:40:54 +00:00

Added integration tests for pysearpc

This commit is contained in:
Shuai Lin
2018-08-04 14:12:50 +08:00
parent 686c15f29e
commit a4fd83416d
4 changed files with 60 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
sudo: false sudo: false
language: c language: python
compiler: compiler:
- gcc - gcc
- clang - clang
@@ -12,7 +12,8 @@ before_install:
- ./autogen.sh - ./autogen.sh
script: script:
- ./configure - ./configure
- make -j8 - make -j4
- make check -j8 - make check -j4
- cd pysearpc && python test_pysearpc.py
notifications: notifications:
email: false email: false

View File

@@ -1,3 +1,4 @@
from common import SearpcError from .common import SearpcError
from client import SearpcClient, searpc_func, SearpcObjEncoder from .client import SearpcClient, searpc_func, SearpcObjEncoder
from server import searpc_server from .server import searpc_server
from .transport import SearpcTransport

53
pysearpc/test_pysearpc.py Normal file → Executable file
View File

@@ -1,17 +1,52 @@
#!/usr/bin/env python
#coding: UTF-8
import json
import sys import sys
sys.path += ['..'] import unittest
from operator import add
sys.path.insert(0, '..')
from pysearpc import (
SearpcClient, SearpcError, SearpcTransport, searpc_func, searpc_server
)
SVCNAME = 'test-service'
def multi(a, b):
return a * b
def init_server():
searpc_server.create_service(SVCNAME)
searpc_server.register_function(SVCNAME, add, 'add')
searpc_server.register_function(SVCNAME, multi, 'multi')
class DummyTransport(SearpcTransport):
def send(self, fcall_str):
return searpc_server.call_function(SVCNAME, fcall_str)
from pysearpc import SearpcClient, searpc_func, SearpcError
class SampleRpcClient(SearpcClient): class SampleRpcClient(SearpcClient):
def call_remote_func_sync(self, fcall_str):
return ""
@searpc_func("void", ["string", "int"]) def __init__(self):
def list_peers(self): self.transport = DummyTransport()
def call_remote_func_sync(self, fcall_str):
return self.transport.send(fcall_str)
@searpc_func("int", ["int", "int"])
def add(self, x, y):
pass pass
client = SampleRpcClient() class SearpcTest(unittest.TestCase):
client.list_peers("id", 10) def setUp(self):
init_server()
self.client = SampleRpcClient()
def testNormalTransport(self):
v = self.client.add(1, 2)
self.assertEqual(v, 3)
if __name__ == '__main__':
unittest.main()

8
pysearpc/transport.py Normal file
View File

@@ -0,0 +1,8 @@
class SearpcTransport(object):
"""
A transport is repsonsible to send the serialized request to the
server, and get back the raw response from the server.
"""
def send(self, request_str):
raise NotImplementedError