Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Add a Message Manager for App #1068

Merged
merged 27 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
28ef38d
init
dipinknair Jan 14, 2025
7b1074c
init
dipinknair Jan 14, 2025
f9de88e
add msg for app
dipinknair Jan 22, 2025
fc16515
add test file
dipinknair Jan 22, 2025
aaa510d
add messages for app
dipinknair Jan 27, 2025
320e260
Ansys.ACT.Core
dipinknair Jan 27, 2025
aeac997
chore: adding changelog file 1068.added.md [dependabot-skip]
pyansys-ci-bot Jan 27, 2025
63de2a9
revert lic
dipinknair Jan 27, 2025
721b31f
Merge branch 'fix/add_message' of https://github.com/ansys/pymechanic…
dipinknair Jan 27, 2025
3d6e3df
Merge branch 'main' into fix/add_message
dipinknair Jan 28, 2025
46d016d
add len and remove count
dipinknair Jan 28, 2025
11fa7c1
Merge branch 'main' of https://github.com/ansys/pymechanical into fix…
dipinknair Jan 29, 2025
e976cde
review suggestion
dipinknair Jan 30, 2025
13ba3b0
Merge branch 'main' of https://github.com/ansys/pymechanical into fix…
dipinknair Jan 30, 2025
8f79b35
pr review suggestions and remove functionality
dipinknair Feb 4, 2025
2fde9f5
remove Msg class
dipinknair Feb 4, 2025
44b2b97
update tests
dipinknair Feb 4, 2025
7e59d8f
remove test.py
dipinknair Feb 5, 2025
08ec5ce
review suggestion
dipinknair Feb 5, 2025
5b9776e
Merge branch 'main' into fix/add_message
dipinknair Feb 5, 2025
1cc5dd2
add _message back
dipinknair Feb 5, 2025
a0d3358
add app.new
dipinknair Feb 5, 2025
dad3f90
add clear before all tests
dipinknair Feb 7, 2025
bde03ff
Merge branch 'main' into fix/add_message
dipinknair Feb 7, 2025
6318579
update test
dipinknair Feb 7, 2025
1cfff12
Merge branch 'fix/add_message' of https://github.com/ansys/pymechanic…
dipinknair Feb 10, 2025
17c3196
change assert for timestamp
Feb 10, 2025
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
1 change: 1 addition & 0 deletions doc/changelog.d/1068.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a Message Manager for App
10 changes: 10 additions & 0 deletions src/ansys/mechanical/core/embedding/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def __init__(self, db_file=None, private_appdata=False, **kwargs):
INSTANCES.append(self)
self._updated_scopes: typing.List[typing.Dict[str, typing.Any]] = []
self._subscribe()
self._messages = None

def __repr__(self):
"""Get the product info."""
Expand Down Expand Up @@ -437,6 +438,15 @@ def project_directory(self):
"""Returns the current project directory."""
return self.DataModel.Project.ProjectDirectory

@property
def messages(self):
dipinknair marked this conversation as resolved.
Show resolved Hide resolved
"""Lazy-load the MessageManager."""
if self._messages is None:
from ansys.mechanical.core.embedding.messages import MessageManager

self._messages = MessageManager(self._app)
return self._messages

def _share(self, other) -> None:
"""Shares the state of self with other.

Expand Down
188 changes: 188 additions & 0 deletions src/ansys/mechanical/core/embedding/messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Message Manager for App."""

# TODO: add functionality to filter only errors, warnings, info
# TODO: add max number of messages to display
# TODO: implement pep8 formatting

try: # noqa: F401
import pandas as pd

HAS_PANDAS = True
"""Whether or not pandas exists."""
except ImportError:
HAS_PANDAS = False


class MessageManager:
"""Message manager for adding, fetching, and printing messages."""

def __init__(self, app):
"""Initialize the message manager."""
self._app = app

# Import necessary classes
from Ansys.Mechanical.DataModel.Enums import MessageSeverityType

self._message_severity = MessageSeverityType
self._messages = self._app.ExtAPI.Application.Messages

