Skip to content

Commit

Permalink
Merge branch 'test/logger' of https://github.com/ansys/pymechanical i…
Browse files Browse the repository at this point in the history
…nto test/logger
  • Loading branch information
dipinknair committed Apr 12, 2024
2 parents b6733d1 + 4e73ac1 commit c251610
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 24 deletions.
116 changes: 107 additions & 9 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ jobs:
echo "matrix={\"mechanical-version\":['${{ needs.revn-variations.outputs.test_docker_image_version }}'],\"experimental\":[false]}" >> $GITHUB_OUTPUT
fi
tests:
name: Testing and coverage - Mechanical ${{ matrix.mechanical-version }}
remote-connect:
name: Remote connect testing and coverage - Mechanical ${{ matrix.mechanical-version }}
runs-on: public-ubuntu-latest-8-cores
needs: [smoke-tests, revn-variations, config-matrix]
needs: [style, revn-variations, config-matrix]
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
Expand All @@ -158,9 +158,18 @@ jobs:
uses: ansys/actions/tests-pytest@v5
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
pytest-markers: '-m remote_session_connect'
pytest-extra-args: '-s --junitxml remote_results${{ env.MAIN_PYTHON_VERSION}}.xml'

# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v3
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: always()
with:
report_paths: '**/remote_results*.xml'
check_name: Remote Connect Test Report ${{ env.MAIN_PYTHON_VERSION}}
detailed_summary: true
include_passed: true
fail_on_failure: true

- name: Upload coverage results
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -199,7 +208,7 @@ jobs:
name: Embedding testing and coverage
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [style, revn-variations]
needs: [smoke-tests, revn-variations]
container:
image: ${{ needs.revn-variations.outputs.test_container }}
options: --entrypoint /bin/bash
Expand Down Expand Up @@ -269,14 +278,88 @@ jobs:
include_passed: true
fail_on_failure: true

embedding-scripts-tests:
name: Embedding scripts testing and coverage
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [smoke-tests, revn-variations]
container:
image: ${{ needs.revn-variations.outputs.test_container }}
options: --entrypoint /bin/bash
strategy:
fail-fast: false
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
- name: Set up python and pip
run: |
apt update
apt install --reinstall ca-certificates
apt install lsb-release xvfb software-properties-common -y
add-apt-repository ppa:deadsnakes/ppa -y
apt install -y python${{ matrix.python-version }} python${{ matrix.python-version }}-venv
python${{ matrix.python-version }} -m venv /env
- name: Install dependencies
run: |
. /env/bin/activate
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org pip setuptools
pip install --upgrade pip flit
- name: Install packages for testing
run: |
. /env/bin/activate
pip install -e .[tests]
- name: Embedding scripts unit testing and coverage
env:
LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
ANSYSLMD_LICENSE_FILE: 1055@${{ secrets.LICENSE_SERVER }}
ANSYS_WORKBENCH_LOGGING_CONSOLE: 0
ANSYS_WORKBENCH_LOGGING: 0
ANSYS_WORKBENCH_LOGGING_FILTER_LEVEL: 2
NUM_CORES: 1
PYTHONUNBUFFERED: 1
run: |
. /env/bin/activate
mechanical-env pytest -m embedding_scripts -s --junitxml test_results_embedding_scripts${{ matrix.python-version }}.xml
- name: Upload coverage results
uses: actions/upload-artifact@v4
if: env.MAIN_PYTHON_VERSION == matrix.python-version
with:
name: coverage-tests-embedding-scripts
path: .cov
retention-days: 7

- name: Upload coverage results (as .coverage)
uses: actions/upload-artifact@v4
if: env.MAIN_PYTHON_VERSION == matrix.python-version
with:
name: coverage-file-tests-embedding-scripts
path: .coverage
retention-days: 7

- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: always()
with:
report_paths: '**/test_results*.xml'
check_name: Test Report ${{ matrix.python-version }}
detailed_summary: true
include_passed: true
fail_on_failure: true

