async def test_context_create(loop): conf = Config() conf.update( MergeDict({ 'q.cls': 'aioworkers.queue.timeout.TimestampQueue', 'f.e': 1, })) c = Context(conf, loop=loop) await c.init() await c.start() assert c.config.f.e == 1 with pytest.raises(AttributeError): c.r with pytest.raises(KeyError): c['r'] async def handler(context): pass c.on_stop.append(handler) async def handler(): raise ValueError c.on_stop.append(handler) c.on_stop.append(handler()) c.on_stop.append(1) await c.stop()
async def test_q(loop): conf = Config() conf.update({'q.cls': utils.import_uri(proxy.ProxyQueue)}) async with Context(conf, loop=loop) as ctx: ctx.q.set_queue(Queue()) await ctx.q.put(1) assert 1 == await ctx.q.get()
def config(config_yaml): from aioworkers.core.config import Config c = Config() if config_yaml: import yaml loader = getattr(yaml, 'CLoader', yaml.Loader) c.update(yaml.load(config_yaml, loader)) return c
def config(aioworkers, config_yaml): from aioworkers.core.config import Config c = Config() if aioworkers.plugins.default: c.load_plugins() if aioworkers.plugins: c.load_plugins(*aioworkers.plugins) for data in yaml_load_all(config_yaml): c.update(data) return c
async def test_plq(loop): conf = Config() conf.update({ 'q.cls': utils.import_uri(proxy.PipeLineQueue), 'q.format': 'newline:str', }) async with Context(conf, loop=loop) as ctx: fin = io.BytesIO(b'123\n') fout = io.BytesIO() ctx.q.set_reader(fin) ctx.q.set_writer(fout) assert '123' == await ctx.q.get() await ctx.q.put('1') assert b'1\n' == fout.getvalue()
def test_from_env(): os.environ['TEST'] = 'DEBUG' c = Config() c.update({ 'env.x.y': 'TEST', 'env.x': {'z': 'TEST'}, 'env': {'z': 'TEST'}, 'env.logging.root.level': 'TEST', }) assert c._env == { 'x.y': 'TEST', 'x.z': 'TEST', 'z': 'TEST', 'logging.root.level': 'TEST', } assert c.x.y == c.x.z == c.z == 'DEBUG' assert c.logging['root']['level'] == 'DEBUG'
async def test_close_connector(loop): from aioworkers.core.config import Config from aioworkers.core.context import Context c = Config() c.update( { "mongo": { "cls": "aioworkers_mongo.base.Connector", "uri": "mongodb://localhost:27017/", } } ) async with Context(c, loop=loop) as ctx: assert ctx.mongo._client # Check that client has been stopped. # TODO Find better way to check that MongoClient has been closed. assert not ctx.mongo._client.delegate._topology._opened