Skip to content

Commit

Permalink
MISC: add logger error when object not found
Browse files Browse the repository at this point in the history
  • Loading branch information
SMoraisAnsys authored Jan 30, 2024
2 parents 3a6c2aa + caa8421 commit 3259f8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions _unittest/test_14_AedtLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ def test_05_disable_stdout(self):
assert stream_content[2] == "PyAEDT INFO: Info after re-enabling the stdout handler.\n"


class TestLogMessages:
"""Class used to test log messages."""

def test_log_when_accessing_non_existing_object(self, caplog):
"""Check that accessing non existing object log an error message."""
from pyaedt import Hfss

app = Hfss(
projectname="log_project", designname="log_design", specified_version="2023.2", new_desktop_session=True
)
with pytest.raises(AttributeError):
app.get_object_material_properties("MS1", "conductivity")
assert ("Global", logging.ERROR, "Object 'MS1' not found.") in caplog.record_tuples


class CaptureStdOut:
"""Capture standard output with a context manager."""

Expand Down
1 change: 1 addition & 0 deletions pyaedt/modeler/cad/Primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def __getitem__(self, partId):
return self.user_defined_components[partId]
elif isinstance(partId, Object3d) or isinstance(partId, UserDefinedComponent):
return partId
self.logger.error("Object '{}' not found.".format(partId))
return None

def __init__(self, app, is3d=True):
Expand Down

0 comments on commit 3259f8c

Please sign in to comment.