1
0
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:
Jiaqiang Xu
2018-08-22 18:24:32 +08:00
committed by Shuai Lin
parent 43d768cf2e
commit 2021fe4aa8
2 changed files with 26 additions and 0 deletions

View File

@@ -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',