mirror of
https://github.com/haiwen/libsearpc.git
synced 2025-09-13 13:32:45 +00:00
Added failing tests for named pipe
This commit is contained in:
@@ -14,6 +14,6 @@ script:
|
|||||||
- ./configure
|
- ./configure
|
||||||
- make -j4
|
- make -j4
|
||||||
- make check -j4
|
- make check -j4
|
||||||
- cd pysearpc && python test_pysearpc.py
|
- python pysearpc/test_pysearpc.py
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
|
@@ -1,4 +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
|
from .transport import SearpcTransport, NamedPipeTransport
|
||||||
|
@@ -2,24 +2,23 @@
|
|||||||
#coding: UTF-8
|
#coding: UTF-8
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
from operator import add
|
from operator import add, mul
|
||||||
|
|
||||||
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||||
sys.path.insert(0, '..')
|
sys.path.insert(0, '..')
|
||||||
from pysearpc import (
|
from pysearpc import (
|
||||||
SearpcClient, SearpcError, SearpcTransport, searpc_func, searpc_server
|
SearpcClient, SearpcError, SearpcTransport, searpc_func, searpc_server, NamedPipeTransport
|
||||||
)
|
)
|
||||||
|
|
||||||
SVCNAME = 'test-service'
|
SVCNAME = 'test-service'
|
||||||
|
|
||||||
def multi(a, b):
|
|
||||||
return a * b
|
|
||||||
|
|
||||||
def init_server():
|
def init_server():
|
||||||
searpc_server.create_service(SVCNAME)
|
searpc_server.create_service(SVCNAME)
|
||||||
searpc_server.register_function(SVCNAME, add, 'add')
|
searpc_server.register_function(SVCNAME, add, 'add')
|
||||||
searpc_server.register_function(SVCNAME, multi, 'multi')
|
searpc_server.register_function(SVCNAME, mul, 'multi')
|
||||||
|
|
||||||
|
|
||||||
class DummyTransport(SearpcTransport):
|
class DummyTransport(SearpcTransport):
|
||||||
@@ -39,14 +38,32 @@ class SampleRpcClient(SearpcClient):
|
|||||||
def add(self, x, y):
|
def add(self, x, y):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@searpc_func("string", ["string", "int"])
|
||||||
|
def multi(self, x, y):
|
||||||
|
pass
|
||||||
|
|
||||||
class SearpcTest(unittest.TestCase):
|
class SearpcTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
init_server()
|
init_server()
|
||||||
self.client = SampleRpcClient()
|
self.client = SampleRpcClient()
|
||||||
|
|
||||||
def testNormalTransport(self):
|
def test_normal_transport(self):
|
||||||
|
self.run_common()
|
||||||
|
|
||||||
|
@unittest.skip('not implemented yet')
|
||||||
|
def test_pipe_transport(self):
|
||||||
|
self.client.transport = NamedPipeTransport('/tmp/libsearpc-test.sock')
|
||||||
|
self.run_common()
|
||||||
|
|
||||||
|
def run_common(self):
|
||||||
v = self.client.add(1, 2)
|
v = self.client.add(1, 2)
|
||||||
self.assertEqual(v, 3)
|
self.assertEqual(v, 3)
|
||||||
|
|
||||||
|
v = self.client.multi(1, 2)
|
||||||
|
self.assertEqual(v, 2)
|
||||||
|
|
||||||
|
v = self.client.multi('abc', 2)
|
||||||
|
self.assertEqual(v, 'abcabc')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@@ -6,3 +6,11 @@ class SearpcTransport(object):
|
|||||||
"""
|
"""
|
||||||
def send(self, request_str):
|
def send(self, request_str):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
class NamedPipeTransport(SearpcTransport):
|
||||||
|
def __init__(self, pipe_path):
|
||||||
|
self.pipe_path = pipe_path
|
||||||
|
|
||||||
|
def send(self, fcall_str):
|
||||||
|
pass
|
||||||
|
Reference in New Issue
Block a user