def testStrongRef(self): #{{{
     '''Call a strong reference'''
     val = ''.join(['hello', 'world'])
     test = 'helloworld'
     a = quote(val)
     self.assertTrue(a() is val)
     self.assertFalse(a() is test)
 def testMakeWeakRef(self): #{{{
     '''Set weak reference'''
     class Test(object): pass
     t = Test()
     a = quote(t)
     self.assertTrue(isinstance(a._ref, ref))
     self.assertTrue(a._isweak is True)
    def testAuto(self): #{{{
        '''If cannot set weak reference, automatically make a strong reference'''
        val = ''.join(['hello', 'world'])
        test = 'helloworld'
        self.assertTrue(test == val)
        self.assertFalse(test is val)
        a = quote(val)
        self.assertFalse(isinstance(a._ref, ref))
        self.assertTrue(a._isweak is False)
        self.assertTrue(a._ref is val)

        msg = re.compile("cannot create weak reference to 'str' object")
        self.assertRaisesEx(TypeError, quote, val, auto=False, exc_pattern=msg)
Esempio n. 4
0
 def __init__(self, *args, **opts): #{{{
     largs = len(args)
     if largs not in (1, 2):
         raise TypeError('Expected either 1 or 2 arguments, got %i instead' %largs)
     itertype = opts.get('itertype', tuple)
     parent, q = quote(opts.get('parent', None)), None
     if largs == 2:
         q = args[0]
     else:
         q = lambda i: True
     q, aiter = self.init_query(q), None
     if largs == 2:
         aitre = args[1]
     else:
         aiter = args[0]
     self._vars = parent, itertype, itertype(el for el in aiter if q(el))
 def testWeakRef(self): #{{{
     '''Call a weak reference'''
     class Test(object): pass
     t = Test()
     a = quote(t)
     self.assertTrue(a() is t)
 def testSetKeywords(self): #{{{
     '''Valid keywords get set properly'''
     a = quote(1, weak=False)
     self.assertTrue(a._isweak is False)