alarm_tests.py 915 B

1234567891011121314151617181920212223242526272829303132333435
  1. """Tests for cement.ext.ext_alarm."""
  2. import sys
  3. import time
  4. import signal
  5. from cement.core.exc import CaughtSignal
  6. from cement.utils import test
  7. class AlarmExtTestCase(test.CementExtTestCase):
  8. def setUp(self):
  9. self.app = self.make_app('tests',
  10. extensions=['alarm'],
  11. argv=[]
  12. )
  13. @test.raises(CaughtSignal)
  14. def test_alarm_timeout(self):
  15. global app
  16. app = self.app
  17. with app as app:
  18. try:
  19. app.alarm.set(1, "The Timer Works!")
  20. time.sleep(3)
  21. except CaughtSignal as e:
  22. self.eq(e.signum, signal.SIGALRM)
  23. raise
  24. def test_alarm_no_timeout(self):
  25. with self.app as app:
  26. app.alarm.set(3, "The Timer Works!")
  27. time.sleep(1)
  28. app.alarm.stop()