mirror of
https://github.com/haiwen/libsearpc.git
synced 2025-09-08 08:08:59 +00:00
Added integration tests for pysearpc
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
sudo: false
|
||||
language: c
|
||||
language: python
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
@@ -12,7 +12,8 @@ before_install:
|
||||
- ./autogen.sh
|
||||
script:
|
||||
- ./configure
|
||||
- make -j8
|
||||
- make check -j8
|
||||
- make -j4
|
||||
- make check -j4
|
||||
- cd pysearpc && python test_pysearpc.py
|
||||
notifications:
|
||||
email: false
|
||||
|
@@ -1,3 +1,4 @@
|
||||
from common import SearpcError
|
||||
from client import SearpcClient, searpc_func, SearpcObjEncoder
|
||||
from server import searpc_server
|
||||
from .common import SearpcError
|
||||
from .client import SearpcClient, searpc_func, SearpcObjEncoder
|
||||
from .server import searpc_server
|
||||
from .transport import SearpcTransport
|
||||
|
51
pysearpc/test_pysearpc.py
Normal file → Executable file
51
pysearpc/test_pysearpc.py
Normal file → Executable file
@@ -1,17 +1,52 @@
|
||||
#!/usr/bin/env python
|
||||
#coding: UTF-8
|
||||
|
||||
import json
|
||||
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):
|
||||
|
||||
def call_remote_func_sync(self, fcall_str):
|
||||
return ""
|
||||
def __init__(self):
|
||||
self.transport = DummyTransport()
|
||||
|
||||
@searpc_func("void", ["string", "int"])
|
||||
def list_peers(self):
|
||||
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
|
||||
|
||||
client = SampleRpcClient()
|
||||
client.list_peers("id", 10)
|
||||
class SearpcTest(unittest.TestCase):
|
||||
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
8
pysearpc/transport.py
Normal 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
|
Reference in New Issue
Block a user