Skip to content

Commit

Permalink
Merge pull request #244 from Abelarm/skip_S4_tests
Browse files Browse the repository at this point in the history
[ENH] RCWA test are skipped if S4 not intalled
  • Loading branch information
phoebe-p committed Feb 13, 2023
2 parents fb8deab + 9447279 commit 277728b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,17 @@ def light_source(wavelength):
output_units="photon_flux_per_m",
concentration=1,
)


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
16 changes: 8 additions & 8 deletions tests/test_optics.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
from .conftest import skip_s4_test
from pytest import mark, approx


@mark.skipif(sys.platform in ["win32", "cygwin"], reason="Only works under unix based systems")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
def test_calculate_rat_rcwa():
import numpy as np

Expand Down Expand Up @@ -32,7 +32,7 @@ def test_calculate_rat_rcwa():
assert v.shape[0] == len(wl)


@mark.skipif(sys.platform in ["win32", "cygwin"], reason="Only works under unix based systems")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
def test_calculate_absorption_profile_rcwa():
import numpy as np

Expand Down Expand Up @@ -75,7 +75,7 @@ def test_calculate_absorption_profile_rcwa():
assert result["absorption"] == approx(parallel_result["absorption"], abs=1e-5)


@mark.skipif(sys.platform in ["win32", "cygwin"], reason="Only works under unix based systems")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
def test_pol_rcwa():
import numpy as np

Expand Down Expand Up @@ -131,7 +131,7 @@ def test_pol_rcwa():
assert result_u["absorption"] == approx(0.5*(result_s["absorption"] + result_p["absorption"]))


@mark.skipif(sys.platform in ["win32", "cygwin"], reason="Only works under unix based systems")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
def test_arbitrary_pol_rcwa():
import numpy as np

Expand Down Expand Up @@ -179,7 +179,7 @@ def test_arbitrary_pol_rcwa():
assert result["absorption"] == approx(result_s["absorption"])


@mark.skipif(sys.platform in ["win32", "cygwin"], reason="Only works under unix based systems")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
def test_rcwa_polygon():
import numpy as np

Expand Down Expand Up @@ -241,7 +241,7 @@ def test_rcwa_polygon():
assert result_polygon["absorption"] == approx(result_square["absorption"], abs=0.001)


@mark.skipif(sys.platform in ["win32", "cygwin"], reason="Only works under unix based systems")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("pol", ['s', 'p', 'u'])
@mark.parametrize("angle", [0, 60])
def test_tmm_rcwa_structure_comparison(pol, angle):
Expand Down Expand Up @@ -285,7 +285,7 @@ def test_tmm_rcwa_structure_comparison(pol, angle):
assert np.sum(rcwa_result['A_per_layer'], 1) + rcwa_result['R'] + rcwa_result['T'] == approx(1)


@mark.skipif(sys.platform in ["win32", "cygwin"], reason="Only works under unix based systems")
@mark.skipif(skip_s4_test(), reason="Only works if S4 installed")
@mark.parametrize("pol", ['s', 'p', 'u'])
@mark.parametrize("angle", [0, 60])
def test_tmm_rcwa_structure_profile_comparison(pol, angle):
Expand Down

0 comments on commit 277728b

Please sign in to comment.