Пример #1
0
def test_plain_iter():
    with bubbling():
        t1 = next(iter(this))
    with context(UNPROXIFING_CONTEXT):
        assert IBoundTerm.providedBy(t1)

    t1 = next(parent for parent in this('parent'))
    assert 'parent' == unboxed(t1).name

    t1 = next(parent for parent in this('parent').children)
    assert 'children' == unboxed(t1).name
Пример #2
0
def test_right_bindings_for_each_term():
    query = these((child, brother)
                  for parent in this
                  for child in parent.children
                  for brother in parent.children
                  if child is not brother)

    child, brother = query.selection
    # XXX: This assume the order of the tokens is mantained!!!
    _this, child_token, brother_token = tuple(query.tokens)
    assert unboxed(child).binding is child_token
    assert unboxed(brother).binding is brother_token
Пример #3
0
    def test_plain_iter(self):
        t1 = next(iter(this))
        with context(UNPROXIFING_CONTEXT):
            self.assertTrue(IQueryPart.providedBy(t1),
                                  'When itering over a this instance we '
                                  'should get an IQueryPart object')

        t1 = next(parent for parent in this('parent'))
        self.assertEquals('parent', unboxed(unboxed(t1)._expression).name,
                          'The name of the QueryBuilderToken should be '
                          'the same as the name of the actual instance')

        t1 = next(parent for parent in this('parent').children)
        self.assertEquals('children', unboxed(unboxed(t1)._expression).name,
                          'The name of the QueryBuilderToken should be '
                          'the same as the name of the actual instance')
Пример #4
0
 def __call__(self, *children, **named):
     resolve_arguments = getattr(self, '_resolve_arguments', None)
     if resolve_arguments:
         children, named = resolve_arguments(*children, **named)
     if children:
         stack = context
         head, tail = children[0], children[1:]
         name = getattr(self, '_method_name', None)
         method = getattr(unboxed(head), name, None) if name else None
         if method and not stack[(head, method)]:
             func = getattr(method, 'im_func', None)
             if not func:   # Py3k
                 func = getattr(method, '__func__', None)
             assert func is not None
             with stack((head, method)):
                 if tail:
                     return func(head, *tail, **named)
                 else:
                     return func(head)
         else:
             return super(_FunctorOperatorType, self).__call__(*children,
                                                               **named)
     else:
         return super(_FunctorOperatorType, self).__call__(*children,
                                                           **named)
Пример #5
0
    def test_plain_iter(self):
        t1 = next(iter(this))
        with context(UNPROXIFING_CONTEXT):
            self.assertTrue(
                IQueryPart.providedBy(t1),
                'When itering over a this instance we '
                'should get an IQueryPart object')

        t1 = next(parent for parent in this('parent'))
        self.assertEquals(
            'parent',
            unboxed(unboxed(t1)._expression).name,
            'The name of the QueryBuilderToken should be '
            'the same as the name of the actual instance')

        t1 = next(parent for parent in this('parent').children)
        self.assertEquals(
            'children',
            unboxed(unboxed(t1)._expression).name,
            'The name of the QueryBuilderToken should be '
            'the same as the name of the actual instance')
Пример #6
0
    def test_yield_once_per_query(self):
        q = (a for c in this for b in c.bs for a in b.a)
        self.assertIsNotNone(next(q))
        with self.assertRaises(StopIteration):
            next(q)

        # TODO: Document how to obtain the queries
        qs = (a for i in range(3) for b in this('b' + str(i)) for a in b.a)
        for i in range(3):
            expected = this('b' + str(i)).a
            returned = unboxed(next(qs)).expression
            with context(UNPROXIFING_CONTEXT):
                self.assertEqual(expected, returned)
        with self.assertRaises(StopIteration):
            next(qs)
Пример #7
0
    def test_yield_once_per_query(self):
        q = (a for c in this for b in c.bs for a in b.a)
        self.assertIsNotNone(next(q))
        with self.assertRaises(StopIteration):
            next(q)

        # TODO: Document how to obtain the queries
        qs = (a for i in range(3) for b in this('b' + str(i)) for a in b.a)
        for i in range(3):
            expected = this('b' + str(i)).a
            returned = unboxed(next(qs)).expression
            with context(UNPROXIFING_CONTEXT):
                self.assertEqual(expected, returned)
        with self.assertRaises(StopIteration):
            next(qs)
Пример #8
0
 def __call__(self, *children, **named):
     if children:
         stack = context
         head, tail = children[0], children[1:]
         name = getattr(self, '_method_name', None)
         method = getattr(unboxed(head), name, None) if name else None
         if method and not stack[(head, method)]:
             func = getattr(method, 'im_func', method)
             with stack((head, method)):
                 if tail:
                     return func(head, *tail, **named)
                 else:
                     return func(head)
         else:
             return super(_FunctorOperatorType,
                          self).__call__(*children, **named)
     else:
         return super(_FunctorOperatorType,
                      self).__call__(*children, **named)
Пример #9
0
 def __call__(self, *children, **named):
     if children:
         stack = context
         head, tail = children[0], children[1:]
         name = getattr(self, '_method_name', None)
         method = getattr(unboxed(head), name, None) if name else None
         if method and not stack[(head, method)]:
             func = getattr(method, 'im_func', method)
             with stack((head, method)):
                 if tail:
                     return func(head, *tail, **named)
                 else:
                     return func(head)
         else:
             return super(_FunctorOperatorType, self).__call__(*children,
                                                               **named)
     else:
         return super(_FunctorOperatorType, self).__call__(*children,
                                                           **named)
Пример #10
0
    def test_unboxed(self):
        class X(object):
            l = [1, 2, 4]

        @proxify
        class Proxified(object):
            def __init__(self, target):
                self.target = target
                self.l = [1, 3]

        x = X()
        p = Proxified(x)
        unboxed(p, 'l') << 234
        self.assertEqual([1, 3, 234], unboxed(p).l)
        self.assertEqual(x.l, p.l)
        self.assertIs(x.l, p.l)

        unboxed(p, 'unassigned') << 1
        self.assertEqual(1, unboxed(p).unassigned)
        self.assertFalse(hasattr(x, 'unassigned'))
Пример #11
0
 def test_20121127_unnamed_this_leaked(self):
     query = these(parent for parent in this if parent.age > 30)
     term = query.filters[0].children[0]
     with context(UNPROXIFING_CONTEXT):
         self.assertEqual(unboxed(term).parent, query.tokens[0])
Пример #12
0
def test_20121127_unnamed_this_leaked():
    query = these(parent for parent in this if parent.age > 30)
    term = query.filters[0].children[0]
    with context(UNPROXIFING_CONTEXT):
        assert unboxed(term).parent == query.tokens[0].expression
Пример #13
0
 def test_20121127_unnamed_this_leaked(self):
     query = these(parent for parent in this if parent.age > 30)
     term = query.filters[0].children[0]
     with context(UNPROXIFING_CONTEXT):
         self.assertEqual(unboxed(term).parent, query.tokens[0])