Esempio n. 1
0
def test_ref_root_node_field():
    malatya_ref = NamedRef(None, 'malatya', ROOT_TYPES['malatya'])
    check_req(malatya_ref, Node([Link('malatya', Node([]))]))

    bartok_ref = NamedRef(malatya_ref, 'bartok',
                          ROOT_TYPES['malatya'].__field_types__['bartok'])
    check_req(bartok_ref, Node([Link('malatya', Node([Field('bartok')]))]))
Esempio n. 2
0
    def testEdgeField(self):
        x_ref = NamedRef(None, 'x', Env.x)
        self.assertReq(x_ref,
                       Edge([Link('x', Edge([]))]))

        a_ref = NamedRef(x_ref, 'a', Env.x.fields['a'])
        self.assertReq(a_ref,
                       Edge([Link('x', Edge([Field('a')]))]))
Esempio n. 3
0
def test_ref_link_many_node_field():
    comped_ref = NamedRef(None, 'comped', ROOT_TYPES['comped'])
    check_req(comped_ref, Node([Link('comped', Node([]))]))

    patens_ref = Ref(comped_ref, TYPES['patens'])
    check_req(patens_ref, Node([Link('comped', Node([]))]))

    clacks_ref = NamedRef(patens_ref, 'clacks',
                          TYPES['patens'].__field_types__['clacks'])
    check_req(clacks_ref, Node([Link('comped', Node([Field('clacks')]))]))
Esempio n. 4
0
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
Esempio n. 5
0
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'),
    ])
Esempio n. 6
0
def test_ref_link_one_node_field():
    weigh_ref = NamedRef(None, 'weigh', ROOT_TYPES['weigh'])
    check_req(weigh_ref, Node([Link('weigh', Node([]))]))

    patens_ref = Ref(weigh_ref, TYPES['patens'])
    check_req(patens_ref, Node([Link('weigh', Node([]))]))

    clacks_ref = NamedRef(patens_ref, 'clacks',
                          TYPES['patens'].__field_types__['clacks'])
    check_req(clacks_ref, Node([Link('weigh', Node([Field('clacks')]))]))
Esempio n. 7
0
def test_named_fragments():
    check_read(
        """
        query Juger {
          gilts {
            sneezer(gire: "noatak") {
              flowers
              ...Goaded
              apres
            }
            ... on Valium {
              movies {
                boree
              }
            }
          }
        }
        fragment Goaded on Makai {
          doozie
          pins {
            gunya
            ...Meer
          }
        }
        fragment Meer on Torsion {
          kilned {
            rusk
          }
        }
        """,
        Node([
            Link(
                'gilts',
                Node([
                    Link('sneezer',
                         Node([
                             Field('flowers'),
                             Field('doozie'),
                             Field('apres'),
                             Link(
                                 'pins',
                                 Node([
                                     Field('gunya'),
                                     Link('kilned', Node([
                                         Field('rusk'),
                                     ])),
                                 ])),
                         ]),
                         options={'gire': 'noatak'}),
                    Link('movies', Node([
                        Field('boree'),
                    ])),
                ])),
        ]),
    )
Esempio n. 8
0
 def testList(self):
     self.assertRequires(
         each(S.item, S.ys,
              [foo(S.item.x1, S.item), bar(S.item)]),
         Edge([
             Link('ys', Edge([
                 Field('d'), Field('e'), Field('f'),
                 Link('x1', Edge([Field('a'), Field('b'), Field('c')])),
             ])),
         ]),
     )
Esempio n. 9
0
def test_query_list():

    @define(Record[{'clacks': Any, 'panicle': Any}])
    def foo():
        pass

    check_query(
        each(S.x, S.comped, [foo(S.weigh), foo(S.x)]),
        Node([Link('comped', Node([Field('clacks'), Field('panicle')])),
              Link('weigh', Node([Field('clacks'), Field('panicle')]))]),
    )
Esempio n. 10
0
    def testLinkOneEdgeField(self):
        x1_ref = NamedRef(None, 'x1', Env.x1)
        self.assertReq(x1_ref,
                       Edge([Link('x1', Edge([]))]))

        x_ref = Ref(x1_ref, Env.x)
        self.assertReq(x_ref,
                       Edge([Link('x1', Edge([]))]))

        b_ref = NamedRef(x_ref, 'b', Env.x.fields['b'])
        self.assertReq(b_ref,
                       Edge([Link('x1', Edge([Field('b')]))]))
