Skip to content

Commit

Permalink
Merge branch 'main' into release/0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys committed May 3, 2024
2 parents 43a7216 + 004e327 commit bd071c9
Show file tree
Hide file tree
Showing 106 changed files with 3,872 additions and 1,839 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude: |
repos:
- repo: https://github.com/psf/black
rev: 24.4.0 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
rev: 24.4.2 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
hooks:
- id: black
args:
Expand Down Expand Up @@ -56,7 +56,7 @@ repos:
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==24.4.0]
additional_dependencies: [black==24.4.2]

# This validates our pre-commit.ci configuration
- repo: https://github.com/pre-commit-ci/pre-commit-ci-config
Expand Down
17 changes: 10 additions & 7 deletions _unittest/test_01_Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
from pyaedt import Hfss3dLayout
from pyaedt import Icepak
from pyaedt import get_pyaedt_app
from pyaedt.application.Design import DesignSettings
from pyaedt.application.aedt_objects import AedtObjects
from pyaedt.application.design_solutions import model_names
from pyaedt.generic.general_methods import is_linux
from pyaedt.generic.general_methods import settings
from pyaedt.workflows import customize_automation_tab

test_subfolder = "T01"
if config["desktopVersion"] > "2022.2":
Expand Down Expand Up @@ -397,17 +399,18 @@ def test_36_test_load(self, add_app):
assert True

def test_37_add_custom_toolkit(self, desktop):
assert desktop.get_available_toolkits()
assert customize_automation_tab.available_toolkits

