11from io import StringIO
22
33from pytest import mark
4+ from yaml import FullLoader , load
45
56from simple_rpc .cli import _describe_method , rpc_call , rpc_list
67from simple_rpc .extras import json_utf8_decode , json_utf8_encode
78
8- from conf import _devices
9+ from conf import _devices , _interface
910
1011
1112def test_json_utf8_encode () -> None :
@@ -27,8 +28,8 @@ def test_describe_method() -> None:
2728 {'name' : 'b' , 'typename' : 'str' , 'doc' : 'Parameter b.' }],
2829 'return' : {
2930 'fmt' : b'f' , 'typename' : 'float' , 'doc' : 'Return value.' }}) ==
30- " test a b\n Test.\n \n int a: Parameter a.\n "
31- " str b: Parameter b.\n \n returns float: Return value." )
31+ ' test a b\n Test.\n \n int a: Parameter a.\n '
32+ ' str b: Parameter b.\n \n returns float: Return value.' )
3233
3334
3435@mark .test_device ('serial' )
@@ -39,9 +40,44 @@ def test_rpc_list() -> None:
3940 assert 'ping data\n Echo a value.\n ' in handle .getvalue ()
4041
4142
43+ @mark .test_device ('serial' )
44+ def test_rpc_list_save () -> None :
45+ handle = StringIO ()
46+ iface_handle = StringIO ()
47+
48+ rpc_list (handle , _devices ['serial' ], 9600 , 1 , iface_handle )
49+ iface_handle .seek (0 )
50+ device = load (iface_handle , Loader = FullLoader )
51+ assert device ['methods' ]['ping' ]['doc' ] == 'Echo a value.'
52+
53+
4254@mark .test_device ('serial' )
4355def test_rpc_call () -> None :
4456 handle = StringIO ()
4557
4658 rpc_call (handle , _devices ['serial' ], 9600 , 1 , None , 'ping' , ['10' ])
4759 assert handle .getvalue () == '10\n '
60+
61+
62+ @mark .test_device ('serial' )
63+ def test_rpc_call_load () -> None :
64+ handle = StringIO ()
65+ iface_handle = StringIO (_interface )
66+
67+ rpc_call (
68+ handle , _devices ['serial' ], 9600 , 1 , iface_handle , 'ping' , ['10' ])
69+ assert handle .getvalue () == '10\n '
70+
71+
72+ @mark .test_device ('serial' )
73+ def test_rpc_call_load_ () -> None :
74+ handle = StringIO ()
75+ iface_handle = StringIO (_interface )
76+
77+ try :
78+ rpc_call (
79+ handle , _devices ['serial' ], 9600 , 1 , iface_handle , 'inc' , ['1' ])
80+ except ValueError as error :
81+ assert str (error ) == 'invalid method name: inc'
82+ else :
83+ assert False
0 commit comments