Пример #1
0
 def test_lazyimport(self):
     from stuf.six import callable
     from stuf.utils import lazyimport
     fsum = lazyimport('math.fsum')
     self.assertTrue(callable(fsum))
     fsum = lazyimport('math', 'fsum')
     self.assertTrue(callable(fsum))
Пример #2
0
 def test_deepmembers(self):
     class stooges:
         name = 'moe'
         age = 40
         def boo(self):
             return 'boo'
         def foo(self):
             return 'foo'
     class stoog2: #@IgnorePep8
         name = 'larry'
         age = 50
         def boo(self):
             return 'boo'
         def foo(self):
             return 'foo'
     class stoog3: #@IgnorePep8
         name = 'curly'
         age = 60
         def boo(self):
             return 'boo'
         def foo(self):
             return 'foo'
     test = lambda x: not x[0].startswith('__')
     manq = self.qclass(stooges, stoog2, stoog3).tap(test).deepmembers()
     self.assertFalse(manq.balanced)
     manq.sync()
     self.assertTrue(manq.balanced)
     self.assertEqual(
         manq.value(),
         [('age', 40), ('boo', stooges.boo), ('foo', stooges.foo),
         ('name', 'moe'), ('age', 50), ('boo', stoog2.boo),
         ('foo', stoog2.foo), ('name', 'larry'), ('age', 60), 
         ('boo', stoog3.boo), ('foo', stoog3.foo), ('name', 'curly')],
     )
     self.assertFalse(manq.balanced)
     from stuf.six import callable
     test = lambda x: not x[0].startswith('_') and callable(x[1])
     manq = self.qclass(stooges, stoog2, stoog3).tap(test).deepmembers()
     self.assertFalse(manq.balanced)
     manq.sync()
     self.assertTrue(manq.balanced)
     self.assertEqual(
         manq.value(),
         [('boo', stooges.boo), ('foo', stooges.foo), ('boo', stoog2.boo),
         ('foo', stoog2.foo), ('boo', stoog3.boo), ('foo', stoog3.foo)],
     )
     self.assertFalse(manq.balanced)
Пример #3
0
 def test_deepmembers(self):
     class stooges:
         name = 'moe'
         age = 40
         def boo(self):#@IgnorePep8
             return 'boo'
         def foo(self):#@IgnorePep8
             return 'foo'
     class stoog2: #@IgnorePep8
         name = 'larry'
         age = 50
         def boo(self):#@IgnorePep8
             return 'boo'
         def foo(self):#@IgnorePep8
             return 'foo'
     class stoog3: #@IgnorePep8
         name = 'curly'
         age = 60
         def boo(self):#@IgnorePep8
             return 'boo'
         def foo(self):#@IgnorePep8
             return 'foo'
     test = lambda x: not x[0].startswith('__')
     self.assertSequenceEqual(
         self.qclass(
             stooges, stoog2, stoog3
         ).tap(test).deepmembers().sync().end(),
         [('age', 40), ('boo', stooges.boo), ('foo', stooges.foo),
         ('name', 'moe'), ('age', 50), ('boo', stoog2.boo),
         ('foo', stoog2.foo), ('name', 'larry'), ('age', 60),
         ('boo', stoog3.boo), ('foo', stoog3.foo), ('name', 'curly')],
     )
     from stuf.six import callable
     test = lambda x: not x[0].startswith('_') and callable(x[1])
     self.assertSequenceEqual(
         self.qclass(
             stooges, stoog2, stoog3
         ).tap(test).deepmembers().sync().end(),
         [('boo', stooges.boo), ('foo', stooges.foo), ('boo', stoog2.boo),
         ('foo', stoog2.foo), ('boo', stoog3.boo), ('foo', stoog3.foo)],
     )
Пример #4
0
 def iscall(cls, value):
     '''is callable?'''
     return six.callable(value)