Allow to execute some tests with a simulator or with a real rig

To execute the tests with the installed Hamlib use the same long arguments
as rigctl, eg:
 bindings/python/test_rig.py --model {MODEL_NUMBER} --rig-file /dev/ttyUSB0 --serial-speed {BAUD}

To execute the tests from the build tree, add the path to the libraries
that you built, eg. from the root of the build tree:
 PYTHONPATH=bindings/:bindings/.libs/ ...your command...
pull/1790/head
Daniele Forsi IU5HKX 2025-06-29 19:18:48 +02:00
rodzic 04c00330a6
commit c3ec11e5f7
2 zmienionych plików z 47 dodań i 12 usunięć

Wyświetl plik

@ -0,0 +1,30 @@
"""Tests of the Python bindings for Hamlib
"""
import pytest
def pytest_addoption(parser):
# using long options only because short options conflict with pytest's
parser.addoption('--model', type=int, default=1,
metavar='ID', help='select radio model number')
parser.addoption('--rig-file', default=None,
metavar='DEVICE', help='set device of the radio to operate on')
parser.addoption('--serial-speed', type=int, default=0,
metavar='BAUD', help='set serial speed of the serial port')
parser.addoption('--hamlib-verbose', action='count', default=0,
help='set verbose mode, cumulative')
@pytest.fixture
def model(request):
return request.config.getoption("--model")
@pytest.fixture
def rig_file(request):
return request.config.getoption("--rig-file")
@pytest.fixture
def serial_speed(request):
return request.config.getoption("--serial-speed")
@pytest.fixture
def hamlib_verbose(request):
return request.config.getoption("--hamlib-verbose")

Wyświetl plik

@ -5,20 +5,18 @@ Running this script directly will use the installed bindings.
For an in-tree run use "make check", or set PYTHONPATH to point to
the directories containing Hamlib.py and _Hamlib.so.
"""
from pytest import raises
import pytest
import Hamlib
Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE)
RIG_MODEL = Hamlib.RIG_MODEL_DUMMY
class TestClass:
"""Container class for tests"""
def test_without_open(self):
def test_without_open(self, model):
"""Call all the methods that do not depend on open()"""
rig = Hamlib.Rig(RIG_MODEL)
rig = Hamlib.Rig(model)
assert rig is not None
assert rig.do_exception == 0
assert rig.error_status == Hamlib.RIG_OK
@ -35,17 +33,22 @@ class TestClass:
assert isinstance(conf, str)
assert rig.set_conf("mcfg", "foo") is None
conf = rig.get_conf("mcfg")
assert conf == "foo"
if model == Hamlib.RIG_MODEL_DUMMY:
assert conf == "foo"
else:
assert conf == ""
assert rig.token_lookup("") is None
def test_with_open(self):
def test_with_open(self, model, rig_file, serial_speed):
"""Call all the methods that depend on open()"""
rig = Hamlib.Rig(RIG_MODEL)
rig = Hamlib.Rig(model)
assert rig is not None
assert rig.state.comm_state == 0
assert rig.set_conf("rig_pathname", rig_file) is None
assert rig.set_conf("serial_speed", str(serial_speed)) is None
assert rig.open() is None
assert rig.state.comm_state == 1
info = rig.get_info()
@ -70,9 +73,10 @@ class TestClass:
assert info is None
def test_misc(self):
@pytest.mark.skipif('config.getoption("model") != Hamlib.RIG_MODEL_DUMMY')
def test_misc(self, model):
"""Just call all the methods"""
rig = Hamlib.Rig(RIG_MODEL)
rig = Hamlib.Rig(model)
assert rig is not None
assert rig.close() is None
@ -213,9 +217,10 @@ class TestClass:
assert rig.vfo_op(0, 0) is None
def test_object_creation(self):
@pytest.mark.skipif('config.getoption("model") != Hamlib.RIG_MODEL_DUMMY')
def test_object_creation(self, model):
"""Create all objects available"""
rig = Hamlib.Rig(RIG_MODEL)
rig = Hamlib.Rig(model)
assert rig is not None
assert isinstance(rig.caps, Hamlib.rig_caps)