def test_38_toolkit(self, desktop):
file = os.path.join(self.local_scratch.path, "test.py")
with open(file, "w") as f:
f.write("import pyaedt\n")
assert desktop.add_script_to_menu(
"test_toolkit",
file,
assert customize_automation_tab.add_script_to_menu(
desktop_object=self.aedtapp.desktop_class, name="test_toolkit", script_file=file
)
assert customize_automation_tab.remove_script_from_menu(
desktop_object=self.aedtapp.desktop_class, name="test_toolkit"
)
assert desktop.remove_script_from_menu("test_toolkit")

def test_39_load_project(self, desktop):
new_project = os.path.join(self.local_scratch.path, "new.aedt")
Expand All @@ -418,9 +421,9 @@ def test_39_load_project(self, desktop):

def test_40_get_design_settings(self, add_app):
ipk = add_app(application=Icepak)
design_settings_dict = ipk.design_settings()
design_settings_dict = ipk.design_settings

assert isinstance(design_settings_dict, dict)
assert isinstance(design_settings_dict, DesignSettings)
assert "AmbTemp" in design_settings_dict
assert "AmbRadTemp" in design_settings_dict
assert "GravityVec" in design_settings_dict
Expand Down
34 changes: 18 additions & 16 deletions _unittest/test_01_toolkit_icons.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import os
import xml.etree.ElementTree as ET

import defusedxml.ElementTree as ET
import defusedxml.minidom

defusedxml.defuse_stdlib()


import pytest

from pyaedt.misc.aedtlib_personalib_install import write_tab_config
from pyaedt.workflows.customize_automation_tab import add_automation_tab


@pytest.fixture(scope="module", autouse=True)
Expand All @@ -17,8 +22,7 @@ def init(self, local_scratch):
self.local_scratch = local_scratch

def test_00_write_new_xml(self):
file_path = os.path.join(self.local_scratch.path, "TabConfig.xml")
write_tab_config(os.path.dirname(file_path), self.local_scratch.path)
file_path = add_automation_tab(name="Test", lib_dir=self.local_scratch.path)
root = self.validate_file_exists_and_pyaedt_tabs_added(file_path)
panels = root.findall("./panel")
panel_names = [panel.attrib["label"] for panel in panels]
Expand All @@ -29,7 +33,7 @@ def test_01_add_pyaedt_config_to_existing_existing_xml(self):
First write a dummy XML with a different Panel and then add PyAEDT's tabs
:return:
"""
file_path = os.path.join(self.local_scratch.path, "TabConfig.xml")
file_path = os.path.join(self.local_scratch.path, "Project", "TabConfig.xml")
with open(file_path, "w") as fid:
fid.write(
"""<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
Expand All @@ -47,15 +51,15 @@ def test_01_add_pyaedt_config_to_existing_existing_xml(self):
"""
)

write_tab_config(os.path.dirname(file_path), self.local_scratch.path)
file_path = add_automation_tab(name="Test", lib_dir=self.local_scratch.path)
root = self.validate_file_exists_and_pyaedt_tabs_added(file_path)
panels = root.findall("./panel")
panel_names = [panel.attrib["label"] for panel in panels]
assert len(panel_names) == 2
assert "Panel_1" in panel_names

def test_03_overwrite_existing_pyaedt_config(self):
file_path = os.path.join(self.local_scratch.path, "TabConfig.xml")
file_path = os.path.join(self.local_scratch.path, "Project", "TabConfig.xml")
with open(file_path, "w") as fid:
fid.write(
"""<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
Expand All @@ -72,14 +76,14 @@ def test_03_overwrite_existing_pyaedt_config(self):
</TabConfig>
"""
)
write_tab_config(os.path.dirname(file_path), self.local_scratch.path)
file_path = add_automation_tab(name="Test", lib_dir=self.local_scratch.path)
root = self.validate_file_exists_and_pyaedt_tabs_added(file_path)
panels = root.findall("./panel")
panel_names = [panel.attrib["label"] for panel in panels]
assert len(panel_names) == 1
assert len(panel_names) == 2

def test_04_write_to_existing_file_but_no_panels(self):
file_path = os.path.join(self.local_scratch.path, "TabConfig.xml")
file_path = os.path.join(self.local_scratch.path, "Project", "TabConfig.xml")
with open(file_path, "w") as fid:
fid.write(
"""<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
Expand All @@ -88,7 +92,7 @@ def test_04_write_to_existing_file_but_no_panels(self):
</TabConfig>
"""
)
write_tab_config(os.path.dirname(file_path), self.local_scratch.path)
file_path = add_automation_tab(name="Test", lib_dir=self.local_scratch.path)
root = self.validate_file_exists_and_pyaedt_tabs_added(file_path)
junks = root.findall("./junk")
junk_names = [junk.attrib["label"] for junk in junks]
Expand All @@ -98,15 +102,13 @@ def test_04_write_to_existing_file_but_no_panels(self):
panel_names = [panel.attrib["label"] for panel in panels]
assert len(panel_names) == 1

def validate_file_exists_and_pyaedt_tabs_added(self, file_path):
@staticmethod
def validate_file_exists_and_pyaedt_tabs_added(file_path):
assert os.path.isfile(file_path) is True
assert ET.parse(file_path) is not None
tree = ET.parse(file_path)
root = tree.getroot()
panels = root.findall("./panel")
panel_names = [panel.attrib["label"] for panel in panels]
assert "Panel_PyAEDT" in panel_names
files_to_verify = ["images/large/pyansys.png", "images/gallery/PyAEDT.png"]
for file_name in files_to_verify:
assert os.path.isfile(os.path.join(os.path.dirname(file_path), file_name))
assert "Panel_PyAEDT_Toolkits" in panel_names
return root
5 changes: 3 additions & 2 deletions _unittest/test_08_Primitives3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ def test_83_cover_face(self):
o1 = self.aedtapp.modeler.create_circle(cs_plane=0, position=[0, 0, 0], radius=10)
assert self.aedtapp.modeler.cover_faces(o1)

def test_84_replace_3dcomponent(self):
def test_84_replace_3d_component(self):
self.aedtapp["test_variable"] = "20mm"
box1 = self.aedtapp.modeler.create_box([0, 0, 0], [10, "test_variable", 30])
box2 = self.aedtapp.modeler.create_box([0, 0, 0], ["test_variable", 100, 30])
Expand All @@ -1782,7 +1782,8 @@ def test_84_replace_3dcomponent(self):
assert len(self.aedtapp.modeler.user_defined_components) == 2

@pytest.mark.skipif(config["desktopVersion"] < "2023.1", reason="Method available in beta from 2023.1")
def test_85_insert_layoutcomponent(self):
@pytest.mark.skipif(is_linux, reason="EDB object is not loaded")
def test_85_insert_layout_component(self):
self.aedtapp.insert_design("LayoutComponent")
self.aedtapp.solution_type = "Modal"
assert not self.aedtapp.modeler.insert_layout_component(
Expand Down
8 changes: 6 additions & 2 deletions _unittest/test_09_Primitives2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ def test_06_create_region(self):
if self.aedtapp.modeler["Region"]:
self.aedtapp.modeler.delete("Region")
assert "Region" not in self.aedtapp.modeler.object_names
assert self.aedtapp.modeler.create_region([20, "50", "100mm", 20], False)
assert self.aedtapp.modeler.create_region([20, "50", "100mm", 20], "Absolute Offset")
self.aedtapp.modeler["Region"].delete()
region = self.aedtapp.modeler.create_region("100", True)
region = self.aedtapp.modeler.create_region("100", "Percentage Offset")
region.delete()
# test backward compatibility
region = self.aedtapp.modeler.create_region(pad_percent=[100, 10, 5, 2], pad_type=True)
region.delete()
#
region = self.aedtapp.modeler.create_region([100, 100, 100, 100])
assert region.solve_inside
assert region.model
Expand Down
8 changes: 4 additions & 4 deletions _unittest/test_09_VariableManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ def test_07_addition(self):
v2 = Variable(3)
v3 = Variable("3mA")
v4 = Variable("10A")
with pytest.raises(AssertionError):
with pytest.raises(ValueError):
v1 + v2

with pytest.raises(AssertionError):
with pytest.raises(ValueError):
v2 + v1
result_1 = v2 + v2
result_2 = v3 + v4
Expand All @@ -278,10 +278,10 @@ def test_08_subtraction(self):
v3 = Variable("3mA")
v4 = Variable("10A")

with pytest.raises(AssertionError):
with pytest.raises(ValueError):
v1 - v2

with pytest.raises(AssertionError):
with pytest.raises(ValueError):
v2 - v1

result_1 = v2 - v2
Expand Down
Loading

0 comments on commit bd071c9

Please sign in to comment.