[pitivi] test_integration.py: add watchdog timer and tests
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pitivi] test_integration.py: add watchdog timer and tests
- Date: Wed, 4 Nov 2009 15:44:39 +0000 (UTC)
commit 024ca2c8dc83063caacd06895a324989d5adf819
Author: Brandon Lewis <brandon_lewis alum berkeley edu>
Date: Wed Oct 28 14:49:02 2009 -0700
test_integration.py: add watchdog timer and tests
tests/test_integration.py | 83 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 83 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_integration.py b/tests/test_integration.py
index 8e3071a..1cbfc3b 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -19,3 +19,86 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
+"""Test pitivi core objects at the API level, simulating the UI input for
+QA scenarios """
+
+import unittest
+TestCase = unittest.TestCase
+from pitivi.application import InteractivePitivi
+import pitivi.instance
+import gobject
+
+class WatchDog(object):
+
+ """A simple watchdog timer to aid developing integration tests. If
+ keepAlive() is not called every <timeout> ms, then the watchdog timer will
+ quit the specified mainloop."""
+
+ def __init__(self, mainloop, timeout=10000):
+ self.timeout = timeout
+ self.mainloop = mainloop
+ self.will_quit = False
+ self.keep_going = True
+ self.activated = False
+
+ def start(self):
+ self.will_quit = False
+ self.keep_going = True
+ gobject.timeout_add(self.timeout, self._timeoutcb)
+
+ def suspend(self):
+ self.keepAlive()
+ self.keep_going = False
+
+ def _timeoutcb(self):
+ if self.will_quit:
+ self.mainloop.quit()
+ self.activated = True
+ self.keep_going = False
+ self.will_quit = True
+ return self.keep_going
+
+ def keepAlive(self):
+ self.will_quit = False
+
+class TestWatchdog(TestCase):
+
+ def testWatchdog(self):
+ self.ml = gobject.MainLoop()
+ wd = WatchDog(self.ml, 100)
+ self.timeout_called = False
+ wd.start()
+ gobject.timeout_add(2000, self._timeoutCb)
+ self.ml.run()
+ self.assertFalse(self.timeout_called)
+ self.assertTrue(wd.activated)
+
+ def testKeepAlive(self):
+ self.ml = gobject.MainLoop()
+ wd = WatchDog(self.ml, 2000)
+ self.timeout_called = False
+ wd.start()
+ gobject.timeout_add(500, wd.keepAlive)
+ gobject.timeout_add(2500, self._timeoutCb)
+ self.ml.run()
+ self.assertTrue(self.timeout_called)
+ self.assertFalse(wd.activated)
+
+ def testSuspend(self):
+ self.ml = gobject.MainLoop()
+ wd = WatchDog(self.ml, 500)
+ self.timeout_called = False
+ wd.start()
+ wd.suspend()
+ gobject.timeout_add(2000, self._timeoutCb)
+ self.ml.run()
+ self.assertTrue(self.timeout_called)
+ self.assertFalse(wd.activated)
+
+ def _timeoutCb(self):
+ self.ml.quit()
+ self.timeout_called = True
+ return False
+
+if __name__ == "__main__":
+ unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]