Skip to content

Commit

Permalink
Merge branch 'main' into fix_ami_report
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys authored Oct 1, 2024
2 parents 69959e2 + 78edb45 commit 2d709bc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
32 changes: 32 additions & 0 deletions _unittest/test_03_Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,38 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import builtins
import logging
import os
from unittest.mock import mock_open

from _unittest.conftest import config
from _unittest.conftest import local_path
from ansys.aedt.core import Icepak
from ansys.aedt.core import Maxwell3d
from ansys.aedt.core.modules.material import MatProperties
from ansys.aedt.core.modules.material import SurfMatProperties
from mock import patch
import pytest

test_subfolder = "T03"

MISSING_RGB_MATERIALS = b"""
{
"materials": {
"copper_5540": {
"AttachedData": {
"MatAppearanceData": {
"property_data": "appearance_data"
}
},
"permeability": "0.999991",
"conductivity": "58000000"
}
}
}
"""


@pytest.fixture(scope="class")
def aedtapp(add_app):
Expand Down Expand Up @@ -527,3 +547,15 @@ def test_16_import_materials_from_workbench(self):
self.testapp2.materials.material_keys["84zn_12ag_4au_imp"].thermal_expansion_coefficient.thermalmodifier
== "pwl($TM_84Zn_12Ag_4Au_imp_thermal_expansion_coefficient, Temp)"
)

@patch.object(builtins, "open", new_callable=mock_open, read_data=MISSING_RGB_MATERIALS)
def test_17_json_missing_rgb(self, _mock_file_open, caplog: pytest.LogCaptureFixture):
input_path = os.path.join(local_path, "example_models", test_subfolder, "mats.json")
with pytest.raises(KeyError):
self.aedtapp.materials.import_materials_from_file(input_path)
assert [
record
for record in caplog.records
if record.levelno == logging.ERROR
and record.message == f"Failed to import material 'copper_5540' from {input_path!r}: key error on 'Red'"
]
14 changes: 9 additions & 5 deletions src/ansys/aedt/core/modules/material_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,15 @@ def import_materials_from_file(self, input_file=None, **kwargs):
self.logger.warning("Material %s already exists. Renaming to %s", el, newname)
else:
newname = el
newmat = Material(self, newname, val, material_update=False)
newmat.update()
newmat._material_update = True
self.material_keys[newname] = newmat
materials_added.append(newmat)
try:
newmat = Material(self, newname, val, material_update=False)
newmat.update()
newmat._material_update = True
self.material_keys[newname] = newmat
materials_added.append(newmat)
except KeyError as e:
self.logger.error(f"Failed to import material {el!r} from {input_file!r}: key error on {e}")
raise e
else:
for mat_name in data:
invalid_names = ["$base_index$", "$index$"]
Expand Down

0 comments on commit 2d709bc

Please sign in to comment.