diff --git a/pyvo/mivot/tests/test_mivot_writer.py b/pyvo/mivot/tests/test_mivot_writer.py index bc0d9770..053a9032 100644 --- a/pyvo/mivot/tests/test_mivot_writer.py +++ b/pyvo/mivot/tests/test_mivot_writer.py @@ -10,7 +10,7 @@ from astropy.io.votable import parse from pyvo.utils import activate_features from pyvo.mivot.version_checker import check_astropy_version -from pyvo.mivot.utils.exceptions import MappingException +from pyvo.mivot.utils.exceptions import MappingError from pyvo.mivot.utils.dict_utils import DictUtils from pyvo.mivot.writer.annotations import MivotAnnotations from pyvo.mivot.writer.instance import MivotInstance @@ -48,25 +48,25 @@ def test_MivotInstance(): """ Test the MivotInstance class for various operations including attribute addition, reference addition, and XML generation. Verifies that invalid operations raise - the expected MappingException. + the expected MappingError. """ - with pytest.raises(MappingException): + with pytest.raises(MappingError): MivotInstance(dmid="model:type.inst") instance1 = MivotInstance(dmtype="model:type.inst", dmid="id1") - with pytest.raises(MappingException): + with pytest.raises(MappingError): instance1.add_attribute( dmrole="model:type.inst.role1", value="value1", unit="m/s" ) - with pytest.raises(MappingException): + with pytest.raises(MappingError): instance1.add_attribute( dmtype="model:type.att1", dmrole="model:type.inst.role1" ) - with pytest.raises(MappingException): + with pytest.raises(MappingError): instance1.add_reference(dmref="dmreference") - with pytest.raises(MappingException): + with pytest.raises(MappingError): instance1.add_reference(dmrole="model:type.inst.role2") - with pytest.raises(MappingException): + with pytest.raises(MappingError): instance1.add_instance("azerty") instance1.add_reference(dmrole="model:type.inst.role2", dmref="dmreference") @@ -88,13 +88,13 @@ def test_MivotInstance(): def test_MivotAnnotations(): """ Test the MivotAnnotations class for template and global instance addition. Verifies - that invalid operations raise the expected MappingException. + that invalid operations raise the expected MappingError. """ mb = MivotAnnotations() - with pytest.raises(MappingException): + with pytest.raises(MappingError): mb.add_templates(12) - with pytest.raises(MappingException): + with pytest.raises(MappingError): mb.add_globals(12) diff --git a/pyvo/mivot/writer/annotations.py b/pyvo/mivot/writer/annotations.py index fdbe986f..650d79b3 100644 --- a/pyvo/mivot/writer/annotations.py +++ b/pyvo/mivot/writer/annotations.py @@ -87,7 +87,7 @@ from astropy import version from pyvo.utils.prototype import prototype_feature from pyvo.mivot.utils.xml_utils import XmlUtils -from pyvo.mivot.utils.exceptions import MappingException, AstropyVersionException +from pyvo.mivot.utils.exceptions import MappingError, AstropyVersionException from pyvo.mivot.writer.instance import MivotInstance from pyvo.mivot.version_checker import check_astropy_version @@ -251,7 +251,7 @@ def add_templates(self, templates_instance): Raises ------ - MappingException + MappingError If `templates_instance` is neither a string nor an instance of `MivotInstance`. """ if isinstance(templates_instance, MivotInstance): @@ -259,7 +259,7 @@ def add_templates(self, templates_instance): elif isinstance(templates_instance, str): self._templates.append(templates_instance) else: - raise MappingException( + raise MappingError( "Instance added to templates must be a string or MivotInstance." ) @@ -274,7 +274,7 @@ def add_globals(self, globals_instance): Raises ------ - MappingException + MappingError If `globals_instance` is neither a string nor an instance of `MivotInstance`. """ if isinstance(globals_instance, MivotInstance): @@ -282,7 +282,7 @@ def add_globals(self, globals_instance): elif isinstance(globals_instance, str): self._globals.append(globals_instance) else: - raise MappingException( + raise MappingError( "Instance added to globals must be a string or MivotInstance." ) @@ -327,7 +327,7 @@ def check_xml(self): Raises ------ - MappingException + MappingError If the validation fails. Notes @@ -349,7 +349,7 @@ def check_xml(self): try: schema.validate(mivot_block) except Exception as excep: - raise MappingException(f"Validation failed: {excep}") from excep + raise MappingError(f"Validation failed: {excep}") from excep def insert_into_votable(self, votable_file, template_id=None, override=False): """ @@ -366,7 +366,7 @@ def insert_into_votable(self, votable_file, template_id=None, override=False): Raises ------ - MappingException + MappingError If a mapping block already exists and `override` is False. """ if not check_astropy_version(): @@ -377,7 +377,7 @@ def insert_into_votable(self, votable_file, template_id=None, override=False): elif isinstance(votable_file, VOTableFile): votable = votable_file else: - raise MappingException( + raise MappingError( "votable_file must be a file path string or a VOTableFile instance." ) @@ -386,7 +386,7 @@ def insert_into_votable(self, votable_file, template_id=None, override=False): for subresource in resource.resources: if subresource.type == "meta": if not override: - raise MappingException( + raise MappingError( "A type='meta' resource already exists in the first 'result' resource." ) else: diff --git a/pyvo/mivot/writer/instance.py b/pyvo/mivot/writer/instance.py index c01411f1..cd8bfd82 100644 --- a/pyvo/mivot/writer/instance.py +++ b/pyvo/mivot/writer/instance.py @@ -38,7 +38,7 @@ """ from pyvo.utils.prototype import prototype_feature -from pyvo.mivot.utils.exceptions import MappingException +from pyvo.mivot.utils.exceptions import MappingError @prototype_feature("MIVOT") @@ -65,11 +65,11 @@ def __init__(self, dmtype=None, dmrole=None, dmid=None): Raises ------ - MappingException + MappingError If `dmtype` is not provided. """ if not dmtype: - raise MappingException("Cannot build an instance without dmtype") + raise MappingError("Cannot build an instance without dmtype") self._dmtype = dmtype self._dmrole = dmrole self._dmid = dmid @@ -94,15 +94,15 @@ def add_attribute(self, dmtype=None, dmrole=None, ref=None, value=None, unit=Non Raises ------ - MappingException + MappingError If `dmtype` or `dmrole` is not provided, or if both `ref` and `value` are not defined. """ if not dmtype: - raise MappingException("Cannot add an attribute without dmtype") + raise MappingError("Cannot add an attribute without dmtype") if not dmrole: - raise MappingException("Cannot add an attribute without dmrole") + raise MappingError("Cannot add an attribute without dmrole") if not ref and not value: - raise MappingException("Cannot add an attribute without ref or value") + raise MappingError("Cannot add an attribute without ref or value") xml_string = f'' self._content.append(xml_string) @@ -149,11 +149,11 @@ def add_instance(self, mivot_instance): Raises ------ - MappingException + MappingError If `mivot_instance` is not of type `MivotInstance`. """ if not isinstance(mivot_instance, MivotInstance): - raise MappingException("Instance added must be of type MivotInstance") + raise MappingError("Instance added must be of type MivotInstance") self._content.append(mivot_instance.xml_string()) def xml_string(self):