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

To execute the tests with the installed Hamlib use the same long arguments
as ampctl, eg:
 bindings/python/test_amp.py --model {MODEL_NUMBER} --amp-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:57:35 +02:00
rodzic 6088445635
commit 0df9d1767e
2 zmienionych plików z 11 dodań i 8 usunięć

Wyświetl plik

@ -5,6 +5,11 @@ 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')

Wyświetl plik

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