]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Update test_ioloop to use AsyncTestCase. Rename it to ioloop_test and
authorBen Darnell <bdarnell@beaker.local>
Fri, 30 Jul 2010 02:00:06 +0000 (19:00 -0700)
committerBen Darnell <bdarnell@beaker.local>
Fri, 30 Jul 2010 02:00:06 +0000 (19:00 -0700)
make other stylistic changes for consistency.

tornado/test/ioloop_test.py [new file with mode: 0755]
tornado/test/runtests.py
tornado/test/test_ioloop.py [deleted file]

diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py
new file mode 100755 (executable)
index 0000000..2c718a7
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+import unittest
+import time
+
+from tornado import ioloop
+from tornado.testing import AsyncTestCase, LogTrapTestCase
+
+class TestIOLoop(AsyncTestCase, LogTrapTestCase):
+    def test_add_callback_wakeup(self):
+        # Make sure that add_callback from inside a running IOLoop
+        # wakes up the IOLoop immediately instead of waiting for a timeout.
+        def callback():
+            self.called = True
+            self.stop()
+
+        def schedule_callback():
+            self.called = False
+            self.io_loop.add_callback(callback)
+            # Store away the time so we can check if we woke up immediately
+            self.start_time = time.time()
+        self.io_loop.add_timeout(time.time(), schedule_callback)
+        self.wait()
+        self.assertAlmostEqual(time.time(), self.start_time, places=2)
+        self.assertTrue(self.called)
+
+if __name__ == "__main__":
+    unittest.main()
index 773c1e5426e17b925dfa3f96303e7d5f2578222b..79b2cc53e444ba730ad129059f9661a8458ba9d9 100755 (executable)
@@ -4,7 +4,7 @@ import unittest
 TEST_MODULES = [
     'tornado.httputil.doctests',
     'tornado.test.stack_context_test',
-    'tornado.test.test_ioloop',
+    'tornado.test.ioloop_test',
 ]
 
 def all():
diff --git a/tornado/test/test_ioloop.py b/tornado/test/test_ioloop.py
deleted file mode 100755 (executable)
index 2541fa8..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env python
-
-import unittest
-import time
-
-from tornado import ioloop
-
-
-class TestIOLoop(unittest.TestCase):
-    def setUp(self):
-        self.loop = ioloop.IOLoop()
-
-    def tearDown(self):
-        pass
-
-    def _callback(self):
-        self.called = True
-        self.loop.stop()
-
-    def _schedule_callback(self):
-        self.loop.add_callback(self._callback)
-        # Scroll away the time so we can check if we woke up immediately
-        self._start_time = time.time()
-        self.called = False
-
-    def test_add_callback(self):
-        self.loop.add_timeout(time.time(), self._schedule_callback)
-        self.loop.start() # Set some long poll timeout so we can check wakeup
-        self.assertAlmostEqual(time.time(), self._start_time, places=2)
-        self.assertTrue(self.called)
-
-
-if __name__ == "__main__":
-    import logging
-
-    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(msecs)03d %(levelname)-8s %(name)-8s %(message)s', datefmt='%H:%M:%S')
-
-    unittest.main()