def _create_messages_data(self):
"""Update the local cache of messages."""
data = {
"Severity": [],
"TimeStamp": [],
"DisplayString": [],
"Source": [],
"StringID": [],
"Location": [],
"RelatedObjects": [],
}
for msg in self._app.ExtAPI.Application.Messages:
data["Severity"].append(str(msg.Severity).upper())
data["TimeStamp"].append(msg.TimeStamp)
data["DisplayString"].append(msg.DisplayString)
data["Source"].append(msg.Source)
data["StringID"].append(msg.StringID)
data["Location"].append(msg.Location)
data["RelatedObjects"].append(msg.RelatedObjects)

return data

def __repr__(self):
"""Provide a DataFrame representation of all messages."""
if not HAS_PANDAS:
return "Pandas is not available. Please pip install pandas to display messages."
data = self._create_messages_data()
return repr(pd.DataFrame(data))

def __str__(self):
"""Provide a custom string representation of the messages."""
if self._messages.Count == 0:
return "No messages to display."

formatted_messages = [f"[{msg.Severity}] : {msg.DisplayString}" for msg in self._messages]
return "\n".join(formatted_messages)

def __getitem__(self, index):
"""Allow indexed access to messages."""
if len(self._messages) == 0:
raise IndexError("No messages are available.")
if index >= len(self._messages) or index < 0:
raise IndexError("Message index out of range.")
return self._messages[index]

def __len__(self):
"""Return the number of messages."""
return self._messages.Count

def add(self, severity: str, text: str):
"""Add a message and update the cache.

Parameters
----------
severity : str
Severity of the message. Can be "info", "warning", or "error".
text : str
Message text.

Examples
--------
>>> app.messages.add("info", "User clicked the start button.")
"""
severity_map = {
"info": self._message_severity.Info,
"warning": self._message_severity.Warning,
"error": self._message_severity.Error,
}

if severity.lower() not in severity_map:
raise ValueError(f"Invalid severity: {severity}")

_msg = self._message(text, severity_map[severity.lower()])
self._messages.Add(_msg)

def remove(self, index: int):
"""Remove a message by index.

dipinknair marked this conversation as resolved.
Show resolved Hide resolved
Parameters
----------
index : int
Index of the message to remove.

Examples
--------
>>> app.messages.remove(0)
"""
if index >= len(self._app.ExtAPI.Application.Messages) or index < 0:
raise IndexError("Message index out of range.")
_msg = self._messages[index]
self._messages.Remove(_msg)

def show(self, filter="Severity;DisplayString"):
"""Print all messages with full details.

Parameters
----------
filter : str, optional
Semicolon separated list of message attributes to display.
Default is "severity;message".
if filter is "*", all available attributes will be displayed.

Examples
--------
>>> app.messages.show()
... severity: info
... message: Sample message.

>>> app.messages.show(filter="time_stamp;severity;message")
... time_stamp: 1/30/2025 12:10:35 PM
... severity: info
... message: Sample message.
"""
if self._messages.Count == 0:
print("No messages to display.")
return

if filter == "*":
selected_columns = [
"TimeStamp",
"Severity",
"DisplayString",
"Source",
"StringID",
"Location",
"RelatedObjects",
]
else:
selected_columns = [col.strip() for col in filter.split(";")]

for msg in self._messages:
for key in selected_columns:
print(f"{key}: {getattr(msg, key, 'Specified attribute not found.')}")
print()

