From 0df9d1767eb7550e1f1668f62e6612e4fd2c442b Mon Sep 17 00:00:00 2001 From: Daniele Forsi IU5HKX Date: Sun, 27 Jul 2025 12:57:35 +0200 Subject: [PATCH] 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... --- bindings/python/conftest.py | 5 +++++ bindings/python/test_amp.py | 14 ++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bindings/python/conftest.py b/bindings/python/conftest.py index 89ba590d9..4f5510778 100644 --- a/bindings/python/conftest.py +++ b/bindings/python/conftest.py @@ -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') diff --git a/bindings/python/test_amp.py b/bindings/python/test_amp.py index 9d6a1d738..1a0b5eac3 100755 --- a/bindings/python/test_amp.py +++ b/bindings/python/test_amp.py @@ -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)