Skip to content

Commit

Permalink
add error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-dudt committed Apr 15, 2024
1 parent f7937a6 commit bb6cae0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions desc/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])

Expand Down
6 changes: 6 additions & 0 deletions tests/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit bb6cae0

Please sign in to comment.