Skip to content

Commit

Permalink
CHORE: Use f-string instead of format (#5272)
Browse files Browse the repository at this point in the history
Co-authored-by: Sébastien Morais <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Abdun Nur <[email protected]>
Co-authored-by: Sebastien Morais <[email protected]>
  • Loading branch information
5 people authored Oct 22, 2024
1 parent 3ca765f commit c4e8562
Show file tree
Hide file tree
Showing 111 changed files with 1,053 additions and 1,122 deletions.
4 changes: 2 additions & 2 deletions _unittest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ def init_scratch():
try:
os.makedirs(test_folder, mode=0o777)
except FileExistsError as e:
print("Failed to create {}. Reason: {}".format(test_folder, e))
print(f"Failed to create {test_folder}. Reason: {e}")

yield test_folder

try:
shutil.rmtree(test_folder, ignore_errors=True)
except Exception as e:
print("Failed to delete {}. Reason: {}".format(test_folder, e))
print(f"Failed to delete {test_folder}. Reason: {e}")


@pytest.fixture(scope="module", autouse=True)
Expand Down
4 changes: 1 addition & 3 deletions _unittest/test_01_3dlayout_edb.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ def test_04_add_mesh_operations(self):

def test_05_change_property(self):
ports = self.aedtapp.create_ports_on_component_by_nets("U1", "DDR4_DQS0_P")
assert self.aedtapp.modeler.change_property(
"Excitations:{}".format(ports[0].name), "Impedance", "49ohm", "EM Design"
)
assert self.aedtapp.modeler.change_property(f"Excitations:{ports[0].name}", "Impedance", "49ohm", "EM Design")

def test_06_assign_spice_model(self):
model_path = os.path.join(local_path, "example_models", test_subfolder, "GRM32ER72A225KA35_25C_0V.sp")
Expand Down
2 changes: 2 additions & 0 deletions _unittest/test_01_Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def test_12_variables(self):
assert "test" not in self.aedtapp.variable_manager.variables

def test_13_designs(self):
with pytest.raises(ValueError):
self.aedtapp._insert_design(design_name="invalid", design_type="invalid")
assert self.aedtapp._insert_design(design_name="TestTransient", design_type="HFSS") == "TestTransient"
self.aedtapp.delete_design("TestTransient")
self.aedtapp.insert_design("NewDesign")
Expand Down
4 changes: 2 additions & 2 deletions _unittest/test_01_configuration_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
q3d_file = "via_gsg_t42"
test_project_name = "dm boundary test"
diff_proj_name = "test_42"
hfss3dl_existing_setup_proj_name = "existing_hfss3dl_setup_v{}{}".format(
config["desktopVersion"][-4:-2], config["desktopVersion"][-1:]
hfss3dl_existing_setup_proj_name = (
f"existing_hfss3dl_setup_v{config['desktopVersion'][-4:-2]}{config['desktopVersion'][-1:]}"
)


Expand Down
4 changes: 2 additions & 2 deletions _unittest/test_02_2D_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_04b_create_rectangle(self):
for m in materials:
material_array.append('"' + m + '"')
s = ", ".join(material_array)
self.aedtapp["Materials"] = "[{}]".format(s)
self.aedtapp["Materials"] = f"[{s}]"
material_index = 1
rect1 = self.aedtapp.modeler.create_rectangle(
origin=[0, 0, 0], sizes=[6, 12], name="rect1", material=f"Materials[{material_index}]"
Expand All @@ -107,7 +107,7 @@ def test_04b_create_rectangle(self):
origin=[0, 0, 0],
sizes=[6, 12],
name="rect3",
material="Materials[if(disp<={} && {}<=disp+{}-1,0,1)]".format(2, 2, 10),
material=f"Materials[if(disp<=2 && 2<=disp+9,0,1)]",
)
assert rect3.material_name == materials[0]

Expand Down
2 changes: 1 addition & 1 deletion _unittest/test_08_Primitives3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def test_40_getmodel_objects(self):
list3 = self.aedtapp.modeler.object_names
for el in list1:
if el not in list3:
print("Missing {}".format(el))
print(f"Missing {el}")
assert len(list1) + len(list2) == len(list3)

def test_41a_create_rect_sheet_to_region(self):
Expand Down
2 changes: 1 addition & 1 deletion _unittest/test_09_VariableManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_02_test_formula(self):

v = self.aedtapp.variable_manager
for var_name in v.variable_names:
print("{} = {}".format(var_name, self.aedtapp[var_name]))
print(f"{var_name} = {self.aedtapp[var_name]}")
tol = 1e-9
c2pi = math.pi * 2.0
assert abs(v["$PrjVar1"].numeric_value - c2pi) < tol
Expand Down
51 changes: 25 additions & 26 deletions _unittest/test_11_Setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ def test_25a_create_parametrics(self):
self.aedtapp.set_active_design("HFSSDesign")
self.aedtapp["w1"] = "10mm"
self.aedtapp["w2"] = "2mm"
assert not self.aedtapp.parametrics.add("invalid", 0.1, 20, 0.2, "LinearStep")
setup1 = self.aedtapp.parametrics.add("w1", 0.1, 20, 0.2, "LinearStep")
assert setup1
assert not setup1.add_variation("invalid", "0.1mm", 10, 11)
assert setup1.add_variation("w2", "0.1mm", 10, 11)
assert setup1.add_variation("w2", start_point="0.2mm", variation_type="SingleValue")
assert setup1.add_variation("w1", start_point="0.3mm", end_point=5, step=0.2, variation_type="LinearStep")
Expand All @@ -208,10 +210,8 @@ def test_25a_create_parametrics(self):
assert setup1.add_calculation(
calculation="dB(S(1,1))", ranges={"Freq": "3.5GHz"}, solution="My_HFSS_Setup : LastAdaptive"
)
assert setup1.name in self.aedtapp.get_oo_name(
self.aedtapp.odesign, r"Optimetrics".format(self.aedtapp.design_name)
)
oo = self.aedtapp.get_oo_object(self.aedtapp.odesign, r"Optimetrics\{}".format(setup1.name))
assert setup1.name in self.aedtapp.get_oo_name(self.aedtapp.odesign, "Optimetrics")
oo = self.aedtapp.get_oo_object(self.aedtapp.odesign, f"Optimetrics\\{setup1.name}")
oo_calculation = oo.GetCalculationInfo()[0]
assert "Modal Solution Data" in oo_calculation
assert setup1.export_to_csv(os.path.join(self.local_scratch.path, "test.csv"))
Expand All @@ -231,6 +231,7 @@ def test_25b_create_parametrics_sync(self):
)
assert setup1
assert setup1.add_variation("a2", start_point="0.3mm", end_point=5, step=10, variation_type="LinearCount")
assert not setup1.sync_variables(["invalid"], sync_n=1)
assert setup1.sync_variables(["a1", "a2"], sync_n=1)
assert setup1.sync_variables(["a1", "a2"], sync_n=0)
setup1.add_variation("a1", start_point="13mm", variation_type="SingleValue")
Expand All @@ -241,23 +242,21 @@ def test_26_create_optimization(self):
new_setup.props["Frequency"] = "2.5GHz"
sweep = new_setup.create_linear_step_sweep(start_frequency=2, stop_frequency=10, step_size=0.1)
setup2 = self.aedtapp.optimizations.add(
calculation, ranges={"Freq": "2.5GHz"}, solution="{} : {}".format(new_setup.name, sweep.name)
calculation, ranges={"Freq": "2.5GHz"}, solution=f"{new_setup.name} : {sweep.name}"
)
assert setup2
assert setup2.name in self.aedtapp.get_oo_name(
self.aedtapp.odesign, r"Optimetrics".format(self.aedtapp.design_name)
)
oo = self.aedtapp.get_oo_object(self.aedtapp.odesign, r"Optimetrics\{}".format(setup2.name))
assert setup2.name in self.aedtapp.get_oo_name(self.aedtapp.odesign, "Optimetrics")
oo = self.aedtapp.get_oo_object(self.aedtapp.odesign, f"Optimetrics\\{setup2.name}")
oo_calculation = oo.GetCalculationInfo()[0]
assert calculation in oo_calculation
assert "{} : {}".format(new_setup.name, sweep.name) in oo_calculation
assert f"{new_setup.name} : {sweep.name}" in oo_calculation
for el in oo_calculation:
if "NAME:Ranges" in el:
break
assert len(el) == 3
assert setup2.add_variation("w1", 0.1, 10, 5)
assert setup2.add_goal(
calculation=calculation, ranges={"Freq": "2.6GHz"}, solution="{} : {}".format(new_setup.name, sweep.name)
calculation=calculation, ranges={"Freq": "2.6GHz"}, solution=f"{new_setup.name} : {sweep.name}"
)
oo_calculation = oo.GetCalculationInfo()[0]
for el in reversed(oo_calculation):
Expand All @@ -267,9 +266,9 @@ def test_26_create_optimization(self):
assert setup2.add_goal(
calculation=calculation,
ranges={"Freq": ("2.6GHz", "5GHZ")},
solution="{} : {}".format(new_setup.name, sweep.name),
solution=f"{new_setup.name} : {sweep.name}",
)
oo = self.aedtapp.get_oo_object(self.aedtapp.odesign, r"Optimetrics\{}".format(setup2.name))
oo = self.aedtapp.get_oo_object(self.aedtapp.odesign, f"Optimetrics\\{setup2.name}")
oo_calculation = oo.GetCalculationInfo()[0]
for el in reversed(oo_calculation):
if "NAME:Ranges" in el:
Expand All @@ -286,7 +285,7 @@ def test_27_create_doe(self):
calculation,
ranges={"Freq": "2.5GHz"},
optimization_type="DXDOE",
solution="{} : {}".format(new_setup.name, sweep.name),
solution=f"{new_setup.name} : {sweep.name}",
)
assert setup2.add_variation("w1", 0.1, 10)
assert setup2.add_variation("w2", 0.1, 10)
Expand All @@ -295,12 +294,12 @@ def test_27_create_doe(self):
assert setup2.add_goal(
calculation="dB(S(1,1))",
ranges={"Freq": "2.5GHz"},
solution="{} : {}".format(new_setup.name, sweep.name),
solution=f"{new_setup.name} : {sweep.name}",
)
assert setup2.add_calculation(
calculation="dB(S(1,1))",
ranges={"Freq": "2.5GHz"},
solution="{} : {}".format(new_setup.name, sweep.name),
solution=f"{new_setup.name} : {sweep.name}",
)
assert setup2.delete()

