Skip to content

Commit

Permalink
MAINT: Update shims.material_import (#837)
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 Jul 29, 2024
1 parent ba8c98e commit 4b05b5a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/837.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MAINT: Update ``shims.material_import``
15 changes: 8 additions & 7 deletions src/ansys/mechanical/core/embedding/shims.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
These shims are used when APIs are released in newer versions of Mechanical,
but workarounds exist in an older release
"""
import warnings


def import_materials(
app: "ansys.mechanical.core.embedding.Application", material_file: str
) -> None:
"""Import material from matml file."""
if app._version >= 232:
materials = app.DataModel.Project.Model.Materials
materials.Import(material_file)
else: # pragma: no cover
material_file = material_file.replace("\\", "\\\\")
script = 'DS.Tree.Projects.Item(1).LoadEngrDataLibraryFromFile("' + material_file + '");'
app.ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(script)
warnings.warn(
"Use of this function is deprecated. Use Model.Materials.Import() directly.",
DeprecationWarning,
stacklevel=2,
)
materials = app.DataModel.Project.Model.Materials
materials.Import(material_file)
11 changes: 11 additions & 0 deletions tests/embedding/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ def test_building_gallery(pytestconfig, run_subprocess, rootdir):
assert "Multiple App launched with building gallery flag on" in stdout


@pytest.mark.embedding
def test_shims_import_material(embedded_app, assets):
"""Test deprecation warning for shims import material."""
from ansys.mechanical.core.embedding import shims

embedded_app.update_globals(globals())
material_file = os.path.join(assets, "eng200_material.xml")
with pytest.warns(DeprecationWarning):
shims.import_materials(embedded_app, material_file)


@pytest.mark.embedding
def test_rm_lockfile(embedded_app, tmp_path: pytest.TempPathFactory):
"""Test lock file is removed on close of embedded application."""
Expand Down
5 changes: 2 additions & 3 deletions tests/embedding/test_qk_eng_wb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

import pytest

from ansys.mechanical.core.embedding import shims


def is_on_docker():
"""check if running in docker image 25R1."""
Expand Down Expand Up @@ -133,7 +131,8 @@ def test_qk_eng_wb2_007(printer, selection, embedded_app, assets):
geometry_import.Import(geometry_file)
material_file = os.path.join(assets, "eng200_material.xml")
printer(f"Setting up test - import materials {material_file}")
shims.import_materials(embedded_app, material_file)
materials = Model.Materials
materials.Import(material_file)

def _innertest():
printer("Add material file")
Expand Down

0 comments on commit 4b05b5a

Please sign in to comment.