From 5b4ff96d6618fc07e7bf8840f41b56b091dffdc7 Mon Sep 17 00:00:00 2001 From: Liam Pattinson Date: Tue, 10 Sep 2024 16:25:39 +0100 Subject: [PATCH 1/2] Add test that Sigma __post_init__ works correctly --- tests/test_cocos.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/test_cocos.py b/tests/test_cocos.py index 71b67ae..8debebd 100644 --- a/tests/test_cocos.py +++ b/tests/test_cocos.py @@ -4,7 +4,7 @@ import numpy as np import pytest -from pyloidal.cocos import Transform, identify_cocos +from pyloidal.cocos import Sigma, Transform, identify_cocos ALL_COCOS = list(range(1, 9)) + list(range(11, 19)) @@ -75,3 +75,14 @@ def test_cocos_transform(): for cocos_add in (cocos + x * 10 for x in range(2)): for key in ("b_toroidal", "toroidal", "poloidal", "q"): assert getattr(Transform(cocos_add, cocos_add), key) == 1 + + +@pytest.mark.parametrize("bad_input", ["B_poloidal", "r_phi_z", "r_theta_phi"]) +def test_sigma_bad_inputs(bad_input): + """Test that Sigma raises an excpetion when given an inputs not in ``(-1, 1)``""" + inputs = { + k: (0 if k == bad_input else 1) + for k in ("B_poloidal", "r_phi_z", "r_theta_phi") + } + with pytest.raises(ValueError, match=bad_input): + Sigma(**inputs) From cd33f50b30d0c3702573273e394cafc93994cd0b Mon Sep 17 00:00:00 2001 From: Liam Pattinson Date: Tue, 10 Sep 2024 16:41:09 +0100 Subject: [PATCH 2/2] Simplify Sigma __post_init__ test --- tests/test_cocos.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/test_cocos.py b/tests/test_cocos.py index 8debebd..a7357a2 100644 --- a/tests/test_cocos.py +++ b/tests/test_cocos.py @@ -77,12 +77,13 @@ def test_cocos_transform(): assert getattr(Transform(cocos_add, cocos_add), key) == 1 -@pytest.mark.parametrize("bad_input", ["B_poloidal", "r_phi_z", "r_theta_phi"]) -def test_sigma_bad_inputs(bad_input): +def test_sigma_bad_inputs(): """Test that Sigma raises an excpetion when given an inputs not in ``(-1, 1)``""" - inputs = { - k: (0 if k == bad_input else 1) - for k in ("B_poloidal", "r_phi_z", "r_theta_phi") - } - with pytest.raises(ValueError, match=bad_input): - Sigma(**inputs) + with pytest.raises(ValueError, match="B_poloidal"): + Sigma(B_poloidal=2, r_phi_z=1, r_theta_phi=-1) + + with pytest.raises(ValueError, match="r_phi_z"): + Sigma(B_poloidal=-1, r_phi_z=0, r_theta_phi=-1) + + with pytest.raises(ValueError, match="r_theta_phi"): + Sigma(B_poloidal=-1, r_phi_z=1, r_theta_phi=-5)