示例#1
0
 def test_put_with_factory(self):
     cleaned_objects = []
     pool = ObjectPool(3,
         create=[2, 1, 0].pop,
         verify=lambda o: o % 2 == 0,
         cleanup=cleaned_objects.append,
     )
     self.assertEqual(pool.pool_get(), 0)
     pool.pool_put(0)
     self.assertEqual(pool.pool_get(), 0)
     self.assertRaises(PoolVerificationError, pool.pool_get)
     self.assertEqual(pool.pool_get(), 2)
     self.assertEqual(cleaned_objects, [0])
示例#2
0
 def test_get_with_factory(self):
     obj_generator = iter(range(10)).next
     pool = ObjectPool(3, create=obj_generator)
     self.assertEqual(pool.pool_get(), 0)
     self.assertEqual(pool.pool_get(), 1)
     self.assertEqual(pool.pool_get(), 2)
示例#3
0
文件: tests.py 项目: wolever/objpool
 def test_unbounded_pool(self):
     pool = ObjectPool(size=0, create=[1,2,3].pop)
     self.assertEqual(pool.pool_get(), 3)
     self.assertEqual(pool.pool_get(), 2)
     self.assertEqual(pool.pool_get(), 1)