From bb6cae089cb9eb2585921e9b466487b31eee3445 Mon Sep 17 00:00:00 2001 From: daniel-dudt Date: Mon, 15 Apr 2024 15:26:22 -0500 Subject: [PATCH] add error tests --- desc/profiles.py | 8 ++++++-- tests/test_profiles.py | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/desc/profiles.py b/desc/profiles.py index 55f9081ef5..2190359501 100644 --- a/desc/profiles.py +++ b/desc/profiles.py @@ -728,12 +728,14 @@ def __init__(self, params=None, name=""): warnif( self._params[1] < 1, UserWarning, - "Derivatives of this profile will be infinite at rho=0!", + "Derivatives of this profile will be infinite at rho=0 " + + "because params[1] < 1.", ) warnif( self._params[2] < 1, UserWarning, - "Derivatives of this profile will be infinite at rho=1!", + "Derivatives of this profile will be infinite at rho=1 " + + "because params[2] < 1.", ) @property @@ -1019,6 +1021,8 @@ def compute(self, grid, params=None, dr=0, dt=0, dz=0): """ if params is None: params = self.params + if dr > 2: + raise NotImplementedError("dr > 2 not implemented for MTanhProfile!") if dt != 0 or dz != 0: return jnp.zeros_like(grid.nodes[:, 0]) diff --git a/tests/test_profiles.py b/tests/test_profiles.py index 8bf0382dd0..530fd5f765 100644 --- a/tests/test_profiles.py +++ b/tests/test_profiles.py @@ -354,6 +354,8 @@ def test_profile_errors(self): sp = pp.to_spline() zp = pp.to_fourierzernike() mp = pp.to_mtanh(order=4, ftol=1e-4, xtol=1e-4) + tp = TwoPowerProfile(params=np.array([0.5, 2, 1.5])) + grid = LinearGrid(L=9) with pytest.raises(ValueError): zp.params = 4 @@ -375,6 +377,10 @@ def test_profile_errors(self): a.params = sp.params with pytest.raises(ValueError): _ = TwoPowerProfile([1, 2, 3, 4]) + with pytest.raises(NotImplementedError): + tp.compute(grid, dr=3) + with pytest.raises(NotImplementedError): + mp.compute(grid, dr=3) @pytest.mark.unit def test_default_profiles(self):