コード例 #1
0
ファイル: test_this_queries.py プロジェクト: pvergain/xotl.ql
    def test_basic_queries(self):
        from xotl.ql.expressions import count
        query = these((parent.title + parent.name, count(child.toys))
                        for parent in this('parent')
                        if parent.age < 40
                        for child in parent.children
                        if child.age > 5)
        self.assertTrue(provides_any(query, IQueryObject))

        (parent_full_name, child_toys) = query.selection
        full_name_expectation = this('parent').title + this('parent').name
#        child_name_expectation = this('parent').children.name
        child_toys_expectation = count(this('parent').children.toys)

        parent_age_test = this('parent').age < 40
        children_age_test = this('parent').children.age > 5

        parent_token = this('parent')
        children_token = this('parent').children

        with context(UNPROXIFING_CONTEXT):
            self.assertEqual(parent_full_name, full_name_expectation)
#            self.assertEqual(child_name, child_name_expectation)
            self.assertEqual(child_toys, child_toys_expectation)

            filters = query.filters
            self.assertEqual(2, len(filters))
            self.assertIn(parent_age_test, filters)
            self.assertIn(children_age_test, filters)

            tokens = query.tokens
            self.assertEqual(2, len(tokens))
            self.assertIn(parent_token, tokens)
            self.assertIn(children_token, tokens)
コード例 #2
0
    def test_basic_queries(self):
        from xotl.ql.expressions import count
        query = these((parent.title + parent.name, count(child.toys))
                      for parent in this('parent') if parent.age < 40
                      for child in parent.children if child.age > 5)
        self.assertTrue(provides_any(query, IQueryObject))

        (parent_full_name, child_toys) = query.selection
        full_name_expectation = this('parent').title + this('parent').name
        #        child_name_expectation = this('parent').children.name
        child_toys_expectation = count(this('parent').children.toys)

        parent_age_test = this('parent').age < 40
        children_age_test = this('parent').children.age > 5

        parent_token = this('parent')
        children_token = this('parent').children

        with context(UNPROXIFING_CONTEXT):
            self.assertEqual(parent_full_name, full_name_expectation)
            #            self.assertEqual(child_name, child_name_expectation)
            self.assertEqual(child_toys, child_toys_expectation)

            filters = query.filters
            self.assertEqual(2, len(filters))
            self.assertIn(parent_age_test, filters)
            self.assertIn(children_age_test, filters)

            tokens = query.tokens
            self.assertEqual(2, len(tokens))
            self.assertIn(parent_token, tokens)
            self.assertIn(children_token, tokens)
コード例 #3
0
ファイル: test_this_queries.py プロジェクト: mvaled/xotl.ql
def test_basic_queries():
    from xotl.ql.expressions import count
    query = these((parent.title + parent.name, count(child.toys))
                    for parent in this('parent')
                    if parent.age < 40
                    for child in parent.children
                    if child.age > 5)
    assert provides_any(query, IQueryObject)

    (parent_full_name, child_toys) = query.selection
    full_name_expectation = this('parent').title + this('parent').name
    child_toys_expectation = count(this('parent').children.toys)

    parent_age_test = this('parent').age < 40
    children_age_test = this('parent').children.age > 5

    parent_token = this('parent')
    children_token = this('parent').children

    with context(UNPROXIFING_CONTEXT):
        assert parent_full_name == full_name_expectation
        assert child_toys == child_toys_expectation

        filters = query.filters
        assert len(filters) == 2
        assert parent_age_test in filters
        assert children_age_test in filters

        tokens = [tk.expression for tk in query.tokens]
        assert len(tokens) == 2
        assert parent_token in tokens
        assert children_token in tokens
コード例 #4
0
ファイル: test_expressions.py プロジェクト: mvaled/xotl.ql
 def test_expression(self):
     from xotl.ql.expressions import (count, ExpressionTree, or_, and_,
                                      pow_, lt, eq, add)
     expr = ((q(1) < 3) & (1 == q("1")) |
             (q("a") + q("b") ** 2 == q("x") + count("y")))
     expected = or_(and_(lt(1, 3), eq(1, "1")),
                    eq(add("a", pow_("b", 2)), add("x", count("y"))))
     self.assertIsInstance(expr, ExpressionTree)
     with context(UNPROXIFING_CONTEXT):
         self.assertTrue(expr == expected, "%s ---- %s" % (expected, expr))
コード例 #5
0
ファイル: test_expressions.py プロジェクト: pvergain/xotl.ql
 def test_expression(self):
     from xotl.ql.expressions import (count, ExpressionTree, or_, and_,
                                      pow_, lt, eq, add)
     expr = ((q(1) < 3) & (1 == q("1")) |
             (q("a") + q("b")**2 == q("x") + count("y")))
     expected = or_(and_(lt(1, 3), eq(1, "1")),
                    eq(add("a", pow_("b", 2)), add("x", count("y"))))
     self.assertIsInstance(expr, ExpressionTree)
     with context(UNPROXIFING_CONTEXT):
         self.assertTrue(expr == expected, "%s ---- %s" % (expected, expr))