def test_ioloop_schedule_now_units(self):
     loop = ioloop.IOLoop.instance()
     scheduler = IOLoopScheduler(loop)
     diff = scheduler.now
     sleep(0.1)
     diff = scheduler.now - diff
     assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
    def test_ioloop_schedule_action(self):
        loop = ioloop.IOLoop.instance()

        scheduler = IOLoopScheduler(loop)
        ran = False

        def action(scheduler, state):
            nonlocal ran
            ran = True

        scheduler.schedule(action)

        def done():
            assert ran is True
            loop.stop()

        loop.call_later(0.1, done)
        loop.start()
    def test_ioloop_schedule_action_cancel(self):
        loop = ioloop.IOLoop.instance()

        ran = False
        scheduler = IOLoopScheduler(loop)

        def action(scheduler, state):
            nonlocal ran
            ran = True

        d = scheduler.schedule_relative(0.01, action)
        d.dispose()

        def done():
            assert ran is False
            loop.stop()

        loop.call_later(0.1, done)
        loop.start()
    def test_ioloop_schedule_action_due(self):
        loop = ioloop.IOLoop.instance()

        scheduler = IOLoopScheduler(loop)
        starttime = loop.time()
        endtime = None

        def action(scheduler, state):
            nonlocal endtime
            endtime = loop.time()

        scheduler.schedule_relative(0.2, action)

        def done():
            assert endtime is not None
            diff = endtime - starttime
            assert diff > 0.18
            loop.stop()

        loop.call_later(0.3, done)
        loop.start()
예제 #5
0
"""

import os

from tornado.websocket import WebSocketHandler
from tornado.web import RequestHandler, StaticFileHandler, Application, url
from tornado.httpclient import AsyncHTTPClient
from tornado.httputil import url_concat
from tornado.escape import json_decode
from tornado import ioloop

from rx import operators as ops
from rx.subjects import Subject
from rx.scheduler.eventloop import IOLoopScheduler

scheduler = IOLoopScheduler(ioloop.IOLoop.current())


def search_wikipedia(term):
    """Search Wikipedia for a given term"""
    url = 'http://en.wikipedia.org/w/api.php'

    params = {"action": 'opensearch', "search": term, "format": 'json'}
    # Must set a user agent for non-browser requests to Wikipedia
    user_agent = "RxPY/3.0 (https://github.com/dbrattli/RxPY; [email protected]) Tornado/4.0.1"

    url = url_concat(url, params)

    http_client = AsyncHTTPClient()
    return http_client.fetch(url, method='GET', user_agent=user_agent)
 def test_ioloop_schedule_now(self):
     loop = ioloop.IOLoop.instance()
     scheduler = IOLoopScheduler(loop)
     diff = scheduler.now - datetime.utcfromtimestamp(loop.time())
     assert abs(diff) < timedelta(milliseconds=1)