launch-tests:
name: Launch testing and coverage
runs-on: public-ubuntu-latest-8-cores
timeout-minutes: 15
container:
image: ${{ needs.revn-variations.outputs.test_container }}
options: --entrypoint /bin/bash
needs: [ smoke-tests, revn-variations]
needs: [ style, revn-variations]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -427,6 +510,9 @@ jobs:
# Make the pdf doc & validate results
make_doc pdf
# Make the pdf doc & validate results
make_doc linkcheck
- name: Upload HTML Documentation
uses: actions/upload-artifact@v4
with:
Expand All @@ -443,7 +529,7 @@ jobs:

coverage:
name: Merging coverage
needs: [tests, embedding-tests, launch-tests]
needs: [remote-connect, embedding-tests, embedding-scripts-tests, launch-tests]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -468,6 +554,11 @@ jobs:
name: coverage-file-tests-embedding
path: cov-dir/embedding

- uses: actions/download-artifact@v4
with:
name: coverage-file-tests-embedding-scripts
path: cov-dir/embedding-scripts

- uses: actions/download-artifact@v4
with:
name: coverage-file-tests-remote-session-launch
Expand Down Expand Up @@ -517,10 +608,17 @@ jobs:
name: combined-coverage-results
path: .coverage-combined
retention-days: 7
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: .coverage-combined/xml


package:
name: Package library
needs: [tests, embedding-tests, doc-build]
needs: [smoke-tests, remote-connect, embedding-tests, embedding-scripts-tests, doc-build]
runs-on: ubuntu-latest
steps:
- name: Build library source and wheel artifacts
Expand Down
2 changes: 0 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ignore:

comment:
layout: "diff"
behavior: default
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/662.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add embedding_scripts marker
1 change: 1 addition & 0 deletions doc/changelog.d/690.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feat: Add reports for remote connect tests
1 change: 1 addition & 0 deletions doc/changelog.d/692.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Maint: Add code cov report
1 change: 1 addition & 0 deletions doc/changelog.d/693.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feat: Add link check
1 change: 1 addition & 0 deletions doc/changelog.d/695.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
work around instability in 2024R1
1 change: 1 addition & 0 deletions doc/changelog.d/696.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feat: Add app libraries test
1 change: 1 addition & 0 deletions doc/changelog.d/700.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test: add log all level
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ output = ".cov/coverage.xml"

