]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Remove hidden testsetup blocks from otherwise self-contained doctests.
authorBen Darnell <ben@bendarnell.com>
Sun, 2 Aug 2015 19:10:32 +0000 (15:10 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 2 Aug 2015 19:10:32 +0000 (15:10 -0400)
docs/queues.rst
tornado/locks.py
tornado/queues.py

index 5c8716eb0187ce010ca88f572c9328a02aed5229..06f99ab755b8a53e375d4b22c307f29561a944af 100644 (file)
@@ -3,11 +3,6 @@
 
 .. versionadded:: 4.2
 
-.. testsetup::
-
-    from tornado import ioloop, gen, queues
-    io_loop = ioloop.IOLoop.current()
-
 .. automodule:: tornado.queues
 
    Classes
index 4b0bdb38f1ea148bfab350a2b5590602d3a876f3..27e14953d34d6b4b728ffdfaf8863457c5106fee 100644 (file)
 # License for the specific language governing permissions and limitations
 # under the License.
 
-"""
-.. testsetup:: *
-
-    from tornado import ioloop, gen, locks
-    io_loop = ioloop.IOLoop.current()
-"""
-
 from __future__ import absolute_import, division, print_function, with_statement
 
 __all__ = ['Condition', 'Event', 'Semaphore', 'BoundedSemaphore', 'Lock']
@@ -61,7 +54,11 @@ class Condition(_TimeoutGarbageCollector):
 
     .. testcode::
 
-        condition = locks.Condition()
+        from tornado import gen
+        from tornado.ioloop import IOLoop
+        from tornado.locks import Condition
+
+        condition = Condition()
 
         @gen.coroutine
         def waiter():
@@ -80,7 +77,7 @@ class Condition(_TimeoutGarbageCollector):
             # Yield two Futures; wait for waiter() and notifier() to finish.
             yield [waiter(), notifier()]
 
-        io_loop.run_sync(runner)
+        IOLoop.current().run_sync(runner)
 
     .. testoutput::
 
@@ -92,7 +89,7 @@ class Condition(_TimeoutGarbageCollector):
     `wait` takes an optional ``timeout`` argument, which is either an absolute
     timestamp::
 
-        io_loop = ioloop.IOLoop.current()
+        io_loop = IOLoop.current()
 
         # Wait up to 1 second for a notification.
         yield condition.wait(timeout=io_loop.time() + 1)
@@ -161,7 +158,11 @@ class Event(object):
 
     .. testcode::
 
-        event = locks.Event()
+        from tornado import gen
+        from tornado.ioloop import IOLoop
+        from tornado.locks import Event
+
+        event = Event()
 
         @gen.coroutine
         def waiter():
@@ -180,7 +181,7 @@ class Event(object):
         def runner():
             yield [waiter(), setter()]
 
-        io_loop.run_sync(runner)
+        IOLoop.current().run_sync(runner)
 
     .. testoutput::
 
@@ -210,7 +211,7 @@ class Event(object):
 
     def clear(self):
         """Reset the internal flag to ``False``.
-        
+
         Calls to `.wait` will block until `.set` is called.
         """
         if self._future.done():
@@ -261,7 +262,8 @@ class Semaphore(_TimeoutGarbageCollector):
 
        from collections import deque
 
-       from tornado import gen, ioloop
+       from tornado import gen
+       from tornado.ioloop import IOLoop
        from tornado.concurrent import Future
 
        # Ensure reliable doctest output: resolve Futures one at a time.
@@ -273,14 +275,18 @@ class Semaphore(_TimeoutGarbageCollector):
                yield gen.moment
                f.set_result(None)
 
-       ioloop.IOLoop.current().add_callback(simulator, list(futures_q))
+       IOLoop.current().add_callback(simulator, list(futures_q))
 
        def use_some_resource():
            return futures_q.popleft()
 
     .. testcode:: semaphore
 
-        sem = locks.Semaphore(2)
+        from tornado import gen
+        from tornado.ioloop import IOLoop
+        from tornado.locks import Semaphore
+
+        sem = Semaphore(2)
 
         @gen.coroutine
         def worker(worker_id):
@@ -297,7 +303,7 @@ class Semaphore(_TimeoutGarbageCollector):
             # Join all workers.
             yield [worker(i) for i in range(3)]
 
-        io_loop.run_sync(runner)
+        IOLoop.current().run_sync(runner)
 
     .. testoutput:: semaphore
 
index 55ab4834ed244d722305f4e6d4b84c7629e7da6d..6d694cc4ce8a7480248c79f8090f87baeb0beb92 100644 (file)
@@ -51,7 +51,11 @@ class Queue(object):
 
     .. testcode::
 
-        q = queues.Queue(maxsize=2)
+        from tornado import gen
+        from tornado.ioloop import IOLoop
+        from tornado.queues import Queue
+
+        q = Queue(maxsize=2)
 
         @gen.coroutine
         def consumer():
@@ -71,19 +75,20 @@ class Queue(object):
 
         @gen.coroutine
         def main():
-            consumer()           # Start consumer.
+            # Start consumer without waiting (since it never finishes).
+            IOLoop.current().spawn_callback(consumer)
             yield producer()     # Wait for producer to put all tasks.
             yield q.join()       # Wait for consumer to finish all tasks.
             print('Done')
 
-        io_loop.run_sync(main)
+        IOLoop.current().run_sync(main)
 
     .. testoutput::
 
         Put 0
         Put 1
-        Put 2
         Doing work on 0
+        Put 2
         Doing work on 1
         Put 3
         Doing work on 2
@@ -266,7 +271,9 @@ class PriorityQueue(Queue):
 
     .. testcode::
 
-        q = queues.PriorityQueue()
+        from tornado.queues import PriorityQueue
+
+        q = PriorityQueue()
         q.put((1, 'medium-priority item'))
         q.put((0, 'high-priority item'))
         q.put((10, 'low-priority item'))
@@ -296,7 +303,9 @@ class LifoQueue(Queue):
 
     .. testcode::
 
-        q = queues.LifoQueue()
+        from tornado.queues import LifoQueue
+
+        q = LifoQueue()
         q.put(3)
         q.put(2)
         q.put(1)