From 5438b7df0580ea368b38b39e46f11d3a30d12757 Mon Sep 17 00:00:00 2001 From: Dipin <26918585+dipinknair@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:36:55 -0500 Subject: [PATCH 1/7] Feat: Add link check (#693) Co-authored-by: pyansys-ci-bot --- .github/workflows/ci_cd.yml | 3 +++ doc/changelog.d/693.added.md | 1 + 2 files changed, 4 insertions(+) create mode 100644 doc/changelog.d/693.added.md diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 6588764cd..76833e7f0 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -427,6 +427,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: diff --git a/doc/changelog.d/693.added.md b/doc/changelog.d/693.added.md new file mode 100644 index 000000000..aa607b35e --- /dev/null +++ b/doc/changelog.d/693.added.md @@ -0,0 +1 @@ +Feat: Add link check \ No newline at end of file From 3b3a3c766d9762d477fe009ea7ee53d4d5b2bbed Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa Date: Thu, 11 Apr 2024 10:52:53 -0500 Subject: [PATCH 2/7] work around instability in 2024R1 (#695) Co-authored-by: Mohamed Koubaa Co-authored-by: pyansys-ci-bot --- doc/changelog.d/695.fixed.md | 1 + .../mechanical/core/embedding/initializer.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 doc/changelog.d/695.fixed.md diff --git a/doc/changelog.d/695.fixed.md b/doc/changelog.d/695.fixed.md new file mode 100644 index 000000000..54144c5dc --- /dev/null +++ b/doc/changelog.d/695.fixed.md @@ -0,0 +1 @@ +work around instability in 2024R1 \ No newline at end of file diff --git a/src/ansys/mechanical/core/embedding/initializer.py b/src/ansys/mechanical/core/embedding/initializer.py index 8c76ae7c7..8087e31c0 100644 --- a/src/ansys/mechanical/core/embedding/initializer.py +++ b/src/ansys/mechanical/core/embedding/initializer.py @@ -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 @@ -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. @@ -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 @@ -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) From 5144c273df70f5d357e324e478b98d32d14dae4c Mon Sep 17 00:00:00 2001 From: Dipin <26918585+dipinknair@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:20:08 -0500 Subject: [PATCH 3/7] Maint: Add code cov report (#692) Co-authored-by: pyansys-ci-bot --- .github/workflows/ci_cd.yml | 7 +++++++ codecov.yml | 2 -- doc/changelog.d/692.changed.md | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 doc/changelog.d/692.changed.md diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 76833e7f0..759720e97 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -520,6 +520,13 @@ 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 diff --git a/codecov.yml b/codecov.yml index 48f5ccbf3..ee8b84990 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,5 +1,3 @@ -ignore: - comment: layout: "diff" behavior: default diff --git a/doc/changelog.d/692.changed.md b/doc/changelog.d/692.changed.md new file mode 100644 index 000000000..dfb5e7d2d --- /dev/null +++ b/doc/changelog.d/692.changed.md @@ -0,0 +1 @@ +Maint: Add code cov report \ No newline at end of file From 4cabcfe14e05c3d7748c71c68078f0999bfc6ec1 Mon Sep 17 00:00:00 2001 From: Dipin <26918585+dipinknair@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:48:56 -0500 Subject: [PATCH 4/7] Feat: Add reports for remote connect tests (#690) Co-authored-by: pyansys-ci-bot --- .github/workflows/ci_cd.yml | 25 +++++++++++++++++-------- doc/changelog.d/690.added.md | 1 + pyproject.toml | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 doc/changelog.d/690.added.md diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 759720e97..cf0906b15 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -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 @@ -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 @@ -276,7 +285,7 @@ jobs: 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: @@ -446,7 +455,7 @@ jobs: coverage: name: Merging coverage - needs: [tests, embedding-tests, launch-tests] + needs: [remote-connect, embedding-tests, launch-tests] runs-on: ubuntu-latest steps: - name: Checkout repository @@ -530,7 +539,7 @@ jobs: package: name: Package library - needs: [tests, embedding-tests, doc-build] + needs: [smoke-tests, remote-connect, embedding-tests, doc-build] runs-on: ubuntu-latest steps: - name: Build library source and wheel artifacts diff --git a/doc/changelog.d/690.added.md b/doc/changelog.d/690.added.md new file mode 100644 index 000000000..3782dccc2 --- /dev/null +++ b/doc/changelog.d/690.added.md @@ -0,0 +1 @@ +Feat: Add reports for remote connect tests \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 30186e91b..97cee9fc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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""" From 5286c751a8a3c273f586954a67f0dba11a2f0cb1 Mon Sep 17 00:00:00 2001 From: Dipin <26918585+dipinknair@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:01:25 -0500 Subject: [PATCH 5/7] Feat: Add app libraries test (#696) Co-authored-by: pyansys-ci-bot --- doc/changelog.d/696.added.md | 1 + tests/embedding/test_app_libraries.py | 47 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 doc/changelog.d/696.added.md create mode 100644 tests/embedding/test_app_libraries.py diff --git a/doc/changelog.d/696.added.md b/doc/changelog.d/696.added.md new file mode 100644 index 000000000..8047a6314 --- /dev/null +++ b/doc/changelog.d/696.added.md @@ -0,0 +1 @@ +Feat: Add app libraries test \ No newline at end of file diff --git a/tests/embedding/test_app_libraries.py b/tests/embedding/test_app_libraries.py new file mode 100644 index 000000000..0dcff3aab --- /dev/null +++ b/tests/embedding/test_app_libraries.py @@ -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" From 6fb184acbab43c07328bf654db3a46caa9f639f2 Mon Sep 17 00:00:00 2001 From: Kerry McAdams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:59:39 -0400 Subject: [PATCH 6/7] Add embedding_scripts marker (#662) Co-authored-by: Dipin <26918585+dipinknair@users.noreply.github.com> Co-authored-by: pyansys-ci-bot Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/ci_cd.yml | 85 ++++++++++++++++++++++++++++++++-- doc/changelog.d/662.added.md | 1 + pyproject.toml | 1 + tests/conftest.py | 9 +++- tests/embedding/test_app.py | 6 +-- tests/embedding/test_logger.py | 10 ++-- 6 files changed, 99 insertions(+), 13 deletions(-) create mode 100644 doc/changelog.d/662.added.md diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index cf0906b15..f04183ddd 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -208,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 @@ -278,6 +278,80 @@ 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 @@ -455,7 +529,7 @@ jobs: coverage: name: Merging coverage - needs: [remote-connect, embedding-tests, launch-tests] + needs: [remote-connect, embedding-tests, embedding-scripts-tests, launch-tests] runs-on: ubuntu-latest steps: - name: Checkout repository @@ -480,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 @@ -539,7 +618,7 @@ jobs: package: name: Package library - needs: [smoke-tests, remote-connect, 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 diff --git a/doc/changelog.d/662.added.md b/doc/changelog.d/662.added.md new file mode 100644 index 000000000..16d1d3b01 --- /dev/null +++ b/doc/changelog.d/662.added.md @@ -0,0 +1 @@ +Add embedding_scripts marker \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 97cee9fc3..e2087f163 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/tests/conftest.py b/tests/conftest.py index a3f157b03..f495e8042 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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( diff --git a/tests/embedding/test_app.py b/tests/embedding/test_app.py index ac05e1b5f..da79ea49b 100644 --- a/tests/embedding/test_app.py +++ b/tests/embedding/test_app.py @@ -161,7 +161,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.""" @@ -190,7 +190,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.""" @@ -204,7 +204,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.""" diff --git a/tests/embedding/test_logger.py b/tests/embedding/test_logger.py index 9da992c21..4a8d2f2e5 100644 --- a/tests/embedding/test_logger.py +++ b/tests/embedding/test_logger.py @@ -98,7 +98,7 @@ def _run_embedding_log_test( return stderr -@pytest.mark.embedding +@pytest.mark.embedding_scripts def test_logging_write_log_before_init(rootdir, run_subprocess, pytestconfig): """Test that an error is thrown when trying to log before initializing""" stderr = _run_embedding_log_test( @@ -107,7 +107,7 @@ def test_logging_write_log_before_init(rootdir, run_subprocess, pytestconfig): assert "Can't log to the embedding logger until Mechanical is initialized" in stderr -@pytest.mark.embedding +@pytest.mark.embedding_scripts def test_logging_write_info_after_initialize_with_error_level( rootdir, run_subprocess, pytestconfig ): @@ -119,7 +119,7 @@ def test_logging_write_info_after_initialize_with_error_level( @pytest.mark.parametrize("addin_configuration", ["Mechanical", "WorkBench"]) -@pytest.mark.embedding +@pytest.mark.embedding_scripts @pytest.mark.minimum_version(241) def test_addin_configuration(rootdir, run_subprocess, pytestconfig, addin_configuration): """Test that mechanical can start with both the Mechanical and WorkBench configuration.""" @@ -129,7 +129,7 @@ def test_addin_configuration(rootdir, run_subprocess, pytestconfig, addin_config assert f"{addin_configuration} configuration!" in stderr -@pytest.mark.embedding +@pytest.mark.embedding_scripts def test_logging_write_error_after_initialize_with_info_level( rootdir, run_subprocess, pytestconfig ): @@ -140,7 +140,7 @@ def test_logging_write_error_after_initialize_with_info_level( assert "Will no one rid me of this turbulent priest?" in stderr -@pytest.mark.embedding +@pytest.mark.embedding_scripts def test_logging_level_before_and_after_initialization(rootdir, run_subprocess, pytestconfig): """Test logging level API before and after initialization.""" stdout, stderr = _run_embedding_log_test_process( From c21f35c115aa0c56fa3fab06c5d0d7ed763775af Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot Date: Thu, 11 Apr 2024 23:30:10 +0000 Subject: [PATCH 7/7] Adding changelog entry: 700.miscellaneous.md --- doc/changelog.d/700.miscellaneous.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/700.miscellaneous.md diff --git a/doc/changelog.d/700.miscellaneous.md b/doc/changelog.d/700.miscellaneous.md new file mode 100644 index 000000000..422a843f8 --- /dev/null +++ b/doc/changelog.d/700.miscellaneous.md @@ -0,0 +1 @@ +Test: add log all level \ No newline at end of file