Skip to content

Commit

Permalink
FEAT: Add tests for transaction (#985)
Browse files Browse the repository at this point in the history
Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
dipinknair and pyansys-ci-bot authored Nov 21, 2024
1 parent af612b6 commit 919ffd2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/985.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add tests for transaction
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ markers = [
"windows_only: tests that run if the testing platform is on Windows",
"linux_only: tests that run if the testing platform is on Linux",
"cli: tests for the Command Line Interface",
"embedding_backgroundapp: tests for the BackgroundApp",
"embedding_logging: tests for the logging with Embedded App",
]
xfail_strict = true

Expand Down
8 changes: 4 additions & 4 deletions tests/embedding/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,17 @@ def test_warning_message(test_env, pytestconfig, run_subprocess, rootdir):
# Install pythonnet
subprocess.check_call([test_env.python, "-m", "pip", "install", "pythonnet"], env=test_env.env)

# Run embedded instance in virtual env with pythonnet installed
embedded_py = os.path.join(rootdir, "tests", "scripts", "run_embedded_app.py")
# Initialize with pythonnet
embedded_pythonnet_py = os.path.join(rootdir, "tests", "scripts", "pythonnet_warning.py")
process, stdout, stderr = run_subprocess(
[test_env.python, embedded_py, pytestconfig.getoption("ansys_version")]
[test_env.python, embedded_pythonnet_py, pytestconfig.getoption("ansys_version")]
)

# If UserWarning & pythonnet are in the stderr output, set warning to True.
# Otherwise, set warning to False
warning = True if "UserWarning" and "pythonnet" in stderr.decode() else False

# Assert warning message appears for embedded app
# # Assert warning message appears for embedded app
assert warning, "UserWarning should appear in the output of the script"


Expand Down
12 changes: 12 additions & 0 deletions tests/embedding/test_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import pytest

from ansys.mechanical.core import global_variables
from ansys.mechanical.core.embedding.imports import Transaction


@pytest.mark.embedding
Expand All @@ -50,3 +51,14 @@ def test_global_variables(embedded_app):
globals_dict = global_variables(embedded_app, True)
for attribute in attributes:
assert attribute in globals_dict


@pytest.mark.embedding
def test_global_variable_transaction(embedded_app):
embedded_app.update_globals(globals())
project_name = DataModel.Project.Name
assert project_name == "Project"
with Transaction():
DataModel.Project.Name = "New Project"
project_name = DataModel.Project.Name
assert project_name == "New Project"
30 changes: 30 additions & 0 deletions tests/scripts/pythonnet_warning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (C) 2022 - 2024 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.

"""Test script for checking pythonnet warning."""
import sys

from ansys.mechanical.core.embedding import initializer

if __name__ == "__main__":
version = int(sys.argv[1])
initializer.initialize(version)

0 comments on commit 919ffd2

Please sign in to comment.