Пример #1
0
def test_with_pass_context(graph_name, sample_count):
    def root_fields1(fields):
        return [1 for _ in fields]

    @pass_context
    def root_fields2(ctx, fields):
        return [2 for _ in fields]

    graph = Graph([
        Root([
            Field('a', None, root_fields1),
            Field('b', None, root_fields2),
        ]),
    ])

    graph = apply(graph, [GraphMetrics(graph_name)])

    assert sample_count('Root', 'a') is None
    assert sample_count('Root', 'b') is None

    result = Engine(SyncExecutor()).execute(
        graph, q.Node([
            q.Field('a'),
            q.Field('b'),
        ]))
    check_result(result, {
        'a': 1,
        'b': 2,
    })

    assert sample_count('Root', 'a') == 1.0
    assert sample_count('Root', 'b') == 1.0
 async def _check(self, src, value):
     sa_engine = create_async_engine(self.db_dsn)
     engine = Engine(AsyncIOExecutor())
     try:
         result = await engine.execute(self.graph, read(src),
                                       {SA_ENGINE_KEY: sa_engine})
         check_result(result, value)
     finally:
         await greenlet_spawn(sa_engine.sync_engine.dispose)
Пример #3
0
 def _check(self, src, value, event_loop):
     sa_engine = yield from aiopg.sa.create_engine(self.db_dsn, minsize=0, loop=event_loop)
     try:
         engine = Engine(AsyncIOExecutor(event_loop))
         result = yield from engine.execute(self.graph, read(src), {SA_ENGINE_KEY: sa_engine})
         check_result(result, value)
     finally:
         sa_engine.close()
         yield from sa_engine.wait_closed()
Пример #4
0
 async def _check(self, src, value):
     sa_engine = await aiopg.sa.create_engine(self.db_dsn, minsize=0)
     engine = Engine(AsyncIOExecutor())
     try:
         result = await engine.execute(self.graph, read(src),
                                       {SA_ENGINE_KEY: sa_engine})
         check_result(result, value)
     finally:
         sa_engine.close()
         await sa_engine.wait_closed()
Пример #5
0
async def test_simple_async(graph_name, sample_count):
    async def x_fields(fields, ids):
        return [[42 for _ in fields] for _ in ids]

    async def root_fields(fields):
        return [1 for _ in fields]

    async def x_link():
        return 2

    ll_graph = Graph([
        Node('X', [
            Field('id', None, x_fields),
        ]),
    ])

    x_sg = SubGraph(ll_graph, 'X')

    hl_graph = Graph([
        Node('X', [
            Field('id', None, x_sg),
        ]),
        Root([
            Field('a', None, root_fields),
            Link('x', TypeRef['X'], x_link, requires=None),
        ]),
    ])

    hl_graph = apply(hl_graph, [AsyncGraphMetrics(graph_name)])

    query = q.Node([
        q.Field('a'),
        q.Link('x', q.Node([
            q.Field('id'),
        ])),
    ])

    engine = Engine(AsyncIOExecutor())

    assert sample_count('Root', 'a') is None
    assert sample_count('Root', 'x') is None
    assert sample_count('X', 'id') is None

    result = await engine.execute(hl_graph, query)
    check_result(result, {
        'a': 1,
        'x': {
            'id': 42,
        },
    })

    assert sample_count('Root', 'a') == 1.0
    assert sample_count('Root', 'x') == 1.0
    assert sample_count('X', 'id') == 1.0