def test_distinct_by_name_fields(): query = Node([ Field('a'), Field('b', options={'x': 1}, alias='a'), Field('a'), ]) assert merge([query]) == Node([ Field('a'), Field('b', options={'x': 1}, alias='a'), ])
def test(): q1 = Node([Field('a1'), Field('a2'), Link('b', Node([Field('b1'), Field('b2')]))]) q2 = Node([Field('a2'), Field('a3'), Link('b', Node([Field('b2'), Field('b3')]))]) query = merge([q1, q2]) expected = Node([Field('a1'), Field('a2'), Field('a3'), Link('b', Node([Field('b1'), Field('b2'), Field('b3')]))]) with reqs_eq_patcher(): assert query == expected
def test_distinct_by_name_links(): query = Node([ Link('a', Node([Field('c')])), Link('b', Node([Field('d')]), options={'x': 1}, alias='a'), Link('a', Node([Field('e')])), ]) assert merge([query]) == Node([ Link('a', Node([Field('c'), Field('e')])), Link('b', Node([Field('d')]), options={'x': 1}, alias='a'), ])
def test_distinct_by_options_fields(): query = Node([ Field('a'), Field('a', options={'x': 1}), Field('a'), ]) assert merge([query]) == Node([ Field('a'), Field('a', options={'x': 1}), ])
def query_func(queue, task_set, edge, fields, ids): this_link = Link(THIS_LINK_NAME, None, sub_edge_name, None, True) reqs = merge(reqs_map[f.name] for f in fields) # FIXME: implement proper way to handle "this" value # and query other possible data from sub_root pattern = reqs.fields['this'].edge procs = [procs_map[f.name] for f in fields] query = Query(queue, task_set, sub_root, None) query._process_link(sub_root, this_link, pattern, None, ids) return _create_result_proc(query, fn_env, edge, fields, procs, ids)
def test(self): with reqs_eq_patcher(): self.assertEqual( merge([ Edge([Field('a1'), Field('a2'), Link('b', Edge([Field('b1'), Field('b2')]))]), Edge([Field('a2'), Field('a3'), Link('b', Edge([Field('b2'), Field('b3')]))]), ]), Edge([Field('a1'), Field('a2'), Field('a3'), Link('b', Edge([Field('b1'), Field('b2'), Field('b3')]))]), )
def test_alias(): query = merge([ Node([ Field('a', alias='a1'), Field('a', alias='a2'), Link('b', Node([Field('c')]), alias='b1'), Link('b', Node([Field('c')]), alias='b2'), ]), ]) assert query == Node([ Field('a', alias='a1'), Field('a', alias='a2'), Link('b', Node([Field('c')]), alias='b1'), Link('b', Node([Field('c')]), alias='b2'), ])
def test_denormalize_non_merged_query(): index = Index() index.root.update({ 'x': Reference('X', 'xN'), }) index['X']['xN'].update({ 'a': 1, 'b': 2, }) index.finish() graph = Graph([ Node('X', [ Field('a', None, None), Field('b', None, None), ]), Root([ Link('x', TypeRef['X'], lambda: 'xN', requires=None), ]), ]) non_merged_query = hiku_query.Node([ hiku_query.Link('x', hiku_query.Node([ hiku_query.Field('a'), ])), hiku_query.Link('x', hiku_query.Node([ hiku_query.Field('b'), ])), ]) with pytest.raises(KeyError) as err: denormalize(graph, Proxy(index, ROOT, non_merged_query)) err.match("Field u?'a' wasn't requested in the query") merged_query = merge([non_merged_query]) assert denormalize(graph, Proxy(index, ROOT, merged_query)) == { 'x': { 'a': 1, 'b': 2 }, }
def test(): query = merge([ Node([ Field('a1'), Field('a1'), Field('a2'), Field('a2'), Link('b', Node([ Field('b1'), Field('b2'), ]), options={'x': 1}), ]), Node([ Field('a2'), Field('a2'), Field('a3'), Field('a3'), Link('b', Node([ Field('b2'), Field('b3'), ]), options={'x': 1}), ]), ]) expected = Node([ Field('a1'), Field('a2'), Field('a3'), Link('b', Node([ Field('b1'), Field('b2'), Field('b3'), ]), options={'x': 1}), ]) assert query == expected
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