Esempio n. 11
0
    def testLinkListEdgeField(self):
        xs_ref = NamedRef(None, 'xs', Env.xs)
        self.assertReq(xs_ref,
                       Edge([Link('xs', Edge([]))]))

        x_ref = Ref(xs_ref, Env.x)
        self.assertReq(x_ref,
                       Edge([Link('xs', Edge([]))]))

        c_ref = NamedRef(x_ref, 'c', Env.x.fields['c'])
        self.assertReq(c_ref,
                       Edge([Link('xs', Edge([Field('c')]))]))
Esempio n. 12
0
 def testDict(self):
     self.assertRequires(
         each(S.item, S.ys,
              {'foo-value': foo(S.item.x1, S.item),
               'bar-value': bar(S.item)}),
         Edge([
             Link('ys', Edge([
                 Field('d'), Field('e'), Field('f'),
                 Link('x1', Edge([Field('a'), Field('b'), Field('c')])),
             ])),
         ]),
     )
Esempio n. 13
0
 def testTupleWithNestedLinkToMany(self):
     self.assertRequires(
         baz(S.y),
         Edge([Link('y',
                    Edge([Field('e'),
                          Link('xs', Edge([Field('b')]))]))]),
     )
     self.assertRequires(
         each(S.item, S.ys, baz(S.item)),
         Edge([Link('ys',
                    Edge([Field('e'),
                          Link('xs', Edge([Field('b')]))]))]),
     )
Esempio n. 14
0
 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')]))]),
         )
Esempio n. 15
0
def test_query_nested_optional_arg():

    @define(Record[{'una': Optional[Record[{'oloroso': Any}]]}])
    def foo(arg):
        pass

    check_query(
        foo(S.weigh),
        Node([
            Link('weigh', Node([
                Link('una', Node([Field('oloroso')])),
            ])),
        ]),
    )
Esempio n. 16
0
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'),
    ])
Esempio n. 17
0
def test_link_options():
    check_read(
        """
        [{(:foo {:bar 1}) [:baz]}]
        """,
        Node([Link('foo', Node([Field('baz')]), options={'bar': 1})]),
    )
Esempio n. 18
0
def test_link():
    node = t.Node()
    link_item = node.items.add()
    link_item.link.name = 'swaying'
    field_item = link_item.link.node.items.add()
    field_item.field.name = 'pelew'
    check_read(node, Node([Link('swaying', Node([Field('pelew')]))]))
Esempio n. 19
0
def test_link():
    check_read(
        """
        [{:foo [:bar :baz]}]
        """,
        Node([Link('foo', Node([Field('bar'), Field('baz')]))]),
    )
Esempio n. 20
0
def test():
    query = build([
        Q.tyan,
        Q.turlock[Q.gange],
        Q.tiber(ramsons='defaces')[Q.decifer(botches='auxerre'),
                                   Q.exocet(brogues='hygiea'), ],
    ])
    with reqs_eq_patcher():
        assert query == Node([
            Field('tyan'),
            Link('turlock', Node([Field('gange')])),
            Link(
                'tiber',
                Node([
                    Field('decifer', options={'botches': 'auxerre'}),
                    Field('exocet', options={'brogues': 'hygiea'}),
                ]), {'ramsons': 'defaces'}),
        ])
Esempio n. 21
0
def test_query_tuple_with_simple_args():

    @define(Record[{'clacks': Any, 'panicle': Any}],
            Any,
            Record[{'oloroso': Any, 'gashes': Any}],
            Any)
    def foo():
        pass

    check_query(
        foo(S.weigh, 1, S.weigh.apatite, 2),
        Node([Link('weigh',
                   Node([Field('clacks'),
                         Field('panicle'),
                         Link('apatite',
                              Node([Field('oloroso'),
                                    Field('gashes')]))]))]),
    )
Esempio n. 22
0
def test_complex_field_args():
    check_read(
        '{ saale(lammie: "nursy") { slighty } }',
        Node([
            Link('saale',
                 Node([Field('slighty')]),
                 options={'lammie': 'nursy'})
        ]),
    )
Esempio n. 23
0
def test_link_alias():
    check_read(
        '{ a: b { c d } }',
        Node([
            Link('b', Node([
                Field('c'),
                Field('d'),
            ]), alias='a'),
        ]),
    )
Esempio n. 24
0
def test_query_tuple_with_node():

    @define(Record[{'clacks': Any, 'panicle': Any}])
    def foo():
        pass

    @define(Record[{'oloroso': Any, 'gashes': Any}])
    def bar():
        pass

    sais_part = Node([Field('oloroso'), Field('gashes')])

    # 1
    check_query(
        foo(S.weigh),
        Node([Link('weigh', Node([Field('clacks'), Field('panicle')]))]),
    )
    # M
    check_query(
        each(S.x, S.comped, foo(S.x)),
        Node([Link('comped', Node([Field('clacks'), Field('panicle')]))]),
    )
    # 1:1
    check_query(
        bar(S.weigh.apatite),
        Node([Link('weigh', Node([Link('apatite', Node([Field('oloroso'),
                                                        Field('gashes')]))]))]),
    )
    # 1:M
    check_query(
        each(S.x, S.weigh.jakies, bar(S.x)),
        Node([Link('weigh', Node([Link('jakies', sais_part)]))]),
    )
    # M:1
    check_query(
        each(S.x, S.comped, bar(S.x.apatite)),
        Node([Link('comped', Node([Link('apatite', sais_part)]))]),
    )
    # M:M
    check_query(
        each(S.x, S.comped, each(S.y, S.x.jakies, bar(S.y))),
        Node([Link('comped', Node([Link('jakies', sais_part)]))]),
    )
Esempio n. 25
0
def test_query_optional_arg():

    @define(Optional[Record[{'clacks': Any}]])
    def foo(arg):
        pass

    check_query(
        foo(S.civics),
        Node([Link('civics', Node([Field('clacks')]))]),
    )
Esempio n. 26
0
def test_link_options():
    node = t.Node()
    link_item = node.items.add()
    link_item.link.name = 'dubiety'
    link_item.link.options['squat'] = 234
    link_item.link.options['liquid'] = 'ravages'
    field_item = link_item.link.node.items.add()
    field_item.field.name = 'gits'
    check_read(node, Node([Link('dubiety', Node([Field('gits')]),
                                {'squat': 234, 'liquid': 'ravages'})]))
Esempio n. 27
0
def test_query_tuple_with_nested_many_node():

    @define(Record[{'panicle': Any,
                    'jakies': Record[{'oloroso': Any,
                                      'gashes': Any}]}])
    def foo():
        pass

    sais_part = Node([Field('oloroso'), Field('gashes')])

    check_query(
        foo(S.weigh),
        Node([Link('weigh', Node([Field('panicle'),
                                  Link('jakies', sais_part)]))]),
    )
    check_query(
        each(S.x, S.comped, foo(S.x)),
        Node([Link('comped', Node([Field('panicle'),
                                   Link('jakies', sais_part)]))]),
    )
Esempio n. 28
0
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
Esempio n. 29
0
def test_link_options():
    node = query_pb2.Node()
    link = node.items.add().link
    link.name = 'pommee'
    link.options['takest'] = 3456
    link.options['decoy'] = 'nyroca'

    field = link.node.items.add().field
    field.name = 'fugazi'

    query = Node([
        Link('pommee',
             Node([Field('fugazi')]),
             options={
                 'takest': 3456,
                 'decoy': 'nyroca'
             })
    ])

    assert export(query) == node
Esempio n. 30
0
 def testTupleWithLinks(self):
     self.assertRequires(
         foo(S.x1, S.y1),
         Edge([Link('x1', Edge([Field('a'), Field('c')])),
               Link('y1', Edge([Field('d'), Field('f')]))]),
     )
     self.assertRequires(
         each(S.item, S.xs, foo(S.item, S.y1)),
         Edge([Link('xs', Edge([Field('a'), Field('c')])),
               Link('y1', Edge([Field('d'), Field('f')]))]),
     )
     self.assertRequires(
         each(S.item, S.ys, foo(S.x1, S.item)),
         Edge([Link('x1', Edge([Field('a'), Field('c')])),
               Link('ys', Edge([Field('d'), Field('f')]))]),
     )
     self.assertRequires(
         each(S.item, S.ys, foo(S.item.x1, S.item)),
         Edge([Link('ys', Edge([Field('d'), Field('f'),
                                Link('x1', Edge([Field('a'),
                                                 Field('c')]))]))]),
     )