Expand All @@ -313,21 +312,21 @@ def test_28A_create_optislang(self):
ranges=None,
variables=None,
optimization_type="optiSLang",
solution="{} : {}".format(new_setup.name, sweep.name),
solution=f"{new_setup.name} : {sweep.name}",
)
assert setup1.add_variation("w1", 1, 10, 51)
setup2 = self.aedtapp.optimizations.add(
calculation=None,
ranges=None,
variables={"w1": "1mm", "w2": "2mm"},
optimization_type="optiSLang",
solution="{} : {}".format(new_setup.name, sweep.name),
solution=f"{new_setup.name} : {sweep.name}",
)
assert setup2.add_variation("a1", 1, 10, 51)
assert not setup2.add_variation("w3", 0.1, 10, 5)
assert setup2
assert setup2.add_goal(
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, solution="{} : {}".format(new_setup.name, sweep.name)
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, solution=f"{new_setup.name} : {sweep.name}"
)

def test_28B_create_dx(self):
Expand All @@ -339,20 +338,20 @@ def test_28B_create_dx(self):
ranges=None,
variables=None,
optimization_type="DesignExplorer",
solution="{} : {}".format(new_setup.name, sweep.name),
solution=f"{new_setup.name} : {sweep.name}",
)
assert setup1.add_variation("w1", 5, 10, 51)
setup2 = self.aedtapp.optimizations.add(
None,
ranges=None,
variables={"w1": "1mm", "w2": "2mm"},
optimization_type="DesignExplorer",
solution="{} : {}".format(new_setup.name, sweep.name),
solution=f"{new_setup.name} : {sweep.name}",
)
assert setup2.add_variation("a1", 1, 10, 51)
assert setup2
assert setup2.add_goal(
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, solution="{} : {}".format(new_setup.name, sweep.name)
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, solution=f"{new_setup.name} : {sweep.name}"
)

