From 5c0a4d34f103c6fb4c486b89ad60013339e6a734 Mon Sep 17 00:00:00 2001 From: "Jeroen F.J. Laros" Date: Sat, 19 Oct 2024 20:24:37 +0200 Subject: [PATCH] Tests. --- README.rst | 2 +- examples/demo/demo.py | 4 +--- simple_rpc/cli.py | 3 +-- simple_rpc/simple_rpc.py | 2 +- tests/__init__.py | 0 tests/conf.py | 4 ++-- tests/test_cli.py | 12 ++++++------ tests/test_device.py | 2 +- tests/test_simple_rpc.py | 2 +- 9 files changed, 14 insertions(+), 17 deletions(-) create mode 100644 tests/__init__.py diff --git a/README.rst b/README.rst index d458f5b..27b8fb1 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ Arduino simpleRPC API client library and CLI :target: https://github.com/jfjlaros/arduino-simple-rpc/graphs/commit-activity .. image:: https://github.com/jfjlaros/arduino-simple-rpc/actions/workflows/python-package.yml/badge.svg :target: https://github.com/jfjlaros/arduino-simple-rpc/actions/workflows/python-package.yml -.. image:: https://readthedocs.org/projects/simplerpc/badge/?version=latest +.. image:: https://readthedocs.org/projects/arduino-simple-rpc/badge/?version=latest :target: https://arduino-simple-rpc.readthedocs.io/en/latest .. image:: https://img.shields.io/github/release-date/jfjlaros/arduino-simple-rpc.svg :target: https://github.com/jfjlaros/arduino-simple-rpc/releases diff --git a/examples/demo/demo.py b/examples/demo/demo.py index 6079969..57bfedf 100644 --- a/examples/demo/demo.py +++ b/examples/demo/demo.py @@ -3,7 +3,7 @@ from simple_rpc import Interface -device = '/dev/ttyACM0' +device = '/dev/ttyUSB0' cycles = 20 @@ -12,8 +12,6 @@ interface = Interface(device) stdout.write('done.\n\n') -stdout.write('Protocol version: {}\n\n'.format(interface._version)) - i = 0 while i < 10: stdout.write('Ping: sent {}, received {}.\n'.format(i, interface.ping(i))) diff --git a/simple_rpc/cli.py b/simple_rpc/cli.py index fc9ad43..b489fca 100644 --- a/simple_rpc/cli.py +++ b/simple_rpc/cli.py @@ -100,8 +100,7 @@ def _arg_parser() -> object: common_parser.add_argument( 'device', metavar='DEVICE', type=str, help='device') common_parser.add_argument( - '-b', dest='baudrate', type=int, default=9600, - help='baud rate') + '-b', dest='baudrate', type=int, default=9600, help='baud rate') common_parser.add_argument( '-w', dest='wait', type=int, default=2, help='time before communication starts') diff --git a/simple_rpc/simple_rpc.py b/simple_rpc/simple_rpc.py index 2bcb5f2..cf8a024 100644 --- a/simple_rpc/simple_rpc.py +++ b/simple_rpc/simple_rpc.py @@ -13,7 +13,7 @@ _protocol = 'simpleRPC' -_version = (3, 0, 0) +_version = (4, 0, 0) _list_req = 0xff diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conf.py b/tests/conf.py index 8e93e06..f04b8a9 100644 --- a/tests/conf.py +++ b/tests/conf.py @@ -2,7 +2,7 @@ _devices = { - 'serial': '/dev/ttyACM0', + 'serial': '/dev/ttyUSB0', 'wifi': 'socket://192.168.21.53:1025', 'bt': '/dev/rfcomm0'} _interface = """ @@ -24,7 +24,7 @@ protocol: simpleRPC size_t: H version: !!python/tuple -- 3 +- 4 - 0 - 0 """.format(''.join(map('- {}\n'.format, _version))) diff --git a/tests/test_cli.py b/tests/test_cli.py index a1d6b3b..15f8f8f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -6,7 +6,7 @@ from simple_rpc.cli import _describe_method, rpc_call, rpc_list from simple_rpc.extras import json_utf8_decode, json_utf8_encode -from conf import _devices, _interface +from .conf import _devices, _interface def test_json_utf8_encode() -> None: @@ -36,7 +36,7 @@ def test_describe_method() -> None: def test_rpc_list() -> None: handle = StringIO() - rpc_list(handle, _devices['serial'], 9600, 1, None) + rpc_list(handle, _devices['serial'], 9600, 2, None) assert 'ping data\n Echo a value.\n' in handle.getvalue() @@ -45,7 +45,7 @@ def test_rpc_list_save() -> None: handle = StringIO() iface_handle = StringIO() - rpc_list(handle, _devices['serial'], 9600, 1, iface_handle) + rpc_list(handle, _devices['serial'], 9600, 2, iface_handle) iface_handle.seek(0) device = load(iface_handle, Loader=FullLoader) assert device['methods']['ping']['doc'] == 'Echo a value.' @@ -55,7 +55,7 @@ def test_rpc_list_save() -> None: def test_rpc_call() -> None: handle = StringIO() - rpc_call(handle, _devices['serial'], 9600, 1, None, 'ping', ['10']) + rpc_call(handle, _devices['serial'], 9600, 2, None, 'ping', ['10']) assert handle.getvalue() == '10\n' @@ -65,7 +65,7 @@ def test_rpc_call_load() -> None: iface_handle = StringIO(_interface) rpc_call( - handle, _devices['serial'], 9600, 1, iface_handle, 'ping', ['10']) + handle, _devices['serial'], 9600, 2, iface_handle, 'ping', ['10']) assert handle.getvalue() == '10\n' @@ -76,7 +76,7 @@ def test_rpc_call_load_() -> None: try: rpc_call( - handle, _devices['serial'], 9600, 1, iface_handle, 'inc', ['1']) + handle, _devices['serial'], 9600, 2, iface_handle, 'inc', ['1']) except ValueError as error: assert str(error) == 'invalid method name: inc' else: diff --git a/tests/test_device.py b/tests/test_device.py index bf428d5..580cf0c 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -6,7 +6,7 @@ from simple_rpc import Interface from simple_rpc.simple_rpc import _version -from conf import _devices, _interface +from .conf import _devices, _interface class _TestDevice(object): diff --git a/tests/test_simple_rpc.py b/tests/test_simple_rpc.py index bdfb6cc..345fc62 100644 --- a/tests/test_simple_rpc.py +++ b/tests/test_simple_rpc.py @@ -2,7 +2,7 @@ SerialInterface, SocketInterface, Interface, _assert_protocol, _assert_version, _protocol, _version) -from conf import _devices +from .conf import _devices def test_assert_protocol_pass() -> None: