Skip to content

Commit

Permalink
fix testing to skip RCWA tests on any platform if S4 is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
phoebe-p committed Mar 12, 2024
1 parent b69f159 commit e713b97
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 26 deletions.
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def skip_s4_test():
"""
Utility function for skipping the test if S4 is not installed,
Returns: True if S4 not installed False otherwise
"""

try:
import S4
return False
except ModuleNotFoundError:
return True
5 changes: 2 additions & 3 deletions tests/test_analytic.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import numpy as np
from pytest import approx, mark
import sys
from .conftest import skip_s4_test


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
def test_get_order_directions():
from rayflare.analytic.diffraction import get_order_directions
from solcore import material
Expand Down
18 changes: 9 additions & 9 deletions tests/test_compare_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import numpy as np
import sys
import itertools
from .conftest import skip_s4_test


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_tmm_rcwa_structure_comparison(RCWA_method):
from solcore import si, material
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_tmm_rcwa_structure_comparison(RCWA_method):
assert np.sum(rcwa_result["A_per_layer"], 1) + rcwa_result["R"] + rcwa_result["T"] == approx(1)


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_planar_structure(RCWA_method):
# solcore imports
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_planar_structure(RCWA_method):
).data == approx(1)


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_planar_structure_45deg(RCWA_method):
# solcore imports
Expand Down Expand Up @@ -368,7 +368,7 @@ def test_planar_structure_45deg(RCWA_method):
).data == approx(1)


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_tmm_rcwa_pol_angle(RCWA_method):
# solcore imports
Expand Down Expand Up @@ -700,7 +700,7 @@ def test_absorption_profile_coh_angles():
assert rt_profile_u == approx(tmm_profile_u, rel=0.4)


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_rcwa_tmm_profiles_coh(RCWA_method):
from rayflare.options import default_options
Expand Down Expand Up @@ -775,7 +775,7 @@ def test_rcwa_tmm_profiles_coh(RCWA_method):
assert rcwa_profile_u == approx(tmm_profile_u, rel=0.025)


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_rcwa_tmm_matrix_check_sums(RCWA_method):
from solcore.structure import Layer
Expand Down Expand Up @@ -965,7 +965,7 @@ def test_rcwa_tmm_matrix_check_sums(RCWA_method):
assert results_per_layer_back_RCWA[c_i] == approx(results_per_layer_back_TMM_ref[c_i], rel=0.05)


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_rcwa_tmm_matrix_profiles(RCWA_method):
from solcore.structure import Layer
Expand Down Expand Up @@ -1147,7 +1147,7 @@ def test_rcwa_tmm_matrix_profiles(RCWA_method):
assert prof_plot_RCWA_back.data[c_i] == approx(back_profile_TMM[c_i], rel=0.15)


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_profile_integration(RCWA_method):
from rayflare.utilities import get_savepath
Expand Down
1 change: 0 additions & 1 deletion tests/test_ideal_cases.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
from pytest import approx


def test_lambertian_scattering():
from rayflare.matrix_formalism.ideal_cases import lambertian_matrix
from rayflare.angles import make_angle_vector
Expand Down
1 change: 0 additions & 1 deletion tests/test_matrix_formalism.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pytest import approx
import numpy as np


def test_bulk_profile():
from solcore import material

Expand Down
17 changes: 8 additions & 9 deletions tests/test_rigorous_coupled_wave.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from pytest import approx, mark
import numpy as np
import sys
from .conftest import skip_s4_test


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_RAT(RCWA_method):
from solcore import si, material
Expand Down Expand Up @@ -122,7 +121,7 @@ def test_RAT(RCWA_method):
)


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_RAT_angle_pol(RCWA_method):
from solcore import si, material
Expand Down Expand Up @@ -199,7 +198,7 @@ def test_RAT_angle_pol(RCWA_method):
assert RAT["R"] + RAT["T"] + np.sum(RAT["A_per_layer"], 1) == approx(1)


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_RAT_angle_pol_ninc(RCWA_method):
from solcore import si, material
Expand Down Expand Up @@ -276,7 +275,7 @@ def test_RAT_angle_pol_ninc(RCWA_method):
assert RAT["R"] + RAT["T"] + np.sum(RAT["A_per_layer"], 1) == approx(1)


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_shapes(RCWA_method):
from solcore import material
Expand Down Expand Up @@ -362,7 +361,7 @@ def test_shapes(RCWA_method):
assert np.all(A_back[i1] > A_back[-1])


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
def test_reciprocal_lattice():
from rayflare.rigorous_coupled_wave_analysis.rcwa import get_reciprocal_lattice

Expand All @@ -374,7 +373,7 @@ def test_reciprocal_lattice():
assert a[1] == approx((0, 1 / 200))


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
def test_plotting_funcs():
from solcore import si, material
from solcore.structure import Layer
Expand Down Expand Up @@ -506,7 +505,7 @@ def test_plotting_funcs():
assert H.shape == (len(xs), len(ys), 3)


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("RCWA_method", ["S4", "Inkstone"])
def test_matrix_generation(RCWA_method):
from rayflare.rigorous_coupled_wave_analysis import RCWA
Expand Down
5 changes: 2 additions & 3 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from pytest import approx, mark
import numpy as np
import sys
from .conftest import skip_s4_test


@mark.skipif(sys.platform == "win32", reason="S4 (RCWA) only installed for tests under Linux and macOS")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
def test_tmm_rcwa_profile():
from rayflare.utilities import make_absorption_function
from rayflare.transfer_matrix_method import tmm_structure
Expand Down

0 comments on commit e713b97

Please sign in to comment.