def test_29_create_sensitivity(self):
Expand All @@ -364,12 +363,12 @@ def test_29_create_sensitivity(self):
calculation,
ranges={"Freq": "2.5GHz"},
optimization_type="Sensitivity",
solution="{} : {}".format(new_setup.name, sweep.name),
solution=f"{new_setup.name} : {sweep.name}",
)
assert setup2.add_variation("w1", 0.1, 10, 3.2)
assert setup2
assert setup2.add_calculation(
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, solution="{} : {}".format(new_setup.name, sweep.name)
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, solution=f"{new_setup.name} : {sweep.name}"
)

def test_29_create_statistical(self):
Expand All @@ -381,10 +380,10 @@ def test_29_create_statistical(self):
calculation,
ranges={"Freq": "2.5GHz"},
optimization_type="Statistical",
solution="{} : {}".format(new_setup.name, sweep.name),
solution=f"{new_setup.name} : {sweep.name}",
)
assert setup2.add_variation("w1", 0.1, 10, 0.3)
assert setup2
assert setup2.add_calculation(
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, solution="{} : {}".format(new_setup.name, sweep.name)
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, solution=f"{new_setup.name} : {sweep.name}"
)
39 changes: 35 additions & 4 deletions _unittest/test_12_1_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ def test_01B_Field_Plot(self):
plot1.update()
assert self.aedtapp.post.field_plots[plot1.name].IsoVal == "Tone"
assert plot1.change_plot_scale(min_value, "30000", scale_levels=50)
assert self.aedtapp.post.create_fieldplot_cutplane(cutlist, quantity_name, setup_name, intrinsic, plot1.name)
assert not self.aedtapp.post.create_fieldplot_volume("invalid", "Vector_E", setup_name, intrinsic)
assert self.aedtapp.post.create_fieldplot_volume("inner", quantity_name, setup_name, intrinsic)
field_plot = self.aedtapp.post.create_fieldplot_volume("inner", quantity_name, setup_name, intrinsic)
assert field_plot
assert self.aedtapp.post.create_fieldplot_volume("inner", quantity_name, setup_name, intrinsic, field_plot.name)

