Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyaml/magnet/cfm_magnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions pyaml/magnet/magnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pyaml/magnet/serialized_magnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
15 changes: 15 additions & 0 deletions tests/magnet/test_missing_model_errors.py
Original file line number Diff line number Diff line change
@@ -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)
Loading