Skip to content

Commit d53fae0

Browse files
committed
Updated unit tests for test_simulation.py
1 parent 5f954ff commit d53fae0

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

tests/test_components/test_simulation.py

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -824,14 +824,14 @@ def test_bad_eps_arg(self, eps_comp):
824824
self.make_sim(self.medium_diag).plot_eps(x=0, eps_component=eps_comp)
825825

826826
@pytest.mark.parametrize(
827-
"eps_comp",
828-
[None, *diag_comps],
827+
"eps_comp, swap_axes",
828+
zip([None, *diag_comps], [True, False]),
829829
)
830-
def test_plot_anisotropic_medium(self, eps_comp):
830+
def test_plot_anisotropic_medium(self, eps_comp, swap_axes):
831831
"""Test plotting diagonal components of a diagonally anisotropic medium succeeds or not.
832832
diagonal components and ``None`` should succeed.
833833
"""
834-
self.make_sim(self.medium_diag).plot_eps(x=0, eps_component=eps_comp)
834+
self.make_sim(self.medium_diag).plot_eps(x=0, eps_component=eps_comp, swap_axes=swap_axes)
835835

836836
@pytest.mark.parametrize("eps_comp", offdiag_comps)
837837
def test_plot_anisotropic_medium_offdiagfail(self, eps_comp):
@@ -855,15 +855,15 @@ def test_plot_anisotropic_medium_diff(self, tmp_path, eps_comp1, eps_comp2, expe
855855
self.compare_eps_images(tmp_path, eps_comp1, eps_comp2, expected, self.medium_diag)
856856

857857
@pytest.mark.parametrize(
858-
"eps_comp",
859-
[None, *diag_comps, *offdiag_comps],
858+
"eps_comp, swap_axes",
859+
zip([None, *diag_comps, *offdiag_comps], [True, False]),
860860
)
861-
def test_plot_fully_anisotropic_medium(self, eps_comp):
861+
def test_plot_fully_anisotropic_medium(self, eps_comp, swap_axes):
862862
"""Test plotting all components of a fully anisotropic medium.
863863
All plots should succeed.
864864
"""
865865
sim = self.make_sim(self.medium_fullyani)
866-
sim.plot_eps(x=0, eps_component=eps_comp)
866+
sim.plot_eps(x=0, eps_component=eps_comp, swap_axes=swap_axes)
867867

868868
# Test parameters for comparing plots of a FullyAnisotropicMedium
869869
fullyani_testplot_diff_params = []
@@ -882,14 +882,14 @@ def test_plot_fully_anisotropic_medium_diff(self, tmp_path, eps_comp1, eps_comp2
882882
self.compare_eps_images(tmp_path, eps_comp1, eps_comp2, expected, self.medium_fullyani)
883883

884884
@pytest.mark.parametrize(
885-
"eps_comp",
886-
[None, *diag_comps],
885+
"eps_comp, swap_axes",
886+
zip([None, *diag_comps], [True, False]),
887887
)
888-
def test_plot_customanisotropic_medium(self, eps_comp, medium_customani):
888+
def test_plot_customanisotropic_medium(self, eps_comp, swap_axes, medium_customani):
889889
"""Test plotting diagonal components of a diagonally anisotropic custom medium.
890890
diagonal components and ``None`` should succeed.
891891
"""
892-
self.make_sim(medium_customani).plot_eps(x=0, eps_component=eps_comp)
892+
self.make_sim(medium_customani).plot_eps(x=0, eps_component=eps_comp, swap_axes=swap_axes)
893893

894894
@pytest.mark.parametrize("eps_comp", offdiag_comps)
895895
def test_plot_customanisotropic_medium_offdiagfail(self, eps_comp, medium_customani):
@@ -915,14 +915,16 @@ def test_plot_customanisotropic_medium_diff(
915915
self.compare_eps_images(tmp_path, eps_comp1, eps_comp2, expected, medium_customani)
916916

917917

918-
def test_plot():
919-
SIM_FULL.plot(x=0)
918+
@pytest.mark.parametrize("swap_axes", [True, False])
919+
def test_plot(swap_axes):
920+
SIM_FULL.plot(x=0, swap_axes=swap_axes)
920921
plt.close()
921922

922923

923-
def test_plot_with_units():
924+
@pytest.mark.parametrize("swap_axes", [True, False])
925+
def test_plot_with_units(swap_axes):
924926
sim_with_units = SIM_FULL.updated_copy(plot_length_units="nm")
925-
sim_with_units.plot(x=-0.5)
927+
sim_with_units.plot(x=-0.5, swap_axes=swap_axes)
926928

927929

928930
def test_plot_1d_sim():
@@ -938,12 +940,13 @@ def test_plot_1d_sim():
938940
plt.close()
939941

940942

941-
def test_plot_bounds():
942-
_ = SIM_FULL.plot(x=0, hlim=[-0.45, 0.45])
943+
@pytest.mark.parametrize("swap_axes", [True, False])
944+
def test_plot_bounds(swap_axes):
945+
_ = SIM_FULL.plot(x=0, hlim=[-0.45, 0.45], swap_axes=swap_axes)
943946
plt.close()
944-
_ = SIM_FULL.plot(x=0, vlim=[-0.45, 0.45])
947+
_ = SIM_FULL.plot(x=0, vlim=[-0.45, 0.45], swap_axes=swap_axes)
945948
plt.close()
946-
_ = SIM_FULL.plot(x=0, hlim=[-0.45, 0.45], vlim=[-0.45, 0.45])
949+
_ = SIM_FULL.plot(x=0, hlim=[-0.45, 0.45], vlim=[-0.45, 0.45], swap_axes=swap_axes)
947950
plt.close()
948951

949952

@@ -1008,22 +1011,25 @@ def test_plot_eps_with_default_frequency():
10081011
plt.close()
10091012

10101013

1011-
def test_plot_symmetries():
1014+
@pytest.mark.parametrize("swap_axes", [True, False])
1015+
def test_plot_symmetries(swap_axes):
10121016
S2 = SIM.copy(update={"symmetry": (1, 0, -1)})
1013-
S2.plot_symmetries(x=0)
1017+
S2.plot_symmetries(x=0, swap_axes=swap_axes)
10141018
plt.close()
10151019

10161020

1017-
def test_plot_grid():
1021+
@pytest.mark.parametrize("swap_axes", [True, False])
1022+
def test_plot_grid(swap_axes):
10181023
override = td.Structure(geometry=td.Box(size=(1, 1, 1)), medium=td.Medium())
10191024
S2 = SIM_FULL.copy(
10201025
update={"grid_spec": td.GridSpec(wavelength=1.0, override_structures=[override])}
10211026
)
1022-
S2.plot_grid(x=0)
1027+
S2.plot_grid(x=0, swap_axes=swap_axes)
10231028
plt.close()
10241029

10251030

1026-
def test_plot_boundaries():
1031+
@pytest.mark.parametrize("swap_axes", [True, False])
1032+
def test_plot_boundaries(swap_axes):
10271033
bound_spec = td.BoundarySpec(
10281034
x=td.Boundary(plus=td.PECBoundary(), minus=td.PMCBoundary()),
10291035
y=td.Boundary(
@@ -1033,16 +1039,17 @@ def test_plot_boundaries():
10331039
z=td.Boundary(plus=td.Periodic(), minus=td.Periodic()),
10341040
)
10351041
S2 = SIM_FULL.copy(update={"boundary_spec": bound_spec})
1036-
S2.plot_boundaries(z=0)
1042+
S2.plot_boundaries(z=0, swap_axes=swap_axes)
10371043
plt.close()
10381044

10391045

1040-
def test_plot_with_lumped_elements():
1046+
@pytest.mark.parametrize("swap_axes", [True, False])
1047+
def test_plot_with_lumped_elements(swap_axes):
10411048
load = td.LumpedResistor(
10421049
center=(0, 0, 0), size=(1, 2, 0), name="resistor", voltage_axis=0, resistance=50
10431050
)
10441051
sim_test = SIM_FULL.updated_copy(lumped_elements=[load])
1045-
sim_test.plot(z=0)
1052+
sim_test.plot(z=0, swap_axes=swap_axes)
10461053
plt.close()
10471054

10481055

0 commit comments

Comments
 (0)