Skip to content

Commit 005fe48

Browse files
committed
catch ValueError in base tendency if duration is negative
1 parent 7f0b836 commit 005fe48

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

tests/tendencies/test_base.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
(None, 20, None, 0, 20, 20, False),
1616
(None, None, 30, 0, 30, 30, False),
1717
(None, None, None, 0, 1, 1, False),
18-
(10, 20, 40, None, None, None, True),
19-
(10, None, 5, None, None, None, True),
20-
(10, -5, None, None, None, None, True),
21-
(None, 0, None, None, None, None, True),
18+
(10, 20, 40, 0, 1, 1, True),
19+
(10, None, 5, 10, 1, 11, True),
20+
(10, -5, None, 10, 1, 11, True),
21+
(None, 0, None, 0, 1, 1, True),
2222
],
2323
)
2424
def test_first_base_tendency(
@@ -34,12 +34,12 @@ def test_first_base_tendency(
3434
kwargs = dict(user_start=start, user_duration=duration, user_end=end)
3535
base_tendency = BaseTendency(**kwargs)
3636

37+
assert base_tendency.start == approx(expected_start)
38+
assert base_tendency.duration == approx(expected_duration)
39+
assert base_tendency.end == approx(expected_end)
3740
if has_error:
3841
assert base_tendency.annotations
3942
else:
40-
assert base_tendency.start == approx(expected_start)
41-
assert base_tendency.duration == approx(expected_duration)
42-
assert base_tendency.end == approx(expected_end)
4343
assert not base_tendency.annotations
4444

4545

@@ -54,10 +54,10 @@ def test_first_base_tendency(
5454
(None, 20, None, 10, 20, 30, False),
5555
(None, None, 30, 10, 20, 30, False),
5656
(None, None, None, 10, 1, 11, False),
57-
(10, 20, 40, None, None, None, True),
58-
(10, None, 5, None, None, None, True),
59-
(10, -5, None, None, None, None, True),
60-
(None, 0, None, None, None, None, True),
57+
(10, 20, 40, 10, 1, 11, True),
58+
(10, None, 5, 10, 1, 11, True),
59+
(10, -5, None, 10, 1, 11, True),
60+
(None, 0, None, 10, 1, 11, True),
6161
],
6262
)
6363
def test_second_base_tendency(
@@ -73,14 +73,15 @@ def test_second_base_tendency(
7373
prev_tendency = BaseTendency(user_start=0, user_end=10)
7474
kwargs = dict(user_start=start, user_duration=duration, user_end=end)
7575
base_tendency = BaseTendency(**kwargs)
76+
base_tendency.set_previous_tendency(prev_tendency)
77+
prev_tendency.set_next_tendency(base_tendency)
7678

79+
assert base_tendency.start == approx(expected_start)
80+
assert base_tendency.duration == approx(expected_duration)
81+
assert base_tendency.end == approx(expected_end)
7782
if has_error:
7883
assert base_tendency.annotations
7984
else:
80-
base_tendency.set_previous_tendency(prev_tendency)
81-
assert base_tendency.start == approx(expected_start)
82-
assert base_tendency.duration == approx(expected_duration)
83-
assert base_tendency.end == approx(expected_end)
8485
assert not base_tendency.annotations
8586

8687

waveform_editor/tendencies/base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,9 @@ def _calc_times(self):
255255

256256
# Check if any value has changed
257257
if (self.start, self.duration, self.end) != values:
258-
self.start, self.duration, self.end = values
258+
try:
259+
self.start, self.duration, self.end = values
260+
except Exception as error:
261+
self._handle_error(error)
259262
# Trigger timing event
260263
self.times_changed = True
261-
262-
if self.duration <= 0:
263-
error_msg = "Tendency end time must be greater than its start time."
264-
self.annotations.add(self.line_number, error_msg)

0 commit comments

Comments
 (0)