Skip to content

Commit

Permalink
test timer nits
Browse files Browse the repository at this point in the history
  • Loading branch information
joshc-slac committed Nov 7, 2024
1 parent f069edb commit 3a9badf
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions beams/tests/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,33 @@
from beams.sequencer.helpers.Timer import Timer


class TestTimer():
def test_elapsed(self):
t = Timer(name="test_elapsed",
timer_period_seconds=0.1,
is_periodic=False)
t.start_timer()
assert t.is_elapsed() is False
time.sleep(0.5)
assert t.is_elapsed() is True

def test_timer_error(self):
t = Timer(name="test_error_not_started",
timer_period_seconds=0.1,
is_periodic=False)
with pytest.raises(RuntimeError):
t.get_elapsed()
with pytest.raises(RuntimeError):
t.is_elapsed()

def test_periodic(self):
t = Timer(name="test_error_not_started",
timer_period_seconds=0.1,
auto_start=True,
is_periodic=True)
time.sleep(0.2)
assert t.is_elapsed() is True
assert t.is_elapsed() is False
time.sleep(0.1)
assert t.is_elapsed() is True
def test_elapsed():
t = Timer(name="test_elapsed",
timer_period_seconds=0.1,
is_periodic=False)
t.start_timer()
assert not t.is_elapsed()
time.sleep(0.5)
assert t.is_elapsed()


def test_timer_error():
t = Timer(name="test_error_not_started",
timer_period_seconds=0.1,
is_periodic=False)
with pytest.raises(RuntimeError):
t.get_elapsed()
with pytest.raises(RuntimeError):
t.is_elapsed()


def test_periodic():
t = Timer(name="test_error_not_started",
timer_period_seconds=0.1,
auto_start=True,
is_periodic=True)
time.sleep(0.2)
assert t.is_elapsed()
assert not t.is_elapsed()
time.sleep(0.1)
assert t.is_elapsed()

0 comments on commit 3a9badf

Please sign in to comment.