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

To execute the tests with the installed Hamlib use the same long arguments
as rotctl, eg:
 bindings/python/test_rot.py --model {MODEL_NUMBER} --rot-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-07-27 12:53:23 +02:00
rodzic eefdda51e5
commit 6088445635
2 zmienionych plików z 21 dodań i 13 usunięć

Wyświetl plik

@ -1,13 +1,20 @@
"""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
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')
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,

19
bindings/python/test_rot.py 100644 → 100755
Wyświetl plik

@ -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)