Skip to content

Commit

Permalink
Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfjlaros committed Oct 19, 2024
1 parent d3a89d0 commit 5c0a4d3
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions examples/demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from simple_rpc import Interface


device = '/dev/ttyACM0'
device = '/dev/ttyUSB0'
cycles = 20


Expand All @@ -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)))
Expand Down
3 changes: 1 addition & 2 deletions simple_rpc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion simple_rpc/simple_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


_protocol = 'simpleRPC'
_version = (3, 0, 0)
_version = (4, 0, 0)

_list_req = 0xff

Expand Down
Empty file added tests/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions tests/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


_devices = {
'serial': '/dev/ttyACM0',
'serial': '/dev/ttyUSB0',
'wifi': 'socket://192.168.21.53:1025',
'bt': '/dev/rfcomm0'}
_interface = """
Expand All @@ -24,7 +24,7 @@
protocol: simpleRPC
size_t: H
version: !!python/tuple
- 3
- 4
- 0
- 0
""".format(''.join(map('- {}\n'.format, _version)))
12 changes: 6 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()


Expand All @@ -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.'
Expand All @@ -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'


Expand All @@ -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'


Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_simple_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5c0a4d3

Please sign in to comment.