Пример #1
0
def test_field_option_defaults(engine, graph):
    result = engine.execute(graph, read('[{:x1s [:buz2]}]'))
    check_result(
        result, {
            'x1s': [
                {
                    'buz2': 'a1 - 100'
                },
                {
                    'buz2': 'a3 - 100'
                },
                {
                    'buz2': 'a2 - 100'
                },
            ]
        })
    result = engine.execute(graph, read('[{:x1s [(:buz2 {:size 200})]}]'))
    check_result(
        result, {
            'x1s': [
                {
                    'buz2': 'a1 - 200'
                },
                {
                    'buz2': 'a3 - 200'
                },
                {
                    'buz2': 'a2 - 200'
                },
            ]
        })
Пример #2
0
def test_sequence_in_arg_type(engine, graph):
    result = engine.execute(graph, read('[{:x1s [:baz]}]'))
    check_result(result, {
        'x1s': [
            {
                'baz': 'D3 [B1]'
            },
            {
                'baz': 'D1 [B3]'
            },
            {
                'baz': 'D2 [B2]'
            },
        ]
    })
    result = engine.execute(graph, read('[{:y1s [:baz]}]'))
    check_result(result, {
        'y1s': [
            {
                'baz': 'D3 [B1]'
            },
            {
                'baz': 'D1 [B3]'
            },
            {
                'baz': 'D2 [B2]'
            },
        ]
    })
Пример #3
0
 def testSequenceInArgType(self):
     result = self.engine.execute(GRAPH, read('[{:x1s [:baz]}]'))
     self.assertResult(result, {'x1s': [
         {'baz': 'D3 [B1]'},
         {'baz': 'D1 [B3]'},
         {'baz': 'D2 [B2]'},
     ]})
     result = self.engine.execute(GRAPH, read('[{:y1s [:baz]}]'))
     self.assertResult(result, {'y1s': [
         {'baz': 'D3 [B1]'},
         {'baz': 'D1 [B3]'},
         {'baz': 'D2 [B2]'},
     ]})
Пример #4
0
 def testFieldOptionDefaults(self):
     result = self.engine.execute(GRAPH,
                                  read('[{:x1s [:buz2]}]'))
     self.assertResult(result, {'x1s': [
         {'buz2': 'a1 - 100'},
         {'buz2': 'a3 - 100'},
         {'buz2': 'a2 - 100'},
     ]})
     result = self.engine.execute(GRAPH,
                                  read('[{:x1s [(:buz2 {:size 200})]}]'))
     self.assertResult(result, {'x1s': [
         {'buz2': 'a1 - 200'},
         {'buz2': 'a3 - 200'},
         {'buz2': 'a2 - 200'},
     ]})
Пример #5
0
 def testField(self):
     result = self.engine.execute(GRAPH, read('[{:x1s [:a :f]}]'))
     self.assertResult(result, {'x1s': [
         {'a': 'a1', 'f': 7},
         {'a': 'a3', 'f': 7},
         {'a': 'a2', 'f': 7},
     ]})
Пример #6
0
    def testSubQuery(self):
        thread_pool = ThreadPoolExecutor(2)
        e = Engine(ThreadsExecutor(thread_pool))

        def query_a(fields, ids):
            data = {1: {'f': 2}}
            return [[data[i][f] for f in fields] for i in ids]

        r = graph.Edge(None, [
            graph.Edge('a', [
                graph.Field('f', query_a),
            ]),
        ])

        # ----------------------------------------------

        @define('[[:f]]', _name='inc_f')
        def inc_f(obj):
            return obj['f'] + 1

        r1 = graph.Edge(None, [
            graph.Edge('a1', subquery_fields(r, 'a', {
                'f1': inc_f(S.this),
            })),
            graph.Link('la1', None, 'a1', lambda: [1], True),
        ])

        self.assertEqual(
            e.execute(r1, read('[{:la1 [:f1]}]'))['la1'], [{
                'f1': 3
            }])
Пример #7
0
 def testField(self):
     result = self.engine.execute(HIGH_ENV, read('[{:xs1 [:a]}]'))
     self.assertResult(result, {'xs1': [
         {'a': 'a1'},
         {'a': 'a2'},
         {'a': 'a3'},
     ]})
Пример #8
0
    def testSubQuery(self):
        thread_pool = ThreadPoolExecutor(2)
        e = Engine(ThreadsExecutor(thread_pool))

        def query_a(fields, ids):
            data = {1: {'f': 2}}
            return [[data[i][f] for f in fields] for i in ids]

        r = graph.Edge(None, [
            graph.Edge('a', [
                graph.Field('f', query_a),
            ]),
        ])

        # ----------------------------------------------

        @define('[[:f]]', _name='inc_f')
        def inc_f(obj):
            return obj['f'] + 1

        r1 = graph.Edge(None, [
            graph.Edge('a1', subquery_fields(r, 'a', {
                'f1': inc_f(S.this),
            })),
            graph.Link('la1', None, 'a1', lambda: [1], True),
        ])

        self.assertEqual(e.execute(r1, read('[{:la1 [:f1]}]'))['la1'],
                         [{'f1': 3}])
