Skip to content

Commit

Permalink
Added tests for WiFi and Bluetooth interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfjlaros committed Mar 3, 2021
1 parent a03d939 commit 2e19057
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
22 changes: 22 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pytest import fixture, skip


def pytest_addoption(parser: object) -> None:
parser.addoption('--device', type=str, default='')


@fixture
def device(pytestconfig: object) -> str:
return pytestconfig.getoption('device')


@fixture(autouse=True)
def test_device(request: object, device: str) -> None:
if request.node.get_closest_marker('test_device'):
if request.node.get_closest_marker('test_device').args[0] != device:
skip('skipped device: not {}'.format(device))


def pytest_configure(config: object) -> None:
config.addinivalue_line(
"markers", "test_device(device): test the given device")
5 changes: 2 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


_device = '/dev/ttyACM0'
_reason = 'device not connected'


def test_json_utf8_encode() -> None:
Expand All @@ -34,15 +33,15 @@ def test_describe_method() -> None:
" str b: Parameter b.\n\n returns float: Return value.")


@mark.skipif(not exists(_device), reason=_reason)
@mark.test_device('serial')
def test_rpc_list() -> None:
handle = StringIO()

rpc_list(handle, _device, 9600, 1)
assert 'ping data\n Echo a value.\n' in handle.getvalue()


@mark.skipif(not exists(_device), reason=_reason)
@mark.test_device('serial')
def test_rpc_call() -> None:
handle = StringIO()

Expand Down
38 changes: 31 additions & 7 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
from simple_rpc.simple_rpc import _version


_device = '/dev/ttyACM0'
if exists(_device):
_interface = Interface(_device, autoconnect=False)


@mark.skipif(not exists(_device), reason='device not connected')
class TestLib(object):
class _TestLib(object):
def test_pre_open(self: object) -> None:
assert not _interface.is_open()
assert _interface.methods == {}
Expand Down Expand Up @@ -57,3 +51,33 @@ def test_close(self: object) -> None:
def test_post_close(self: object) -> None:
assert not _interface.is_open()
assert _interface.methods == {}


def test_init_serial() -> None:
global _interface
_interface = Interface('/dev/ttyACM0', autoconnect=False)


@mark.test_device('serial')
class TestSerial(_TestLib):
pass


def test_init_wifi() -> None:
global _interface
_interface = Interface('socket://192.168.21.53:1025', autoconnect=False)


@mark.test_device('wifi')
class TestWiFi(_TestLib):
pass


def test_init_bluetooth() -> None:
global _interface
_interface = Interface('/dev/rfcomm0', autoconnect=False)


@mark.test_device('bt')
class TestBluetooth(_TestLib):
pass

0 comments on commit 2e19057

Please sign in to comment.