[tool.pytest.ini_options]
minversion = "7.1"
addopts = """-ra -s -m remote_session_connect --durations=0 --cov=ansys.mechanical --cov-report html:.cov/html \
addopts = """-ra -s --durations=0 --cov=ansys.mechanical --cov-report html:.cov/html \
--cov-report xml:.cov/xml --cov-report term -vv --print --print-relative-time"""
# addopts = """-ra -s -m remote_session_launch --durations=0 --cov=ansys.mechanical --cov-report html:.cov/html \
# --cov-report xml:.cov/xml --cov-report term -vv --print --print-relative-time"""
Expand All @@ -130,6 +130,7 @@ testpaths = [
]
markers = [
"embedding: tests that embed Mechanical in the python process",
"embedding_scripts: embedding tests that use subprocess",
"python_env: tests that check for an appropriate python environment",
"remote_session_launch: tests that launch Mechanical and work with gRPC server inside it",
"remote_session_connect: tests that connect to Mechanical and work with gRPC server inside it",
Expand Down
19 changes: 17 additions & 2 deletions src/ansys/mechanical/core/embedding/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
SUPPORTED_MECHANICAL_EMBEDDING_VERSIONS_WINDOWS = {241: "2024R1", 232: "2023R2", 231: "2023R1"}


def __add_sys_path(version) -> str:
def __add_sys_path(version: int) -> str:
install_path = Path(os.environ[f"AWP_ROOT{version}"])
platform_string = "winx64" if os.name == "nt" else "linx64"
bin_path = install_path / "aisol" / "bin" / platform_string
Expand All @@ -52,6 +52,19 @@ def __disable_sec() -> None:
os.environ["ANSYS_MECHANICAL_EMBEDDING_NO_SEC"] = "1"


def __workaround_material_server(version: int) -> None:
"""Workaround material server bug in 2024 R1.
A REST server is used as a backend for the material model GUI.
In 2024 R1, this GUI is used even in batch mode. The server
starts by default on a background thread, which may lead to
a race condition on shutdown.
"""
# TODO - remove 242 when that is fixed
if version in [241, 242]:
os.environ["ENGRDATA_SERVER_SERIAL"] = "1"


def _get_default_linux_version() -> int:
"""Try to get the active linux version from the environment.
Expand Down Expand Up @@ -96,7 +109,7 @@ def __check_python_interpreter_architecture():
raise Exception("Mechanical Embedding requires a 64-bit Python environment.")


def initialize(version=None):
def initialize(version: int = None):
"""Initialize Mechanical embedding."""
__check_python_interpreter_architecture() # blocks 32 bit python

Expand All @@ -112,6 +125,8 @@ def initialize(version=None):

__disable_sec()

__workaround_material_server(version)

# need to add system path in order to import the assembly with the resolver
__add_sys_path(version)

Expand Down
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ def pytest_collection_modifyitems(config, items):

# skip embedding tests unless the mark is specified
skip_embedding = pytest.mark.skip(
reason="embedding not selected for pytest run (`pytest -m embedding`). Skip by default"
reason="""embedding not selected for pytest run
(`pytest -m embedding` or `pytest -m embedding_scripts`). Skip by default"""
)
[item.add_marker(skip_embedding) for item in items if "embedding" in item.keywords]
[
item.add_marker(skip_embedding)
for item in items
if ("embedding" or "embedding_scripts") in item.keywords
]

# TODO - skip python_env tests unless the mark is specified. (The below doesn't work!)
# skip_python_env = pytest.mark.skip(
Expand Down
6 changes: 3 additions & 3 deletions tests/embedding/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_app_getters_notstale(embedded_app):
assert model.Name != "b"


@pytest.mark.embedding
@pytest.mark.embedding_scripts
@pytest.mark.python_env
def test_warning_message(test_env, pytestconfig, run_subprocess, rootdir):
"""Test Python.NET warning of the embedded instance using a test-scoped Python environment."""
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_warning_message(test_env, pytestconfig, run_subprocess, rootdir):
assert warning, "UserWarning should appear in the output of the script"


@pytest.mark.embedding
@pytest.mark.embedding_scripts
@pytest.mark.python_env
def test_private_appdata(pytestconfig, run_subprocess, rootdir):
"""Test embedded instance does not save ShowTriad using a test-scoped Python environment."""
Expand All @@ -222,7 +222,7 @@ def test_private_appdata(pytestconfig, run_subprocess, rootdir):
assert "ShowTriad value is True" in stdout


@pytest.mark.embedding
@pytest.mark.embedding_scripts
@pytest.mark.python_env
def test_normal_appdata(pytestconfig, run_subprocess, rootdir):
"""Test embedded instance saves ShowTriad value using a test-scoped Python environment."""
Expand Down
47 changes: 47 additions & 0 deletions tests/embedding/test_app_libraries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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.

"""Testing app libraries"""

import os
import sys

from ansys.tools.path.path import _get_unified_install_base_for_version
import pytest

from ansys.mechanical.core.embedding import add_mechanical_python_libraries


@pytest.mark.embedding
def test_app_library(embedded_app):
"""Loads one of the libraries and calls a method."""
add_mechanical_python_libraries(embedded_app.version)
install, _ = _get_unified_install_base_for_version(embedded_app.version)
location = os.path.join(install, "Addins", "ACT", "libraries", "Mechanical")
assert location in sys.path

# import mechanical library and test a method

from mechanical import AnalysisTypeName

analysis_name = AnalysisTypeName(0)
assert analysis_name == "Static"
Loading

0 comments on commit c251610

Please sign in to comment.