Esempio n. 1
0
 def test_resource_close_destructor(self):
     pool = mock.Mock()
     resource = base_sync.BaseSync.HttpClientPoolEntry(None, pool)
     self.assertTrue(resource.acquire())
     self.assertEqual(0, resource.semaphore.balance)
     data_src = StringIO.StringIO('test data')
     closing_iter = utils.ClosingResourceIterable(resource, data_src)
     del closing_iter
     self.assertEqual(1, resource.semaphore.balance)
Esempio n. 2
0
 def test_resource_close_afted_read(self):
     pool = mock.Mock()
     resource = base_sync.BaseSync.HttpClientPoolEntry(None, pool)
     self.assertTrue(resource.acquire())
     self.assertEqual(0, resource.semaphore.balance)
     data_src = StringIO.StringIO('test data')
     closing_iter = utils.ClosingResourceIterable(resource, data_src)
     data = next(closing_iter)
     with self.assertRaises(StopIteration):
         next(closing_iter)
     self.assertEqual('test data', data)
     self.assertEqual(1, resource.semaphore.balance)
     self.assertTrue(closing_iter.closed)