Skip to content

Commit

Permalink
Setup tests for common cases and make them pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
btasdelen committed Dec 14, 2024
1 parent 0ef79b9 commit 4f9c197
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ exclude = ["examples/**"]
# PyTest section
[tool.pytest.ini_options]
testpaths = ["tests"]
filterwarnings = ["error"]
filterwarnings = ["error",
# Suppress error in debugpy due to mpl deprecation to debug tests.
"ignore::matplotlib._api.deprecation.MatplotlibDeprecationWarning:pydev",
]
markers = [
"matlab_seq_comp: comparison with matlab generated sequence",
"sigpy: tests that require sigpy",
Expand Down
6 changes: 6 additions & 0 deletions src/pypulseq/make_trapezoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ def make_trapezoid(
if area is None and flat_area is None and amplitude == 0:
raise ValueError("Must supply either 'area', 'flat_area' or 'amplitude'.")

if flat_area is not None:
if duration > 0:
raise NotImplementedError('Flat Area + Duration input pair is not implemented yet.')
if amplitude != 0:
raise NotImplementedError('Flat Area + Amplitude input pair is not implemented yet.')

if flat_time != -1:
if amplitude != 0:
amplitude2 = amplitude
Expand Down
32 changes: 23 additions & 9 deletions tests/test_make_trapezoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,30 @@ def test_generation_methods():
- flat_time and amplitude
- flat_time, area and rise_time
"""
assert isinstance(make_trapezoid(channel='x', area=1), SimpleNamespace)

# Amplitude specified
# amplitude + duration
assert isinstance(make_trapezoid(channel='x', amplitude=1, duration=1), SimpleNamespace)

assert isinstance(make_trapezoid(channel='x', flat_time=1, flat_area=1), SimpleNamespace)

# flat_time + amplitude
assert isinstance(make_trapezoid(channel='x', flat_time=1, amplitude=1), SimpleNamespace)

assert isinstance(make_trapezoid(channel='x', flat_time=0.5, area=1, rise_time=0.1), SimpleNamespace)

# Test addition to minimum input cases

# Flat area specified
# flat_area + flat_time
assert isinstance(make_trapezoid(channel='x', flat_time=1, flat_area=1), SimpleNamespace)
# flat_area + duration
with pytest.raises(NotImplementedError, match=r'Flat Area \+ Duration input pair is not implemented yet.'):
make_trapezoid(channel='x', flat_area=1, duration=1)
# flat_area + amplitude
with pytest.raises(NotImplementedError, match=r'Flat Area \+ Amplitude input pair is not implemented yet.'):
make_trapezoid(channel='x', flat_area=1, amplitude=1)

# Area specified
# area
assert isinstance(make_trapezoid(channel='x', area=1), SimpleNamespace)
# area + duration
assert isinstance(make_trapezoid(channel='x', area=1, duration=1), SimpleNamespace)
# area + amplitude
assert isinstance(make_trapezoid(channel='x', area=1, amplitude=1), SimpleNamespace)
# area + duration + rise_time
assert isinstance(make_trapezoid(channel='x', area=1, duration=0.1, rise_time=0.01), SimpleNamespace)
# flat_time + area + rise_time
assert isinstance(make_trapezoid(channel='x', flat_time=0.5, area=1, rise_time=0.1), SimpleNamespace)

0 comments on commit 4f9c197

Please sign in to comment.