Ejemplo n.º 1
0
def test_name_collision():
    check_compiles(
        each(S.i, S.ys,
             each(S.i, S.i.xs, bar(S.i.b))),
        """
        [[env['bar'](i_2['b']) for i_2 in i['xs']] for i in ctx['ys']]
        """
    )
Ejemplo n.º 2
0
 def testNameCollision(self):
     self.assertCompiles(
         each(S.i, S.ys,
              each(S.i, S.i.xs, bar(S.i.b))),
         """
         [[env['bar'](i_2['b']) for i_2 in i['xs']] for i in ctx['ys']]
         """
     )
Ejemplo n.º 3
0
 def testEachExpr(self):
     self.assertCompiles(
         each(S.i, S.ys,
              baz(S.a, S.i)),
         """
         [env['baz'](ctx['a'], i) for i in ctx['ys']]
         """
     )
Ejemplo n.º 4
0
def test_each_expr():
    check_compiles(
        each(S.i, S.ys,
             baz(S.a, S.i)),
        """
        [env['baz'](ctx['a'], i) for i in ctx['ys']]
        """
    )
Ejemplo n.º 5
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)]))]),
    )
Ejemplo n.º 6
0
def test_query_tuple_with_node():

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

    @define(Record[{'oloroso': Unknown, 'gashes': Unknown}])
    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)]))]),
    )
Ejemplo n.º 7
0
def test_query_list():

    @define(Record[{'clacks': Unknown, 'panicle': Unknown}])
    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')]))]),
    )
Ejemplo n.º 8
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')]))]),
    )
Ejemplo n.º 9
0
def test_each_sequence_of_scalar():
    types = {
        '__root__': Record[{
            'foo': Sequence[Integer]
        }],
    }
    ast = check_expr(types, each(S.x, S.foo, S.x))
    _, x1, _, x2 = ast.values
    ref_chain = [
        (None, Integer),
        ('foo', Sequence[Integer]),
    ]
    check_ref(x1, ref_chain)
    check_ref(x2, ref_chain)
Ejemplo n.º 10
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)]))]),
    )
Ejemplo n.º 11
0
def test_each_sequence_of_record():
    types = {
        'Bar': Record[{
            'baz': Integer
        }],
        'Foo': Record[{
            'bar': 'Bar'
        }],
        '__root__': Record[{
            'foo': Sequence['Foo']
        }],
    }
    ast = check_expr(types, each(S.x, S.foo, S.x.bar.baz))
    _, _, _, x_bar_baz = ast.values
    check_ref(x_bar_baz, [
        ('baz', Integer),
        ('bar', TypeRef['Bar']),
        (None, TypeRef['Foo']),
        ('foo', Sequence[TypeRef['Foo']]),
    ])
Ejemplo n.º 12
0
def test_query_tuple_with_nested_many_node():

    @define(Record[{'panicle': Unknown,
                    'jakies': Record[{'oloroso': Unknown,
                                      'gashes': Unknown}]}])
    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)]))]),
    )
Ejemplo n.º 13
0
def test_if_some_optional():
    types = {
        'Bar': Record[{
            'baz': Integer
        }],
        'Foo': Record[{
            'bar': Sequence['Bar']
        }],
        '__root__': Record[{
            'foo': Optional['Foo']
        }],
    }
    ast = check_expr(types,
                     if_some([S.x, S.foo], each(S.y, S.x.bar, S.y.baz), None))
    _, _, each_ast, _ = ast.values
    _, _, _, y_baz = each_ast.values
    check_ref(y_baz, [
        ('baz', Integer),
        (None, TypeRef['Bar']),
        ('bar', Sequence[TypeRef['Bar']]),
        (None, TypeRef['Foo']),
        ('foo', Optional[TypeRef['Foo']]),
    ])
Ejemplo n.º 14
0
              sg_x.c(buz(S.this, S.size)),
              options=[Option('size', None, default=None)]),
        Field('buz2',
              None,
              sg_x.c(buz(S.this, S.size)),
              options=[Option('size', None, default=100)]),
        Field('buz3',
              None,
              sg_x.c(buz(S.this, S.size)),
              options=[Option('size', None)]),
    ]),
    Node('y1', [
        Field('id', None, sg_y),
        Field('c', None, sg_y),
        Field('f', None, sg_y.c(S.f2)),
        Field('foo', None, sg_y.c(each(S.x, S.this.xs, foo(S.x, S.this)))),
        Field('bar', None, sg_y.c(each(S.x, S.this.xs, bar(S.x)))),
        Field('baz', None, sg_y.c(baz(S.this))),
    ]),
    Root([
        Link('x1s', Sequence[TypeRef['x1']], to_x, requires=None),
        Link('y1s', Sequence[TypeRef['y1']], to_y, requires=None),
    ]),
])


@pytest.fixture(name='engine')
def _engine():
    return Engine(ThreadsExecutor(ThreadPoolExecutor(2)))

Ejemplo n.º 15
0
    Node('x1', [
        Expr('id', sg_x, S.this.id),
        Expr('a', sg_x, S.this.a),
        Expr('f', sg_x, S.f1),
        Expr('foo', sg_x, foo(S.this, S.this.y)),
        Expr('bar', sg_x, bar(S.this)),
        Expr('baz', sg_x, baz(S.this.y)),
        Expr('buz', sg_x, buz(S.this, S.size), options=[Option('size', None)]),
        Expr('buz2', sg_x, buz(S.this, S.size),
             options=[Option('size', None, default=100)]),
    ]),
    Node('y1', [
        Expr('id', sg_y, S.this.id),
        Expr('c', sg_y, S.this.c),
        Expr('f', sg_y, S.f2),
        Expr('foo', sg_y, each(S.x, S.this.xs, foo(S.x, S.this))),
        Expr('bar', sg_y, each(S.x, S.this.xs, bar(S.x))),
        Expr('baz', sg_y, baz(S.this)),
    ]),
    Root([
        Link('x1s', Sequence[TypeRef['x1']], to_x, requires=None),
        Link('y1s', Sequence[TypeRef['y1']], to_y, requires=None),
    ]),
])


class TestSourceGraph(TestCase):

    def setUp(self):
        self.engine = Engine(ThreadsExecutor(ThreadPoolExecutor(2)))
Ejemplo n.º 16
0
def test_query_each_root_node_link_field():
    check_query(
        each(S.item, S.malatya.wandy, S.item.clacks),
        Node([Link('malatya', Node([Link('wandy', Node([Field('clacks')]))]))]),
    )
Ejemplo n.º 17
0
def test_query_each_node_field():
    check_query(
        each(S.item, S.comped, S.item.clacks),
        Node([Link('comped', Node([Field('clacks')]))]),
    )
Ejemplo n.º 18
0
def test_query_each_node_field():
    check_query(
        each(S.item, S.comped, S.item.clacks),
        Node([Link('comped', Node([Field('clacks')]))]),
    )
Ejemplo n.º 19
0
def test_query_each_root_node_link_field():
    check_query(
        each(S.item, S.malatya.wandy, S.item.clacks),
        Node([Link('malatya', Node([Link('wandy', Node([Field('clacks')]))]))]),
    )