From 0c8d1dc2dcc19c1be8781d9c29223cc6016febde Mon Sep 17 00:00:00 2001 From: BM804 <112770884+BM804@users.noreply.github.com> Date: Fri, 16 Oct 2026 22:36:48 +0530 Subject: [PATCH 1/3] Fix missing magnet model error recursion --- pyaml/magnet/cfm_magnet.py | 4 ++-- pyaml/magnet/magnet.py | 4 ++-- pyaml/magnet/serialized_magnet.py | 4 ++-- tests/magnet/test_missing_model_errors.py | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 tests/magnet/test_missing_model_errors.py diff --git a/pyaml/magnet/cfm_magnet.py b/pyaml/magnet/cfm_magnet.py index 83c5578f..47140100 100644 --- a/pyaml/magnet/cfm_magnet.py +++ b/pyaml/magnet/cfm_magnet.py @@ -239,7 +239,7 @@ def strengths(self) -> abstract.ReadWriteFloatScalar: """ self.check_peer() if self.__strengths is None: - raise PyAMLException(f"{str(self)} has no model that supports physics units") + raise PyAMLException(f"{self.name} has no model that supports physics units") return self.__strengths @property @@ -250,7 +250,7 @@ def hardwares(self) -> abstract.ReadWriteFloatScalar: """ self.check_peer() if self.__hardwares is None: - raise PyAMLException(f"{str(self)} has no model that supports hardware units") + raise PyAMLException(f"{self.name} has no model that supports hardware units") return self.__hardwares def set_energy(self, E: float): diff --git a/pyaml/magnet/magnet.py b/pyaml/magnet/magnet.py index b01491d7..fd5a4a09 100644 --- a/pyaml/magnet/magnet.py +++ b/pyaml/magnet/magnet.py @@ -83,7 +83,7 @@ def strength(self) -> abstract.ReadWriteFloatScalar: """ self.check_peer() if self.__strength is None: - raise PyAMLException(f"{str(self)} has no model that supports physics units") + raise PyAMLException(f"{self.name} has no model that supports physics units") return self.__strength @property @@ -94,7 +94,7 @@ def hardware(self) -> abstract.ReadWriteFloatScalar: """ self.check_peer() if self.__hardware is None: - raise PyAMLException(f"{str(self)} has no model that supports hardware units") + raise PyAMLException(f"{self.name} has no model that supports hardware units") return self.__hardware @property diff --git a/pyaml/magnet/serialized_magnet.py b/pyaml/magnet/serialized_magnet.py index ddfe1733..c5aab6fa 100644 --- a/pyaml/magnet/serialized_magnet.py +++ b/pyaml/magnet/serialized_magnet.py @@ -355,7 +355,7 @@ def strength(self) -> abstract.ReadWriteFloatScalar: """ self.check_peer() if self.__strengths is None: - raise PyAMLException(f"{str(self)} has no model that supports physics units") + raise PyAMLException(f"{self.name} has no model that supports physics units") return self.__strengths @property @@ -365,7 +365,7 @@ def hardware(self) -> abstract.ReadWriteFloatScalar: """ self.check_peer() if self.__hardwares is None: - raise PyAMLException(f"{str(self)} has no model that supports hardware units") + raise PyAMLException(f"{self.name} has no model that supports hardware units") return self.__hardwares def set_energy(self, energy: float): diff --git a/tests/magnet/test_missing_model_errors.py b/tests/magnet/test_missing_model_errors.py new file mode 100644 index 00000000..37c25b57 --- /dev/null +++ b/tests/magnet/test_missing_model_errors.py @@ -0,0 +1,15 @@ +import pytest + +from pyaml import PyAMLException +from pyaml.magnet.hcorrector import HCorrector + + +@pytest.mark.parametrize( + ("accessor", "unit"), + [("strength", "physics"), ("hardware", "hardware")], +) +def test_missing_model_error_names_magnet_without_repr_recursion(accessor, unit): + magnet = HCorrector("CH1").attach(object(), strength=None, hardware=None) + + with pytest.raises(PyAMLException, match=f"CH1 has no model that supports {unit} units"): + getattr(magnet, accessor) From 492730763ea49bc29b06621329e8826b588d6ba1 Mon Sep 17 00:00:00 2001 From: Babu Midddya <112770884+BM804@users.noreply.github.com> Date: Wed, 21 Oct 2026 01:37:56 +0530 Subject: [PATCH 2/3] Clarify missing magnet model regression test --- tests/magnet/test_missing_model_errors.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/magnet/test_missing_model_errors.py b/tests/magnet/test_missing_model_errors.py index 37c25b57..b07402d0 100644 --- a/tests/magnet/test_missing_model_errors.py +++ b/tests/magnet/test_missing_model_errors.py @@ -4,12 +4,11 @@ from pyaml.magnet.hcorrector import HCorrector -@pytest.mark.parametrize( - ("accessor", "unit"), - [("strength", "physics"), ("hardware", "hardware")], -) -def test_missing_model_error_names_magnet_without_repr_recursion(accessor, unit): +def test_missing_model_errors_name_magnet_without_formatting_it(): magnet = HCorrector("CH1").attach(object(), strength=None, hardware=None) - with pytest.raises(PyAMLException, match=f"CH1 has no model that supports {unit} units"): - getattr(magnet, accessor) + with pytest.raises(PyAMLException, match="CH1 has no model that supports physics units"): + magnet.strength + + with pytest.raises(PyAMLException, match="CH1 has no model that supports hardware units"): + magnet.hardware From f65487073e478fa268aea9f1d9c4884a35d68556 Mon Sep 17 00:00:00 2001 From: Babu Midddya <112770884+BM804@users.noreply.github.com> Date: Wed, 21 Oct 2026 01:42:59 +0530 Subject: [PATCH 3/3] Provide a default Python version for CI matrix --- .github/workflows/unit-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index b0bad8d9..9b6a185f 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -21,8 +21,8 @@ jobs: matrix: python-version: >- ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') - && fromJSON(vars.PYTHON_ALL_SUPPORTED_TEST_VERSIONS) - || fromJSON(vars.PYTHON_DEFAULT_TEST_VERSIONS) }} + && fromJSON(vars.PYTHON_ALL_SUPPORTED_TEST_VERSIONS || '["3.11"]') + || fromJSON(vars.PYTHON_DEFAULT_TEST_VERSIONS || '["3.11"]') }} steps: - uses: actions/checkout@v6