Merge branch 'master' into fix/pytest

This commit is contained in:
dforsi 2025-07-27 18:22:26 +02:00 committed by GitHub
commit 96d5abab47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1207 additions and 498 deletions

View file

@ -0,0 +1,42 @@
"""Tests of the Python bindings for Hamlib
"""
import pytest
import sys
def pytest_addoption(parser):
# using long options only because short options conflict with pytest's
if sys.argv[1].endswith("amp.py"):
parser.addoption('--model', type=int, default=1,
metavar='ID', help='select amplifier model number')
parser.addoption('--amp-file', default=None,
metavar='DEVICE', help='set device of the amplifier to operate on')
if sys.argv[1].endswith("rig.py"):
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')
elif sys.argv[1].endswith("rot.py"):
parser.addoption('--model', type=int, default=1,
metavar='ID', help='select rotator model number')
parser.addoption('--rot-file', default=None,
metavar='DEVICE', help='set device of the rotator 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")

View file

@ -9,14 +9,12 @@ import Hamlib
Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE)
AMP_MODEL = Hamlib.AMP_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()"""
amp = Hamlib.Amp(AMP_MODEL)
amp = Hamlib.Amp(model)
assert amp is not None
assert amp.do_exception == 0
assert amp.error_status == Hamlib.RIG_OK
@ -38,9 +36,9 @@ class TestClass:
assert amp.token_lookup("") is None
def test_with_open(self):
def test_with_open(self, model):
"""Call all the methods that depend on open()"""
amp = Hamlib.Amp(AMP_MODEL)
amp = Hamlib.Amp(model)
assert amp is not None
assert amp.state.comm_state == 0
@ -70,9 +68,9 @@ class TestClass:
assert info is None
def test_object_creation(self):
def test_object_creation(self, model):
"""Create all objects available"""
amp = Hamlib.Rig(AMP_MODEL)
amp = Hamlib.Rig(model)
assert amp is not None
assert isinstance(amp.caps, Hamlib.rig_caps)

View file

@ -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()
@ -117,9 +120,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
@ -232,9 +236,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)

19
bindings/python/test_rot.py Normal file → Executable file
View file

@ -11,8 +11,6 @@ import Hamlib
Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE)
ROT_MODEL = Hamlib.ROT_MODEL_DUMMY
class TestClass:
"""Container class for tests"""
@ -23,9 +21,9 @@ class TestClass:
# TOK_EL_ROT_MAGICCOMBO = 5 # handled by get_ext_level/set_ext_level
TOK_EL_ROT_MAGICEXTFUNC = 6
def test_without_open(self):
def test_without_open(self, model):
"""Call all the methods that do not depend on open()"""
rot = Hamlib.Rot(ROT_MODEL)
rot = Hamlib.Rot(model)
assert rot is not None
assert rot.do_exception == 0
assert rot.error_status == Hamlib.RIG_OK
@ -42,14 +40,17 @@ class TestClass:
assert isinstance(conf, str)
assert rot.set_conf("mcfg", "foo") is None
conf = rot.get_conf("mcfg")
assert conf == "foo"
if model == Hamlib.ROT_MODEL_DUMMY:
assert conf == "foo"
else:
assert conf == ""
assert rot.token_lookup("") is None
def test_with_open(self):
def test_with_open(self, model):
"""Call all the methods that depend on open()"""
rot = Hamlib.Rot(ROT_MODEL)
rot = Hamlib.Rot(model)
assert rot is not None
assert rot.state.comm_state == 0
@ -106,9 +107,9 @@ class TestClass:
assert info is None
def test_object_creation(self):
def test_object_creation(self, model):
"""Create all objects available"""
rot = Hamlib.Rig(ROT_MODEL)
rot = Hamlib.Rig(model)
assert rot is not None
assert isinstance(rot.caps, Hamlib.rig_caps)