mirror of
https://github.com/haiwen/libsearpc.git
synced 2025-09-02 13:25:25 +00:00
[pysearpc] Support json return type. (#33)
* [pysearpc] Support json return type. * Added tests for json return type
This commit is contained in:
@@ -22,6 +22,10 @@ def init_server():
|
||||
searpc_server.create_service(SVCNAME)
|
||||
searpc_server.register_function(SVCNAME, add, 'add')
|
||||
searpc_server.register_function(SVCNAME, mul, 'multi')
|
||||
searpc_server.register_function(SVCNAME, json_func, 'json_func')
|
||||
|
||||
def json_func(a, b):
|
||||
return {'a': a, 'b': b}
|
||||
|
||||
|
||||
class DummyTransport(SearpcTransport):
|
||||
@@ -40,6 +44,10 @@ class RpcMixin(object):
|
||||
def multi(self, x, y):
|
||||
pass
|
||||
|
||||
@searpc_func("json", ["string", "int"])
|
||||
def json_func(self, x, y):
|
||||
pass
|
||||
|
||||
class DummyRpcClient(SearpcClient, RpcMixin):
|
||||
def __init__(self):
|
||||
self.transport = DummyTransport()
|
||||
@@ -86,6 +94,9 @@ class SearpcTest(unittest.TestCase):
|
||||
v = client.multi('abc', 2)
|
||||
self.assertEqual(v, 'abcabc')
|
||||
|
||||
v = client.json_func(1, 2)
|
||||
self.assertEqual(v, json_func(1, 2))
|
||||
|
||||
def setup_logging(level=logging.INFO):
|
||||
kw = {
|
||||
# 'format': '[%(asctime)s][%(pathname)s]: %(message)s',
|
||||
|
Reference in New Issue
Block a user