volume_plot = self.aedtapp.post.create_fieldplot_volume("NewObject_IJD39Q", "Vector_E", setup_name, intrinsic)

Expand All @@ -113,9 +116,13 @@ def test_01B_Field_Plot(self):
)
assert export_status
assert os.path.splitext(export_status)[1] == ".case"
assert self.aedtapp.post.create_fieldplot_surface(
field_plot = self.aedtapp.post.create_fieldplot_surface(
self.aedtapp.modeler["outer"].faces[0].id, "Mag_E", setup_name, intrinsic
)
assert field_plot
assert self.aedtapp.post.create_fieldplot_surface(
self.aedtapp.modeler["outer"].faces[0].id, "Mag_E", setup_name, intrinsic, field_plot.name
)
assert self.aedtapp.post.create_fieldplot_surface(self.aedtapp.modeler["outer"], "Mag_E", setup_name, intrinsic)
assert self.aedtapp.post.create_fieldplot_surface(
self.aedtapp.modeler["outer"].faces, "Mag_E", setup_name, intrinsic
Expand Down Expand Up @@ -254,6 +261,29 @@ def test_06_export_report_to_rdat(self):
assert os.path.exists(os.path.join(self.local_scratch.path, "MyTestScattering.rdat"))

def test_07_export_fields_from_Calculator(self):
file_path = self.aedtapp.post.export_field_file_on_grid(
"E",
"Setup1 : LastAdaptive",
self.aedtapp.available_variations.nominal_w_values_dict,
self.local_scratch.path,
grid_stop=[5, 5, 5],
grid_step=[0.5, 0.5, 0.5],
is_vector=True,
intrinsics="5GHz",
)
assert os.path.exists(file_path)

file_path = self.aedtapp.post.export_field_file_on_grid(
"E",
"Setup1 : LastAdaptive",
self.aedtapp.available_variations.nominal_w_values_dict,
grid_stop=[5, 5, 5],
grid_step=[0.5, 0.5, 0.5],
is_vector=True,
intrinsics="5GHz",
)
assert os.path.exists(file_path)

self.aedtapp.post.export_field_file_on_grid(
"E",
"Setup1 : LastAdaptive",
Expand Down Expand Up @@ -290,7 +320,6 @@ def test_07_export_fields_from_Calculator(self):
is_vector=False,
intrinsics="5GHz",
)

assert os.path.exists(os.path.join(self.local_scratch.path, "MagEfieldCyl.fld"))

def test_07_copydata(self):
Expand Down Expand Up @@ -730,7 +759,9 @@ def test_53_line_plot(self):
setup_name = "Setup1 : LastAdaptive"
intrinsic = {"Freq": "5GHz", "Phase": "180deg"}
self.aedtapp.modeler.create_polyline([udp1, udp2], name="Poly1", non_model=True)
assert self.aedtapp.post.create_fieldplot_line("Poly1", "Mag_E", setup_name, intrinsic)
field_line_plot = self.aedtapp.post.create_fieldplot_line("Poly1", "Mag_E", setup_name, intrinsic)
assert field_line_plot
self.aedtapp.post.create_fieldplot_line("Poly1", "Mag_E", setup_name, intrinsic, field_line_plot.name)

def test_55_reload(self, add_app):
self.aedtapp.save_project()
Expand Down
1 change: 1 addition & 0 deletions _unittest/test_12_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ def test_75_plot_field_line_traces(self, m2dtest):
m2dtest.analyze_setup(setup_name)
plot = m2dtest.post.create_fieldplot_line_traces(["Ground", "Electrode"], "Region", plot_name="LineTracesTest4")
assert plot
assert m2dtest.post.create_fieldplot_line_traces(["Ground", "Electrode"], "Region", plot_name="LineTracesTest4")
assert m2dtest.post.create_fieldplot_line_traces(
["Ground", "Electrode"], "Region", "Ground", plot_name="LineTracesTest5"
)
Expand Down
2 changes: 2 additions & 0 deletions _unittest/test_20_HFSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ def test_06a_create_linear_count_sweep(self):
setup3.delete()

def test_06b_setup_exists(self):
with pytest.raises(ValueError):
self.aedtapp.active_setup = "invalid"
assert self.aedtapp.active_setup is not None
assert self.aedtapp.nominal_sweep is not None

Expand Down
15 changes: 10 additions & 5 deletions _unittest/test_21_Circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ def test_05b_add_pin_iport(self):
assert self.aedtapp.modeler.schematic.add_pin_iports(mycap3.name, mycap3.id)
assert len(self.aedtapp.get_all_sparameter_list) == 3
assert len(self.aedtapp.get_all_return_loss_list()) == 2
assert len(self.aedtapp.get_all_return_loss_list(math_formula="abs")) == 2
assert len(self.aedtapp.get_all_insertion_loss_list()) == 2
assert len(self.aedtapp.get_all_insertion_loss_list(math_formula="abs")) == 2
assert len(self.aedtapp.get_all_insertion_loss_list(math_formula="abs", nets=self.aedtapp.excitations)) == 2
assert len(self.aedtapp.get_next_xtalk_list()) == 1
assert len(self.aedtapp.get_next_xtalk_list(math_formula="abs")) == 1
assert len(self.aedtapp.get_fext_xtalk_list()) == 2
assert len(self.aedtapp.get_fext_xtalk_list(math_formula="abs")) == 2

def test_05c_create_component(self):
assert self.aedtapp.modeler.schematic.create_new_component_from_symbol("Test", ["1", "2"])
Expand Down Expand Up @@ -157,7 +162,7 @@ def test_10_import_touchstone(self):
assert numports2 == 3
tx = ports[: int(numports / 2)]
rx = ports[int(numports / 2) :]
insertions = ["dB(S({},{}))".format(i, j) for i, j in zip(tx, rx)]
insertions = [f"dB(S({i},{j}))" for i, j in zip(tx, rx)]
assert self.aedtapp.create_touchstone_report("Insertion Losses", insertions)
touchstone_data = self.aedtapp.get_touchstone_data()
assert touchstone_data
Expand Down Expand Up @@ -498,8 +503,8 @@ def test_35_netlist_data_block(self):
self.aedtapp.insert_design("data_block")
with open(os.path.join(self.local_scratch.path, "lc.net"), "w") as f:
for i in range(10):
f.write("L{} net_{} net_{} 1e-9\n".format(i, i, i + 1))
f.write("C{} net_{} 0 5e-12\n".format(i, i + 1))
f.write(f"L{i} net_{i} net_{i+1} 1e-9\n")
f.write(f"C{i} net_{i+1} 0 5e-12\n")
assert self.aedtapp.add_netlist_datablock(os.path.join(self.local_scratch.path, "lc.net"))
self.aedtapp.modeler.components.create_interface_port("net_0", (0, 0))
self.aedtapp.modeler.components.create_interface_port("net_10", (0.01, 0))
Expand All @@ -520,8 +525,8 @@ def test_38_browse_log_file(self):
self.aedtapp.insert_design("data_block1")
with open(os.path.join(self.local_scratch.path, "lc.net"), "w") as f:
for i in range(10):
f.write("L{} net_{} net_{} 1e-9\n".format(i, i, i + 1))
f.write("C{} net_{} 0 5e-12\n".format(i, i + 1))
f.write(f"L{i} net_{i} net_{i+1} 1e-9\n")
f.write(f"C{i} net_{i+1} 0 5e-12\n")
self.aedtapp.modeler.components.create_interface_port("net_0", (0, 0), angle=90)
self.aedtapp.modeler.components.create_interface_port("net_10", (0.01, 0))
lna = self.aedtapp.create_setup("mylna", self.aedtapp.SETUPS.NexximLNA)
Expand Down
Loading

0 comments on commit c4e8562

Please sign in to comment.