Skip to content

Commit 3fc1880

Browse files
authored
Add unit tests for setup from different analysis. (#889)
* Add unit test for the Maxwell setup_ctrlprog with file. * Add test for the linear step sweeep in HFSS 3d layout. * Error message corrected. * Fix typo. * Unit tests are not supposed to be covered by coverage. They are use as a base. * Fix typo. * Re-initialize code coverage. * Reinstate maxwell test for code coverage. * Rename setup as transient_setup. * Add unit test for Q3D discrete sweep. * Remove tmpdir. * Add unit test for mechanical fixed support. * Reinstate tmpdir. * Do not use tempdir pytest fixture. It creates conflict with code coverage. * Fix typo. * Use TemporaryFile. * Remove the modifications to the .coveragerc.
1 parent 75c6236 commit 3fc1880

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

_unittest/test_28_Maxwell3D.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Setup paths for module imports
22
from _unittest.conftest import scratch_path, local_path
33
import os
4+
import tempfile
45

56
# Import required modules
67
from pyaedt import Maxwell3d
@@ -99,6 +100,20 @@ def test_07_setup(self):
99100
assert Setup.enable()
100101
assert self.aedtapp.setup_ctrlprog(Setup.name)
101102

103+
def test_08_setup_ctrlprog_with_file(self):
104+
transient_setup = self.aedtapp.create_setup()
105+
transient_setup.props["MaximumPasses"] = 12
106+
transient_setup.props["MinimumPasses"] = 2
107+
transient_setup.props["MinimumConvergedPasses"] = 1
108+
transient_setup.props["PercentRefinement"] = 30
109+
transient_setup.props["Frequency"] = "200Hz"
110+
transient_setup.update()
111+
transient_setup.enable_expression_cache(["CoreLoss"], "Fields", "Phase='0deg' ", True)
112+
113+
# Test the creation of the control program file
114+
with tempfile.TemporaryFile("w+") as fp:
115+
assert self.aedtapp.setup_ctrlprog(transient_setup.name, file_str=fp.name)
116+
102117
def test_22_create_length_mesh(self):
103118
assert self.aedtapp.mesh.assign_length_mesh(["Plate"])
104119

_unittest/test_29_Mechanical.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def test_07_assign_mechanical_boundaries(self):
9090
assert mech.assign_fixed_support(mech.modeler["MyCylinder"].faces[0].id)
9191
assert mech.assign_frictionless_support(mech.modeler["MyCylinder"].faces[1].id)
9292

93+
mech = Mechanical(solution_type=self.aedtapp.SOLUTIONS.Mechanical.Thermal)
94+
assert not mech.assign_fixed_support(mech.modeler["MyCylinder"].faces[0].id)
95+
assert not mech.assign_frictionless_support(mech.modeler["MyCylinder"].faces[0].id)
96+
9397
def test_08_mesh_settings(self):
9498
assert self.aedtapp.mesh.initial_mesh_settings
9599
assert self.aedtapp.mesh.initial_mesh_settings.props

_unittest/test_31_Q3D.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def test_06a_create_setup(self):
5353
assert sweep
5454
assert sweep.props["RangeStart"] == "1GHz"
5555

56+
# Create a discrete sweep with the same name of an existing sweep is not possible.
57+
assert not self.aedtapp.create_discrete_sweep(mysetup.name, sweepname="mysweep", freqstart=1, units="GHz")
58+
5659
def test_06b_create_setup(self):
5760
mysetup = self.aedtapp.create_setup()
5861
mysetup.props["SaveFields"] = True

_unittest/test_41_3dlayout_modeler.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,23 @@ def test_18b_create_linear_step_sweep(self):
292292
)
293293
assert sweep4.props["Sweeps"]["Data"] == "LIN 1GHz 10GHz 0.12GHz"
294294

295+
# Create a linear step sweep with the incorrect sweep type.
296+
try:
297+
sweep_raising_error = self.aedtapp.create_linear_step_sweep(
298+
setupname=setup_name,
299+
unit="GHz",
300+
freqstart=1,
301+
freqstop=10,
302+
step_size=0.12,
303+
sweepname="RFBoardSweep4",
304+
sweep_type="Incorrect",
305+
save_fields=True,
306+
)
307+
except AttributeError as e:
308+
exception_raised = True
309+
assert e.args[0] == "Invalid in `sweep_type`. It has to be either 'Discrete', 'Interpolating', or 'Fast'"
310+
assert exception_raised
311+
295312
def test_18c_create_single_point_sweep(self):
296313
setup_name = "RFBoardSetup"
297314
sweep5 = self.aedtapp.create_single_point_sweep(

0 commit comments

Comments
 (0)