예제 #1
0
def use_cassette_and_stub_time_sleep(cassette_name, **kwargs):
    context = pn_vcr.use_cassette(cassette_name, **kwargs)
    full_path = "{}/{}".format(pn_vcr.cassette_library_dir, cassette_name)
    cs = context.cls(path=full_path).load(path=full_path)

    if "filter_query_parameters" in kwargs:
        kwargs["filter_query_parameters"].append("pnsdk")

    import tornado.gen

    @tornado.gen.coroutine
    def returner():
        return

    def _inner(f):
        @patch("tornado.gen.sleep", return_value=returner())
        @six.wraps(f)
        def stubbed(*args, **kwargs):
            with context:
                largs = list(args)
                # 1 - index
                largs.pop(1)
                return f(*largs, **kwargs)

        @six.wraps(f)
        def original(*args):
            with context:
                return f(*args)

        return stubbed if len(cs) > 0 else original

    return _inner
예제 #2
0
def get_sleeper(cassette_name):
    """
    Loads cassette just to check if it is in record or playback mode
    """
    context = pn_vcr.use_cassette(cassette_name)
    full_path = "{}/{}".format(pn_vcr.cassette_library_dir, cassette_name)
    cs = context.cls(path=full_path).load(path=full_path)

    import asyncio

    @asyncio.coroutine
    def fake_sleeper(v):
        yield from asyncio.sleep(0)

    def decorate(f):
        @six.wraps(f)
        def call(*args, event_loop=None):
            yield from f(*args,
                         sleeper=(fake_sleeper if
                                  (len(cs) > 0) else asyncio.sleep),
                         event_loop=event_loop)

        return call

    return decorate
예제 #3
0
def use_cassette_and_stub_time_sleep(cassette_name, **kwargs):
    context = pn_vcr.use_cassette(cassette_name, **kwargs)
    full_path = "{}/{}".format(pn_vcr.cassette_library_dir, cassette_name)
    cs = context.cls(path=full_path).load(path=full_path)

    import tornado.gen

    @tornado.gen.coroutine
    def returner():
        return

    def _inner(f):
        @patch('tornado.gen.sleep', return_value=returner())
        @six.wraps(f)
        def stubbed(*args, **kwargs):
            with context:
                largs = list(args)
                # 1 - index
                largs.pop(1)
                return f(*largs, **kwargs)

        @six.wraps(f)
        def original(*args):
            with context:
                return f(*args)

        return stubbed if len(cs) > 0 else original

    return _inner
예제 #4
0
def get_sleeper(cassette_name):
    """
    Loads cassette just to check if it is in record or playback mode
    """
    context = pn_vcr.use_cassette(cassette_name)
    full_path = "{}/{}".format(pn_vcr.cassette_library_dir, cassette_name)
    cs = context.cls(path=full_path).load(path=full_path)

    import asyncio

    @asyncio.coroutine
    def fake_sleeper(v):
        yield from asyncio.sleep(0)

    def decorate(f):
        @six.wraps(f)
        def call(*args, event_loop=None):
            yield from f(*args, sleeper=(fake_sleeper if (len(cs) > 0) else asyncio.sleep), event_loop=event_loop)

        return call
    return decorate