Пример #9
0
 def testFieldOptions(self):
     result = self.engine.execute(GRAPH,
                                  read('[{:x1s [(:buz {:size "100"})]}]'))
     self.assertResult(result, {'x1s': [
         {'buz': 'a1 - 100'},
         {'buz': 'a3 - 100'},
         {'buz': 'a2 - 100'},
     ]})
Пример #10
0
 def testFieldWithoutOptions(self):
     result = self.engine.execute(GRAPH,
                                  read('[{:x1s [:buz]}]'))
     self.assertResult(result, {'x1s': [
         {'buz': 'a1 - None'},
         {'buz': 'a3 - None'},
         {'buz': 'a2 - None'},
     ]})
 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)
Пример #12
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()
Пример #13
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()
Пример #14
0
def index():
    fn = lookup.get('index/view')
    query_str = str(fn.query())
    print('QUERY:', query_str)

    hiku_query = read(query_str)
    result = engine.execute(GRAPH, hiku_query,
                            ctx=hiku_engine_ctx)
    print('RESULT:')
    pprint(denormalize(GRAPH, result, hiku_query))
    return fn.render(result)
Пример #15
0
    def check(self, src, value):
        sa_engine = create_engine(
            'sqlite://',
            connect_args={'check_same_thread': False},
            poolclass=StaticPool,
        )
        setup_db(sa_engine)

        engine = Engine(ThreadsExecutor(thread_pool))
        result = engine.execute(self.graph, read(src),
                                {SA_ENGINE_KEY: sa_engine})
        check_result(result, value)
Пример #16
0
    def check(self, src, value):
        sa_engine = create_engine(
            'sqlite://',
            connect_args={'check_same_thread': False},
            poolclass=StaticPool,
        )
        setup_db(sa_engine)

        engine = Engine(ThreadsExecutor(thread_pool))
        result = engine.execute(self.graph, read(src),
                                {SA_ENGINE_KEY: sa_engine})
        check_result(result, value)
Пример #17
0
def test_link_invalid_options():
    # missing options
    with pytest.raises(TypeError):
        read('[{(:foo) [:baz]}]')

    # invalid options type
    with pytest.raises(TypeError):
        read('[{(:foo :bar) [:baz]}]')

    # more arguments than expected
    with pytest.raises(TypeError):
        read('[{(:foo 1 2) [:bar]}]')

    # invalid option key
    with pytest.raises(TypeError):
        read('[{(:foo {1 2}) [:bar]}]')
Пример #18
0
def test_field_invalid_options():
    # missing options
    with pytest.raises(TypeError):
        read('[(:foo)]')

    # invalid options type
    with pytest.raises(TypeError):
        read('[(:foo :bar)]')

    # more arguments than expected
    with pytest.raises(TypeError):
        read('[(:foo 1 2)]')

    # invalid option key
    with pytest.raises(TypeError):
        read('[(:foo {1 2})]')
Пример #19
0
    def testLinkInvalidOptions(self):
        # missing options
        with self.assertRaises(TypeError):
            read('[{(:foo) [:baz]}]')

        # invalid options type
        with self.assertRaises(TypeError):
            read('[{(:foo :bar) [:baz]}]')

        # more arguments than expected
        with self.assertRaises(TypeError):
            read('[{(:foo 1 2) [:bar]}]')

        # invalid option key
        with self.assertRaises(TypeError):
            read('[{(:foo {1 2}) [:bar]}]')
Пример #20
0
    def testFieldInvalidOptions(self):
        # missing options
        with self.assertRaises(TypeError):
            read('[(:foo)]')

        # invalid options type
        with self.assertRaises(TypeError):
            read('[(:foo :bar)]')

        # more arguments than expected
        with self.assertRaises(TypeError):
            read('[(:foo 1 2)]')

        # invalid option key
        with self.assertRaises(TypeError):
            read('[(:foo {1 2})]')
Пример #21
0
def test_field_options(engine, graph):
    result = engine.execute(graph, read('[{:x1s [(:buz {:size "100"})]}]'))
    check_result(result, {
        'x1s': [
            {
                'buz': 'a1 - 100'
            },
            {
                'buz': 'a3 - 100'
            },
            {
                'buz': 'a2 - 100'
            },
        ]
    })
Пример #22
0
def test_field_without_options(engine, graph):
    result = engine.execute(graph, read('[{:x1s [:buz]}]'))
    check_result(
        result, {
            'x1s': [
                {
                    'buz': 'a1 - None'
                },
                {
                    'buz': 'a3 - None'
                },
                {
                    'buz': 'a2 - None'
                },
            ]
        })
Пример #23
0
def test_field(engine, graph):
    result = engine.execute(graph, read('[{:x1s [:a :f]}]'))
    check_result(result, {
        'x1s': [
            {
                'a': 'a1',
                'f': 7
            },
            {
                'a': 'a3',
                'f': 7
            },
            {
                'a': 'a2',
                'f': 7
            },
        ]
    })