def clear(self):
"""Clear all messages."""
self._messages.Clear()
122 changes: 122 additions & 0 deletions tests/embedding/test_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Message manager test"""

import os

import pytest


@pytest.mark.embedding
def test_message_manager(embedded_app, capsys):
"""Test message manager"""
assert len(embedded_app.messages) == 0

Check failure on line 33 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.12

test_messages.test_message_manager

assert 1 == 0 + where 1 = len(Pandas is not available. Please pip install pandas to display messages.) + where Pandas is not available. Please pip install pandas to display messages. = Ansys Mechanical [Ansys Mechanical Enterprise]\nProduct Version:251\nSoftware build date: 11/27/2024 09:34:44\n.messages
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

capsys = <_pytest.capture.CaptureFixture object at 0x7f0b24714140>

    @pytest.mark.embedding
    def test_message_manager(embedded_app, capsys):
        """Test message manager"""
>       assert len(embedded_app.messages) == 0
E       assert 1 == 0
E        +  where 1 = len(Pandas is not available. Please pip install pandas to display messages.)
E        +    where Pandas is not available. Please pip install pandas to display messages. = Ansys Mechanical [Ansys Mechanical Enterprise]\nProduct Version:251\nSoftware build date: 11/27/2024 09:34:44\n.messages

tests/embedding/test_messages.py:33: AssertionError

Check failure on line 33 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.10

test_messages.test_message_manager

assert 1 == 0 + where 1 = len(Pandas is not available. Please pip install pandas to display messages.) + where Pandas is not available. Please pip install pandas to display messages. = Ansys Mechanical [Ansys Mechanical Enterprise]\nProduct Version:251\nSoftware build date: 11/27/2024 09:34:44\n.messages
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

capsys = <_pytest.capture.CaptureFixture object at 0x7f5487ea6140>

    @pytest.mark.embedding
    def test_message_manager(embedded_app, capsys):
        """Test message manager"""
>       assert len(embedded_app.messages) == 0
E       assert 1 == 0
E        +  where 1 = len(Pandas is not available. Please pip install pandas to display messages.)
E        +    where Pandas is not available. Please pip install pandas to display messages. = Ansys Mechanical [Ansys Mechanical Enterprise]\nProduct Version:251\nSoftware build date: 11/27/2024 09:34:44\n.messages

tests/embedding/test_messages.py:33: AssertionError

Check failure on line 33 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.13

test_messages.test_message_manager

assert 1 == 0 + where 1 = len(Pandas is not available. Please pip install pandas to display messages.) + where Pandas is not available. Please pip install pandas to display messages. = Ansys Mechanical [Ansys Mechanical Enterprise]\nProduct Version:251\nSoftware build date: 11/27/2024 09:34:44\n.messages
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

capsys = <_pytest.capture.CaptureFixture object at 0x7f9df01e4910>

    @pytest.mark.embedding
    def test_message_manager(embedded_app, capsys):
        """Test message manager"""
>       assert len(embedded_app.messages) == 0
E       assert 1 == 0
E        +  where 1 = len(Pandas is not available. Please pip install pandas to display messages.)
E        +    where Pandas is not available. Please pip install pandas to display messages. = Ansys Mechanical [Ansys Mechanical Enterprise]\nProduct Version:251\nSoftware build date: 11/27/2024 09:34:44\n.messages

tests/embedding/test_messages.py:33: AssertionError

print(embedded_app.messages)
captured = capsys.readouterr()
printed_output = captured.out.strip()
assert "No messages to display." in printed_output

embedded_app.messages.add("info", "Info message")

Check failure on line 40 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.11

test_messages.test_message_manager

AttributeError: 'MessageManager' object has no attribute '_message'
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

capsys = <_pytest.capture.CaptureFixture object at 0x7f5e59bba750>

    @pytest.mark.embedding
    def test_message_manager(embedded_app, capsys):
        """Test message manager"""
        assert len(embedded_app.messages) == 0
    
        print(embedded_app.messages)
        captured = capsys.readouterr()
        printed_output = captured.out.strip()
        assert "No messages to display." in printed_output
    
>       embedded_app.messages.add("info", "Info message")

tests/embedding/test_messages.py:40: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Pandas is not available. Please pip install pandas to display messages.
severity = 'info', text = 'Info message'

    def add(self, severity: str, text: str):
        """Add a message and update the cache.
    
        Parameters
        ----------
        severity : str
            Severity of the message. Can be "info", "warning", or "error".
        text : str
            Message text.
    
        Examples
        --------
        >>> app.messages.add("info", "User clicked the start button.")
        """
        severity_map = {
            "info": self._message_severity.Info,
            "warning": self._message_severity.Warning,
            "error": self._message_severity.Error,
        }
    
        if severity.lower() not in severity_map:
            raise ValueError(f"Invalid severity: {severity}")
    
>       _msg = self._message(text, severity_map[severity.lower()])
E       AttributeError: 'MessageManager' object has no attribute '_message'

src/ansys/mechanical/core/embedding/messages.py:123: AttributeError

print(embedded_app.messages)
captured = capsys.readouterr()
printed_output = captured.out.strip()
assert "Info message" in printed_output


@pytest.mark.embedding
def test_message_add_and_clear(embedded_app):
"""Test adding and clearing messages"""
embedded_app.messages.add("info", "Info message")

Check failure on line 51 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.11

test_messages.test_message_add_and_clear

AttributeError: 'MessageManager' object has no attribute '_message'
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44


    @pytest.mark.embedding
    def test_message_add_and_clear(embedded_app):
        """Test adding and clearing messages"""
>       embedded_app.messages.add("info", "Info message")

tests/embedding/test_messages.py:51: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Pandas is not available. Please pip install pandas to display messages.
severity = 'info', text = 'Info message'

    def add(self, severity: str, text: str):
        """Add a message and update the cache.
    
        Parameters
        ----------
        severity : str
            Severity of the message. Can be "info", "warning", or "error".
        text : str
            Message text.
    
        Examples
        --------
        >>> app.messages.add("info", "User clicked the start button.")
        """
        severity_map = {
            "info": self._message_severity.Info,
            "warning": self._message_severity.Warning,
            "error": self._message_severity.Error,
        }
    
        if severity.lower() not in severity_map:
            raise ValueError(f"Invalid severity: {severity}")
    
>       _msg = self._message(text, severity_map[severity.lower()])
E       AttributeError: 'MessageManager' object has no attribute '_message'

src/ansys/mechanical/core/embedding/messages.py:123: AttributeError

Check failure on line 51 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.12

test_messages.test_message_add_and_clear

AttributeError: 'MessageManager' object has no attribute '_message'. Did you mean: '_messages'?
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44


    @pytest.mark.embedding
    def test_message_add_and_clear(embedded_app):
        """Test adding and clearing messages"""
>       embedded_app.messages.add("info", "Info message")

tests/embedding/test_messages.py:51: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Pandas is not available. Please pip install pandas to display messages.
severity = 'info', text = 'Info message'

    def add(self, severity: str, text: str):
        """Add a message and update the cache.
    
        Parameters
        ----------
        severity : str
            Severity of the message. Can be "info", "warning", or "error".
        text : str
            Message text.
    
        Examples
        --------
        >>> app.messages.add("info", "User clicked the start button.")
        """
        severity_map = {
            "info": self._message_severity.Info,
            "warning": self._message_severity.Warning,
            "error": self._message_severity.Error,
        }
    
        if severity.lower() not in severity_map:
            raise ValueError(f"Invalid severity: {severity}")
    
>       _msg = self._message(text, severity_map[severity.lower()])
E       AttributeError: 'MessageManager' object has no attribute '_message'. Did you mean: '_messages'?

src/ansys/mechanical/core/embedding/messages.py:123: AttributeError

Check failure on line 51 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.10

test_messages.test_message_add_and_clear

AttributeError: 'MessageManager' object has no attribute '_message'. Did you mean: '_messages'?
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44


    @pytest.mark.embedding
    def test_message_add_and_clear(embedded_app):
        """Test adding and clearing messages"""
>       embedded_app.messages.add("info", "Info message")

tests/embedding/test_messages.py:51: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Pandas is not available. Please pip install pandas to display messages.
severity = 'info', text = 'Info message'

    def add(self, severity: str, text: str):
        """Add a message and update the cache.
    
        Parameters
        ----------
        severity : str
            Severity of the message. Can be "info", "warning", or "error".
        text : str
            Message text.
    
        Examples
        --------
        >>> app.messages.add("info", "User clicked the start button.")
        """
        severity_map = {
            "info": self._message_severity.Info,
            "warning": self._message_severity.Warning,
            "error": self._message_severity.Error,
        }
    
        if severity.lower() not in severity_map:
            raise ValueError(f"Invalid severity: {severity}")
    
>       _msg = self._message(text, severity_map[severity.lower()])
E       AttributeError: 'MessageManager' object has no attribute '_message'. Did you mean: '_messages'?

src/ansys/mechanical/core/embedding/messages.py:123: AttributeError

Check failure on line 51 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.13

test_messages.test_message_add_and_clear

AttributeError: 'MessageManager' object has no attribute '_message'. Did you mean: '_messages'?
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44


    @pytest.mark.embedding
    def test_message_add_and_clear(embedded_app):
        """Test adding and clearing messages"""
>       embedded_app.messages.add("info", "Info message")

tests/embedding/test_messages.py:51: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Pandas is not available. Please pip install pandas to display messages.
severity = 'info', text = 'Info message'

    def add(self, severity: str, text: str):
        """Add a message and update the cache.
    
        Parameters
        ----------
        severity : str
            Severity of the message. Can be "info", "warning", or "error".
        text : str
            Message text.
    
        Examples
        --------
        >>> app.messages.add("info", "User clicked the start button.")
        """
        severity_map = {
            "info": self._message_severity.Info,
            "warning": self._message_severity.Warning,
            "error": self._message_severity.Error,
        }
    
        if severity.lower() not in severity_map:
            raise ValueError(f"Invalid severity: {severity}")
    
>       _msg = self._message(text, severity_map[severity.lower()])
E       AttributeError: 'MessageManager' object has no attribute '_message'. Did you mean: '_messages'?

src/ansys/mechanical/core/embedding/messages.py:123: AttributeError
assert len(embedded_app.messages) == 1
embedded_app.messages.add("warning", "Warning message")
assert len(embedded_app.messages) == 2
embedded_app.messages.add("error", "Error message")
assert len(embedded_app.messages) == 3

embedded_app.messages.remove(0)
assert len(embedded_app.messages) == 2

with pytest.raises(IndexError):
embedded_app.messages.remove(10)

embedded_app.messages.clear()
assert len(embedded_app.messages) == 0

with pytest.raises(ValueError):
embedded_app.messages.add("trace", "Trace message")


@pytest.mark.embedding
def test_message_show(embedded_app, capsys):
"""Test showing messages"""
print(embedded_app.messages.show())
captured = capsys.readouterr()
printed_output = captured.out.strip()
assert "No messages to display." in printed_output

Check failure on line 77 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.12

test_messages.test_message_show

AssertionError: assert 'No messages to display.' in 'Severity: Warning\nDisplayString: The license manager is delayed in its response. The latest requests were answered after 6 seconds.\n\nNone'
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

capsys = <_pytest.capture.CaptureFixture object at 0x7f0b24714560>

    @pytest.mark.embedding
    def test_message_show(embedded_app, capsys):
        """Test showing messages"""
        print(embedded_app.messages.show())
        captured = capsys.readouterr()
        printed_output = captured.out.strip()
>       assert "No messages to display." in printed_output
E       AssertionError: assert 'No messages to display.' in 'Severity: Warning\nDisplayString: The license manager is delayed in its response. The latest requests were answered after 6 seconds.\n\nNone'

tests/embedding/test_messages.py:77: AssertionError

Check failure on line 77 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.10

test_messages.test_message_show

AssertionError: assert 'No messages to display.' in 'Severity: Warning\nDisplayString: The license manager is delayed in its response. The latest requests were answered after 26 seconds.\n\nNone'
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

capsys = <_pytest.capture.CaptureFixture object at 0x7f54840afb20>

    @pytest.mark.embedding
    def test_message_show(embedded_app, capsys):
        """Test showing messages"""
        print(embedded_app.messages.show())
        captured = capsys.readouterr()
        printed_output = captured.out.strip()
>       assert "No messages to display." in printed_output
E       AssertionError: assert 'No messages to display.' in 'Severity: Warning\nDisplayString: The license manager is delayed in its response. The latest requests were answered after 26 seconds.\n\nNone'

tests/embedding/test_messages.py:77: AssertionError

Check failure on line 77 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.13

test_messages.test_message_show

AssertionError: assert 'No messages to display.' in 'Severity: Warning\nDisplayString: The license manager is delayed in its response. The latest requests were answered after 28 seconds.\n\nNone'
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

capsys = <_pytest.capture.CaptureFixture object at 0x7f9e7ce37820>

    @pytest.mark.embedding
    def test_message_show(embedded_app, capsys):
        """Test showing messages"""
        print(embedded_app.messages.show())
        captured = capsys.readouterr()
        printed_output = captured.out.strip()
>       assert "No messages to display." in printed_output
E       AssertionError: assert 'No messages to display.' in 'Severity: Warning\nDisplayString: The license manager is delayed in its response. The latest requests were answered after 28 seconds.\n\nNone'

tests/embedding/test_messages.py:77: AssertionError

embedded_app.messages.add("info", "Info message")

Check failure on line 79 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.11

test_messages.test_message_show

AttributeError: 'MessageManager' object has no attribute '_message'
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

capsys = <_pytest.capture.CaptureFixture object at 0x7f5e59bd5610>

    @pytest.mark.embedding
    def test_message_show(embedded_app, capsys):
        """Test showing messages"""
        print(embedded_app.messages.show())
        captured = capsys.readouterr()
        printed_output = captured.out.strip()
        assert "No messages to display." in printed_output
    
>       embedded_app.messages.add("info", "Info message")

tests/embedding/test_messages.py:79: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Pandas is not available. Please pip install pandas to display messages.
severity = 'info', text = 'Info message'

    def add(self, severity: str, text: str):
        """Add a message and update the cache.
    
        Parameters
        ----------
        severity : str
            Severity of the message. Can be "info", "warning", or "error".
        text : str
            Message text.
    
        Examples
        --------
        >>> app.messages.add("info", "User clicked the start button.")
        """
        severity_map = {
            "info": self._message_severity.Info,
            "warning": self._message_severity.Warning,
            "error": self._message_severity.Error,
        }
    
        if severity.lower() not in severity_map:
            raise ValueError(f"Invalid severity: {severity}")
    
>       _msg = self._message(text, severity_map[severity.lower()])
E       AttributeError: 'MessageManager' object has no attribute '_message'

src/ansys/mechanical/core/embedding/messages.py:123: AttributeError
embedded_app.messages.show()
captured = capsys.readouterr()
printed_output = captured.out.strip()
assert "Severity" in printed_output
assert "DisplayString" in printed_output
assert "Info message" in printed_output
embedded_app.messages.show(filter="TimeStamp")
captured = capsys.readouterr()
printed_output = captured.out.strip()
assert "TimeStamp" in printed_output

embedded_app.messages.show(filter="unknown")
captured = capsys.readouterr()
printed_output = captured.out.strip()
assert "Specified attribute not found" in printed_output


@pytest.mark.embedding
def test_message_get(embedded_app, assets, capsys):
"""Test getting a message"""
with pytest.raises(IndexError):

Check failure on line 100 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.12

test_messages.test_message_get

Failed: DID NOT RAISE <class 'IndexError'>
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

assets = PosixPath('/__w/pymechanical/pymechanical/tests/assets')
capsys = <_pytest.capture.CaptureFixture object at 0x7f0b24714ce0>

    @pytest.mark.embedding
    def test_message_get(embedded_app, assets, capsys):
        """Test getting a message"""
>       with pytest.raises(IndexError):
E       Failed: DID NOT RAISE <class 'IndexError'>

tests/embedding/test_messages.py:100: Failed

Check failure on line 100 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.10

test_messages.test_message_get

Failed: DID NOT RAISE <class 'IndexError'>
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

assets = PosixPath('/__w/pymechanical/pymechanical/tests/assets')
capsys = <_pytest.capture.CaptureFixture object at 0x7f5487f51690>

    @pytest.mark.embedding
    def test_message_get(embedded_app, assets, capsys):
        """Test getting a message"""
>       with pytest.raises(IndexError):
E       Failed: DID NOT RAISE <class 'IndexError'>

tests/embedding/test_messages.py:100: Failed

Check failure on line 100 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.13

test_messages.test_message_get

Failed: DID NOT RAISE <class 'IndexError'>
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

assets = PosixPath('/__w/pymechanical/pymechanical/tests/assets')
capsys = <_pytest.capture.CaptureFixture object at 0x7f9e7ce37bb0>

    @pytest.mark.embedding
    def test_message_get(embedded_app, assets, capsys):
        """Test getting a message"""
>       with pytest.raises(IndexError):
E       Failed: DID NOT RAISE <class 'IndexError'>

tests/embedding/test_messages.py:100: Failed
embedded_app.messages[0]

embedded_app.open(os.path.join(assets, "cube-hole.mechdb"))
_msg1 = embedded_app.messages[0]

print(embedded_app.messages[0])
captured = capsys.readouterr()
printed_output = captured.out.strip()
assert "Ansys.Mechanical.Application.Message" in printed_output

assert str(_msg1.Severity) == "Warning"
assert "Image file not found" in _msg1.DisplayString
assert "AM" in str(_msg1.TimeStamp) or "PM" in str(_msg1.TimeStamp)

Check failure on line 113 in tests/embedding/test_messages.py

View workflow job for this annotation

GitHub Actions / Test Report 3.11

test_messages.test_message_get

AssertionError: assert ('AM' in '02/05/2025 17:40:31' or 'PM' in '02/05/2025 17:40:31') + where '02/05/2025 17:40:31' = str(<System.DateTime object at 0x7f5ea50da100>) + where <System.DateTime object at 0x7f5ea50da100> = <Ansys.Mechanical.Application.Message object at 0x7f5ea50c5b40>.TimeStamp + and '02/05/2025 17:40:31' = str(<System.DateTime object at 0x7f5ea50d8ec0>) + where <System.DateTime object at 0x7f5ea50d8ec0> = <Ansys.Mechanical.Application.Message object at 0x7f5ea50c5b40>.TimeStamp
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44

assets = PosixPath('/__w/pymechanical/pymechanical/tests/assets')
capsys = <_pytest.capture.CaptureFixture object at 0x7f5ea50c7d10>

    @pytest.mark.embedding
    def test_message_get(embedded_app, assets, capsys):
        """Test getting a message"""
        with pytest.raises(IndexError):
            embedded_app.messages[0]
    
        embedded_app.open(os.path.join(assets, "cube-hole.mechdb"))
        _msg1 = embedded_app.messages[0]
    
        print(embedded_app.messages[0])
        captured = capsys.readouterr()
        printed_output = captured.out.strip()
        assert "Ansys.Mechanical.Application.Message" in printed_output
    
        assert str(_msg1.Severity) == "Warning"
        assert "Image file not found" in _msg1.DisplayString
>       assert "AM" in str(_msg1.TimeStamp) or "PM" in str(_msg1.TimeStamp)
E       AssertionError: assert ('AM' in '02/05/2025 17:40:31' or 'PM' in '02/05/2025 17:40:31')
E        +  where '02/05/2025 17:40:31' = str(<System.DateTime object at 0x7f5ea50da100>)
E        +    where <System.DateTime object at 0x7f5ea50da100> = <Ansys.Mechanical.Application.Message object at 0x7f5ea50c5b40>.TimeStamp
E        +  and   '02/05/2025 17:40:31' = str(<System.DateTime object at 0x7f5ea50d8ec0>)
E        +    where <System.DateTime object at 0x7f5ea50d8ec0> = <Ansys.Mechanical.Application.Message object at 0x7f5ea50c5b40>.TimeStamp

tests/embedding/test_messages.py:113: AssertionError
print(_msg1.StringID, _msg1.Source, _msg1.Location, _msg1.RelatedObjects)
captured = capsys.readouterr()
printed_output = captured.out.strip()
assert "Ansys.ACT.Automation.Mechanical.Image" in printed_output
assert "Ansys.Mechanical.DataModel.Interfaces.IDataModelObject" in printed_output
assert "Ansys.ACT.Core.Utilities.SelectionInf" in printed_output

with pytest.raises(IndexError):
embedded_app.messages[10]
Loading