Example #1
0
 def testEachExpr(self):
     self.assertCompiles(
         each(S.x, S.col,
              foo(S.x, S.x.a)),
         """
         [env['foo'](x, x['a']) for x in ctx['col']]
         """
     )
Example #2
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')])),
             ])),
         ]),
     )
Example #3
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')])),
             ])),
         ]),
     )
Example #4
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')]))]))]),
     )
Example #5
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')]))]))]),
     )
Example #6
0
 def testEdgeEachLinkField(self):
     self.assertRequires(
         each(S.item, S.y.xs, S.item.b),
         Edge([Link('y', Edge([Link('xs', Edge([Field('b')]))]))]),
     )
Example #7
0
 def testEachLinkField(self):
     self.assertRequires(
         each(S.item, S.xs, S.item.a),
         Edge([Link('xs', Edge([Field('a')]))]),
     )
Example #8
0
 def testEachExpr(self):
     self.assertCompiles(
         each(S.x, S.col, foo(S.x, S.x.a)), """
         [env['foo'](x, x['a']) for x in ctx['col']]
         """)
Example #9
0
    return '{y[d]} [{xs}]'.format(y=y, xs=xs).upper()


HIGH_ENV = Edge(None, [
    Edge('x1', subquery_fields(LOW_ENV, 'x', {
        'id': S.this.id,
        'a': S.this.a,
        'foo': foo(S.this, S.this.y),
        'bar': bar(S.this),
        'baz': baz(S.this.y),
        # 'y': S.this.y,
    })),
    Edge('y1', subquery_fields(LOW_ENV, 'y', {
        'id': S.this.id,
        'c': S.this.c,
        'foo': each(S.x, S.this.xs, foo(S.x, S.this)),
        'bar': each(S.x, S.this.xs, bar(S.x)),
        'baz': baz(S.this),
        # 'xs': S.this.xs,
    })),
    # TODO: links reuse
    Link('xs1', None, 'x1', to_x, to_list=True),
    Link('ys2', None, 'y2', to_y, to_list=True),
])


class TestSourceGraph(TestCase):

    def setUp(self):
        self.engine = Engine(ThreadsExecutor(ThreadPoolExecutor(2)))
Example #10
0
                    "foo": foo(S.this, S.this.y),
                    "bar": bar(S.this),
                    "baz": baz(S.this.y),
                    # 'y': S.this.y,
                },
            ),
        ),
        Edge(
            "y1",
            subquery_fields(
                LOW_ENV,
                "y",
                {
                    "id": S.this.id,
                    "c": S.this.c,
                    "foo": each(S.x, S.this.xs, foo(S.x, S.this)),
                    "bar": each(S.x, S.this.xs, bar(S.x)),
                    "baz": baz(S.this),
                    # 'xs': S.this.xs,
                },
            ),
        ),
        # TODO: links reuse
        Link("xs1", None, "x1", to_x, to_list=True),
        Link("ys2", None, "y2", to_y, to_list=True),
    ],
)


class TestSourceGraph(TestCase):
    def setUp(self):