[Hamlib-commits] Hamlib -- Ham radio control libraries branch master updated. 119e0793739c772fcee2f
Library to control radio transceivers and receivers
Brought to you by:
n0nb
From: n0nb <n0...@us...> - 2025-07-27 15:53:39
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Hamlib -- Ham radio control libraries". The branch, master has been updated via 119e0793739c772fcee2fbe7228c4b61afc279e1 (commit) via 0df9d1767eb7550e1f1668f62e6612e4fd2c442b (commit) via 6088445635876162b47a9d59d4ce70a7d1fef128 (commit) via eefdda51e5451c9b470d84e4fdfc834e254f5d3a (commit) via ede84bfce41bf8da3dafea7c585666259a5e4b71 (commit) via c3ec11e5f7636ebe0912b43f59804aae326ee917 (commit) from 7cceee9abad13888f5705feef5330904eb06bf31 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 119e0793739c772fcee2fbe7228c4b61afc279e1 Merge: 7cceee9ab 0df9d1767 Author: Nate Bargmann <n0...@n0...> Date: Sun Jul 27 10:14:43 2025 -0500 Merge GitHub PR #1790 commit 0df9d1767eb7550e1f1668f62e6612e4fd2c442b Author: Daniele Forsi IU5HKX <iu...@gm...> Date: Sun Jul 27 12:57:35 2025 +0200 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... 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) commit 6088445635876162b47a9d59d4ce70a7d1fef128 Author: Daniele Forsi IU5HKX <iu...@gm...> Date: Sun Jul 27 12:53:23 2025 +0200 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... diff --git a/bindings/python/conftest.py b/bindings/python/conftest.py index d3d435e98..89ba590d9 100644 --- a/bindings/python/conftest.py +++ b/bindings/python/conftest.py @@ -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, diff --git a/bindings/python/test_rot.py b/bindings/python/test_rot.py old mode 100644 new mode 100755 index f51ea46ce..c87835534 --- a/bindings/python/test_rot.py +++ b/bindings/python/test_rot.py @@ -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) commit eefdda51e5451c9b470d84e4fdfc834e254f5d3a Author: Daniele Forsi IU5HKX <iu...@gm...> Date: Sun Jul 27 11:04:52 2025 +0200 Update documentation for Python tests diff --git a/README.developer b/README.developer index bdca0f715..177717f09 100644 --- a/README.developer +++ b/README.developer @@ -481,6 +481,21 @@ autogenerated tests must be updated: and the handwritten tests should be updated to reflect the change. +The Python tests can also be run against a simulator or an actual rig, but +they aren't guaranteed to succeed because the CI only tests the dummy rig. +To execute the tests from the build tree, add the path to the libraries +that you built, using the PYTHONPATH environment variable, eg: + PYTHONPATH=bindings/:bindings/.libs/ bindings/python/test_rig.py \ + --model 1035 --rig-file /dev/ttyUSB0 --serial-speed 4800 + +Only the following long arguments are supported: + --model ID + --rig-file DEVICE + --serial-speed BAUD + --hamlib-verbose +The argument --hamlib-verbose can be repeated as many times as the --verbose +argument accepted by rigctl. + 1.4. Feedback commit ede84bfce41bf8da3dafea7c585666259a5e4b71 Author: Daniele Forsi IU5HKX <iu...@gm...> Date: Sun Jul 27 08:39:02 2025 +0200 Also check the "val" parameter in rig_set_conf() Avoids a segfault in lower level functions that can more easily happen when using the bindings. Simmetric with rig_get_conf() via rig_get_conf2(). diff --git a/src/conf.c b/src/conf.c index 41349ec1e..ef845dcde 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1477,7 +1477,7 @@ int HAMLIB_API rig_set_conf(RIG *rig, hamlib_token_t token, const char *val) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) + if (!rig || !rig->caps || !val) { return -RIG_EINVAL; } commit c3ec11e5f7636ebe0912b43f59804aae326ee917 Author: Daniele Forsi IU5HKX <iu...@gm...> Date: Sun Jun 29 19:18:48 2025 +0200 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... diff --git a/bindings/python/conftest.py b/bindings/python/conftest.py new file mode 100644 index 000000000..d3d435e98 --- /dev/null +++ b/bindings/python/conftest.py @@ -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') + +...@py...xture +def model(request): + return request.config.getoption("--model") + +...@py...xture +def rig_file(request): + return request.config.getoption("--rig-file") + +...@py...xture +def serial_speed(request): + return request.config.getoption("--serial-speed") + +...@py...xture +def hamlib_verbose(request): + return request.config.getoption("--hamlib-verbose") diff --git a/bindings/python/test_rig.py b/bindings/python/test_rig.py index 1c3927cb0..2de41ec71 100755 --- a/bindings/python/test_rig.py +++ b/bindings/python/test_rig.py @@ -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) ----------------------------------------------------------------------- Summary of changes: README.developer | 15 +++++++++++++++ bindings/python/conftest.py | 42 ++++++++++++++++++++++++++++++++++++++++++ bindings/python/test_amp.py | 14 ++++++-------- bindings/python/test_rig.py | 29 +++++++++++++++++------------ bindings/python/test_rot.py | 19 ++++++++++--------- src/conf.c | 2 +- 6 files changed, 91 insertions(+), 30 deletions(-) create mode 100644 bindings/python/conftest.py mode change 100644 => 100755 bindings/python/test_rot.py hooks/post-receive -- Hamlib -- Ham radio control libraries |