Beispiel #1
0
def test_for_generator_as_sole_argument():
    from xotl.ql.core import QueryObject
    from xotl.ql.expressions import all_
    query = these(parent for parent in this
                  if all_(child.age < 5 for child in parent.children)
                  if all_(parent.children, this.age < 5)
                  if all_(this.children, this.age < 5))
    assert len(query.filters) == 3
    assert isinstance(query.filters[0].children[0], QueryObject)
Beispiel #2
0
def test_all_pred(**kwargs):
    from xoutil.iterators import dict_update_new
    from xotl.ql.expressions import all_, sum_
    from xotl.ql.translation.py import naive_translation
    query = these(parent
                  for parent in Person
                  if parent.children
                  if all_((30 < child.age) & (child.age < 36) for child in parent.children))
    dict_update_new(kwargs, dict(only='test_translate.*'))
    plan = naive_translation(query, **kwargs)
    result = list(plan())
    assert elsa in result
    assert papi in result
    assert len(result) == 2

    query = these(parent
                  for parent in Person
                  if parent.children
                  if all_(parent.name.startswith('Manu'), parent.age > 30))

    dict_update_new(kwargs, dict(only='test_translate.*'))
    plan = naive_translation(query, **kwargs)
    with pytest.raises(SyntaxError):
        result = list(plan())


    query = these(parent
                  for parent in Person
                  if parent.children
                  if sum_(child.age for child in parent.children) > 60)

    dict_update_new(kwargs, dict(only='test_translate.*'))
    plan = naive_translation(query, **kwargs)
    result = list(plan())
    assert denia in result
    assert pedro in result
    assert len(result) == 2