Пример #24
0
def test_mixed_query(engine, graph):
    result = engine.execute(graph,
                            read('[{:x1s [(:with_option {:opt 123}) :a]}]'))
    check_result(
        result, {
            'x1s': [
                {
                    'a': 'a1',
                    'with_option': 7
                },
                {
                    'a': 'a3',
                    'with_option': 9
                },
                {
                    'a': 'a2',
                    'with_option': 8
                },
            ]
        })
Пример #25
0
 def testInvalidRoot(self):
     with self.assertRaises(TypeError):
         read('{:foo []}')
     with self.assertRaises(TypeError):
         read(':foo')
Пример #26
0
def check_read(source, query):
    first = read(source)
    assert first == query
Пример #27
0
 def execute(self, query):
     return self.engine.execute(TEST_ENV, read(query))
Пример #28
0
def check_read(source, query):
    first = read(source)
    with reqs_eq_patcher():
        assert first == query
Пример #29
0
def test_field_invalid():
    with pytest.raises(TypeError):
        read('["foo"]')
    with pytest.raises(TypeError):
        read('[1]')
Пример #30
0
def test_field_without_required_option(engine, graph):
    with pytest.raises(TypeError) as err:
        engine.execute(graph, read('[{:x1s [:buz3]}]'))
    err.match('^Required option "size" for (.*)buz3(.*) was not provided$')
Пример #31
0
 def testField(self):
     result = self.engine.execute(HIGH_ENV, read("[{:xs1 [:a]}]"))
     self.assertResult(result, {"xs1": [{"a": "a1"}, {"a": "a2"}, {"a": "a3"}]})
Пример #32
0
 def assertReads(self, source, query):
     first = read(source)
     with reqs_eq_patcher():
         self.assertEqual(first, query)
Пример #33
0
 def assertExecute(self, src, result):
     result = self.engine.execute(ENV, read(src))
     self.assertResult(result, result)
Пример #34
0
def check_result(query_string, result):
    new_result = denormalize(GRAPH, RESULT, read(query_string))
    json.dumps(new_result)  # using json to check for circular references
    assert new_result == result
Пример #35
0
def check_pb(query, expected):
    pb_root = t.Root()
    populate(pb_root, GRAPH, RESULT, read(query))
    assert pb_root == msg(t.Root, expected)
Пример #36
0
def check_result(query_string, result):
    query = merge([read(query_string)])
    new_result = denormalize(GRAPH, get_result(query))
    json.dumps(new_result)  # using json to check for circular references
    assert new_result == result
Пример #37
0
def check_result(query_string, result):
    new_result = denormalize(GRAPH, RESULT, read(query_string))
    json.dumps(new_result)  # using json to check for circular references
    assert new_result == result
Пример #38
0
 def testFieldInvalid(self):
     with self.assertRaises(TypeError):
         read('["foo"]')
     with self.assertRaises(TypeError):
         read('[1]')
Пример #39
0
async def execute(hiku_engine, sa_engine, graph, query_string):
    query = read(query_string)
    result = await hiku_engine.execute(graph, query,
                                       {SA_ENGINE_KEY: sa_engine})
    return denormalize(graph, result, query)
Пример #40
0
def test_link_invalid():
    with pytest.raises(TypeError):
        read('[{"foo" [:baz]}]')
    with pytest.raises(TypeError):
        read('[{foo [:baz]}]')
Пример #41
0
def test_invalid_root():
    with pytest.raises(TypeError):
        read('{:foo []}')
    with pytest.raises(TypeError):
        read(':foo')
Пример #42
0
def graph_endpoint():
    request_data = request.data.decode("utf-8")
    request_data = read(request_data)
    result = hiku_engine.execute(GRAPH, request_data)
    result = denormalize(GRAPH, result, request_data)
    return jsonify(result)
Пример #43
0
 def testLinkInvalid(self):
     with self.assertRaises(TypeError):
         read('[{"foo" [:baz]}]')
     with self.assertRaises(TypeError):
         read('[{foo [:baz]}]')
Пример #44
0
def execute(graph, query_string):
    query = read(query_string)
    result = hiku_engine.execute(graph, query, {SA_ENGINE_KEY: sa_engine})
    return denormalize(graph, result, query)
Пример #45
0
def execute(graph, query_string):
    query = read(query_string)
    result = hiku_engine.execute(graph, query, {SA_ENGINE_KEY: sa_engine})
    return denormalize(graph, result)
Пример #46
0
def execute(graph, query_string):
    query = read(query_string)
    result = hiku_engine.execute(graph, query)
    return denormalize(graph, result, query)
Пример #47
0
def execute(graph, query_string):
    query = read(query_string)
    result = hiku_engine.execute(graph, query)
    return denormalize(graph, result)
Пример #48
0
def execute(query_, ctx=None):
    engine = Engine(ThreadsExecutor(thread_pool))
    return engine.execute(get_graph(), read(query_), ctx=ctx)