Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def method(*args, **kw):
calls.append((args, kw))
return "OHAI"
f0 = txaio.as_future(method, 1, 2, 3, key='word')
f1 = txaio.as_future(foo)
f2 = txaio.gather([f0, f1])
def done(arg):
results.append(arg)
def error(fail):
errors.append(fail)
# fail.printTraceback()
txaio.add_callbacks(f2, done, error)
for f in [f0, f1, f2]:
_await(f)
assert len(results) == 1
assert len(errors) == 0
assert results[0] == ['OHAI', 42] or results[0] == [42, 'OHAI']
assert len(calls) == 2
assert calls[0] == ((1, 2, 3), dict(key='word'))
assert calls[1] == (tuple(), dict())
results = []
calls = []
def foo():
def codependant(*args, **kw):
calls.append((args, kw))
return 42
return txaio.as_future(codependant)
def method(*args, **kw):
calls.append((args, kw))
return "OHAI"
f0 = txaio.as_future(method, 1, 2, 3, key='word')
f1 = txaio.as_future(foo)
f2 = txaio.gather([f0, f1])
def done(arg):
results.append(arg)
def error(fail):
errors.append(fail)
# fail.printTraceback()
txaio.add_callbacks(f2, done, error)
for f in [f0, f1, f2]:
_await(f)
assert len(results) == 1
assert len(errors) == 0
assert results[0] == ['OHAI', 42] or results[0] == [42, 'OHAI']
assert len(calls) == 2
def test_emit_noop(handler, framework):
"""
emit() with a too-low level is an no-op.
"""
logger = txaio.make_logger()
old_log = txaio.get_global_log_level()
txaio.set_global_log_level("info")
logger.emit("debug", "foobar")
txaio.set_global_log_level(old_log)
assert len(handler.messages) == 0
def test_emit_noop(handler, framework):
"""
emit() with a too-low level is an no-op.
"""
logger = txaio.make_logger()
old_log = txaio.get_global_log_level()
txaio.set_global_log_level("info")
logger.emit("debug", "foobar")
txaio.set_global_log_level(old_log)
assert len(handler.messages) == 0
def __init__(self):
self.log = txaio.make_logger()
def test_callback(framework):
f = txaio.create_future()
results = []
def cb(f):
results.append(f)
txaio.add_callbacks(f, cb, None)
txaio.resolve(f, "it worked")
run_once()
assert len(results) == 1
assert results[0] == "it worked"
def test_is_future_generic(framework):
'''
Returning an immediate value from as_future
'''
f = txaio.create_future('result')
assert txaio.is_future(f)
def test_as_future_immediate(framework):
'''
Returning an immediate value from as_future
'''
errors = []
results = []
calls = []
def method(*args, **kw):
calls.append((args, kw))
return 42
f = txaio.as_future(method, 1, 2, 3, key='word')
def cb(x):
results.append(x)
def errback(f):
errors.append(f)
txaio.add_callbacks(f, cb, errback)
run_once()
assert len(results) == 1
assert len(errors) == 0
assert results[0] == 42
assert calls[0] == ((1, 2, 3), dict(key='word'))
def foo():
def codependant(*args, **kw):
calls.append((args, kw))
return 42
return txaio.as_future(codependant)
# parse command line parameters
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--debug', action='store_true', help='Enable debug output.')
parser.add_argument('--url', dest='url', type=six.text_type, default=url,
help='The router URL (default: "ws://localhost:8080/ws").')
parser.add_argument('--realm', dest='realm', type=six.text_type, default=realm,
help='The realm to join (default: "realm1").')
args = parser.parse_args()
# start logging
if args.debug:
txaio.start_logging(level='debug')
else:
txaio.start_logging(level='info')
# any extra info we want to forward to our ClientSession (in self.config.extra)
extra = {
u'foobar': u'A custom value'
}
# now actually run a WAMP client using our session class ClientSession
runner = ApplicationRunner(url=args.url, realm=args.realm, extra=extra)
runner.run(ClientSession, auto_reconnect=True)