Skip to content

Commit

Permalink
add error catch tests to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmoMatt committed Apr 9, 2024
1 parent 64d5586 commit baa412b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/test_spherical_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,55 @@ def test_transform_forward_healpix(
flm = hp.sphtfunc.map2alm(f, lmax=L - 1, iter=0)

np.testing.assert_allclose(flm, flm_check, atol=1e-14)


def test_spin_exceptions(flm_generator):
spin = 10
L = 16
sampling = "mw"

flm = flm_generator(L=L, reality=False)
f = spherical.inverse(flm, L, spin=0, sampling=sampling, method="jax_ssht")

with pytest.raises(Warning) as e:
spherical.inverse(flm, L, spin=spin, sampling=sampling, method="jax")

with pytest.raises(Warning) as e:
spherical.forward(f, L, spin=spin, sampling=sampling, method="jax")


def test_sampling_ssht_backend_exceptions(flm_generator):
sampling = "healpix"
nside = 6
L = 2 * nside

flm = flm_generator(L=L, reality=False)
f = spherical.inverse(flm, L, 0, nside, sampling, "jax_healpy")

with pytest.raises(ValueError) as e:
spherical.inverse(flm, L, 0, nside, sampling, "jax_ssht")

with pytest.raises(ValueError) as e:
spherical.forward(f, L, 0, nside, sampling, "jax_ssht")


def test_sampling_healpy_backend_exceptions(flm_generator):
sampling = "mw"
L = 12

flm = flm_generator(L=L, reality=False)
f = spherical.inverse(flm, L, 0, None, sampling, "jax_ssht")

with pytest.raises(ValueError) as e:
spherical.inverse(flm, L, 0, None, sampling, "jax_healpy")

with pytest.raises(ValueError) as e:
spherical.forward(f, L, 0, None, sampling, "jax_healpy")


def test_sampling_exceptions(flm_generator):
with pytest.raises(ValueError) as e:
spherical.inverse(None, 0, 0, None, method="incorrect")

with pytest.raises(ValueError) as e:
spherical.forward(None, 0, 0, None, method="incorrect")
26 changes: 26 additions & 0 deletions tests/test_wigner_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,29 @@ def test_ssht_c_backend_forward_wigner_transform(
f, L, N, None, sampling, "jax_ssht", reality, L_lower=L_lower
)
np.testing.assert_allclose(flmn, flmn_check, atol=1e-12)


def test_N_exceptions(flmn_generator):
N = 10
L = 16
flmn = flmn_generator(L=L, N=N)
f = base_wigner.inverse(flmn, L, N)

with pytest.raises(Warning) as e:
wigner.inverse(flmn, L, N)

with pytest.raises(Warning) as e:
wigner.forward(f, L, N)


def test_sampling_ssht_backend_exceptions(flmn_generator):
L = 16
N = 1
flmn = flmn_generator(L=L, N=N)
f = base_wigner.inverse(flmn, L, N)

with pytest.raises(ValueError) as e:
wigner.inverse(flmn, L, N, sampling="healpix", method="jax_ssht")

with pytest.raises(ValueError) as e:
wigner.forward(f, L, N, sampling="healpix", method="jax_ssht")

0 comments on commit baa412b

Please sign in to comment.