本文整理汇总了Python中aiohttp.client.ClientResponse._post_init方法的典型用法代码示例。如果您正苦于以下问题:Python ClientResponse._post_init方法的具体用法?Python ClientResponse._post_init怎么用?Python ClientResponse._post_init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.client.ClientResponse
的用法示例。
在下文中一共展示了ClientResponse._post_init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestBaseConnector
# 需要导入模块: from aiohttp.client import ClientResponse [as 别名]
# 或者: from aiohttp.client.ClientResponse import _post_init [as 别名]
class TestBaseConnector(unittest.TestCase):
def setUp(self):
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(None)
self.transport = unittest.mock.Mock()
self.stream = aiohttp.StreamParser()
self.response = ClientResponse('get', 'http://base-conn.org')
self.response._post_init(self.loop)
def tearDown(self):
self.response.close()
self.loop.close()
gc.collect()
def test_del(self):
conn = aiohttp.BaseConnector(loop=self.loop)
transp = unittest.mock.Mock()
conn._conns['a'] = [(transp, 'proto', 123)]
conns_impl = conn._conns
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
with self.assertWarns(ResourceWarning):
del conn
gc.collect()
self.assertFalse(conns_impl)
transp.close.assert_called_with()
msg = {'connector': unittest.mock.ANY, # conn was deleted
'connections': unittest.mock.ANY,
'message': 'Unclosed connector'}
if self.loop.get_debug():
msg['source_traceback'] = unittest.mock.ANY
exc_handler.assert_called_with(self.loop, msg)
def test_del_with_scheduled_cleanup(self):
conn = aiohttp.BaseConnector(loop=self.loop, keepalive_timeout=0.01)
transp = unittest.mock.Mock()
conn._conns['a'] = [(transp, 'proto', 123)]
conns_impl = conn._conns
conn._start_cleanup_task()
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
with self.assertWarns(ResourceWarning):
del conn
yield from asyncio.sleep(0.01)
gc.collect()
self.assertFalse(conns_impl)
transp.close.assert_called_with()
msg = {'connector': unittest.mock.ANY, # conn was deleted
'message': 'Unclosed connector'}
if self.loop.get_debug():
msg['source_traceback'] = unittest.mock.ANY
exc_handler.assert_called_with(self.loop, msg)
def test_del_with_closed_loop(self):
conn = aiohttp.BaseConnector(loop=self.loop)
transp = unittest.mock.Mock()
conn._conns['a'] = [(transp, 'proto', 123)]
conns_impl = conn._conns
conn._start_cleanup_task()
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
self.loop.close()
with self.assertWarns(ResourceWarning):
del conn
gc.collect()
self.assertFalse(conns_impl)
self.assertFalse(transp.close.called)
self.assertTrue(exc_handler.called)
def test_del_empty_conector(self):
conn = aiohttp.BaseConnector(loop=self.loop)
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
del conn
self.assertFalse(exc_handler.called)
def test_create_conn(self):
def go():
conn = aiohttp.BaseConnector(loop=self.loop)
with self.assertRaises(NotImplementedError):
yield from conn._create_connection(object())
self.loop.run_until_complete(go())
@unittest.mock.patch('aiohttp.connector.asyncio')
#.........这里部分代码省略.........
示例2: TestBaseConnector
# 需要导入模块: from aiohttp.client import ClientResponse [as 别名]
# 或者: from aiohttp.client.ClientResponse import _post_init [as 别名]
class TestBaseConnector(unittest.TestCase):
def setUp(self):
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(None)
self.transport = unittest.mock.Mock()
self.stream = aiohttp.StreamParser()
self.response = ClientResponse('get', 'http://base-conn.org')
self.response._post_init(self.loop)
def tearDown(self):
self.response.close()
self.loop.close()
gc.collect()
@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del(self):
conn = aiohttp.BaseConnector(loop=self.loop)
transp = unittest.mock.Mock()
conn._conns['a'] = [(transp, 'proto', 123)]
conns_impl = conn._conns
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
with self.assertWarns(ResourceWarning):
del conn
gc.collect()
self.assertFalse(conns_impl)
transp.close.assert_called_with()
msg = {'connector': unittest.mock.ANY, # conn was deleted
'message': 'Unclosed connector'}
if self.loop.get_debug():
msg['source_traceback'] = unittest.mock.ANY
exc_handler.assert_called_with(self.loop, msg)
@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del_with_scheduled_cleanup(self):
conn = aiohttp.BaseConnector(loop=self.loop, keepalive_timeout=0.01)
transp = unittest.mock.Mock()
conn._conns['a'] = [(transp, 'proto', 123)]
conns_impl = conn._conns
conn._start_cleanup_task()
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
with self.assertWarns(ResourceWarning):
del conn
yield from asyncio.sleep(0.01)
gc.collect()
self.assertFalse(conns_impl)
transp.close.assert_called_with()
msg = {'connector': unittest.mock.ANY, # conn was deleted
'message': 'Unclosed connector'}
if self.loop.get_debug():
msg['source_traceback'] = unittest.mock.ANY
exc_handler.assert_called_with(self.loop, msg)
@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del_with_closed_loop(self):
conn = aiohttp.BaseConnector(loop=self.loop)
transp = unittest.mock.Mock()
conn._conns['a'] = [(transp, 'proto', 123)]
conns_impl = conn._conns
conn._start_cleanup_task()
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
self.loop.close()
with self.assertWarns(ResourceWarning):
del conn
gc.collect()
self.assertFalse(conns_impl)
self.assertFalse(transp.close.called)
self.assertTrue(exc_handler.called)
@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del_empty_conector(self):
conn = aiohttp.BaseConnector(loop=self.loop)
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
del conn
self.assertFalse(exc_handler.called)
def test_create_conn(self):
def go():
conn = aiohttp.BaseConnector(loop=self.loop)
with self.assertRaises(NotImplementedError):
yield from conn._create_connection(object())
#.........这里部分代码省略.........
示例3: TestBaseConnector
# 需要导入模块: from aiohttp.client import ClientResponse [as 别名]
# 或者: from aiohttp.client.ClientResponse import _post_init [as 别名]
class TestBaseConnector(unittest.TestCase):
def setUp(self):
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(None)
self.transport = unittest.mock.Mock()
self.stream = aiohttp.StreamParser()
self.response = ClientResponse('get', 'http://base-conn.org')
self.response._post_init(self.loop)
def tearDown(self):
self.response.close()
self.loop.close()
gc.collect()
@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del(self):
conn = aiohttp.BaseConnector(loop=self.loop)
transp = unittest.mock.Mock()
conn._conns['a'] = [(transp, 'proto', 123)]
conns_impl = conn._conns
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
with self.assertWarns(ResourceWarning):
del conn
gc.collect()
self.assertFalse(conns_impl)
transp.close.assert_called_with()
msg = {'connector': unittest.mock.ANY, # conn was deleted
'message': 'Unclosed connector'}
if self.loop.get_debug():
msg['source_traceback'] = unittest.mock.ANY
exc_handler.assert_called_with(self.loop, msg)
@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del_with_scheduled_cleanup(self):
conn = aiohttp.BaseConnector(loop=self.loop, keepalive_timeout=0.01)
transp = unittest.mock.Mock()
conn._conns['a'] = [(transp, 'proto', 123)]
conns_impl = conn._conns
conn._start_cleanup_task()
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
with self.assertWarns(ResourceWarning):
del conn
yield from asyncio.sleep(0.01)
gc.collect()
self.assertFalse(conns_impl)
transp.close.assert_called_with()
msg = {'connector': unittest.mock.ANY, # conn was deleted
'message': 'Unclosed connector'}
if self.loop.get_debug():
msg['source_traceback'] = unittest.mock.ANY
exc_handler.assert_called_with(self.loop, msg)
@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del_with_closed_loop(self):
conn = aiohttp.BaseConnector(loop=self.loop)
transp = unittest.mock.Mock()
conn._conns['a'] = [(transp, 'proto', 123)]
conns_impl = conn._conns
conn._start_cleanup_task()
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
self.loop.close()
with self.assertWarns(ResourceWarning):
del conn
gc.collect()
self.assertFalse(conns_impl)
self.assertFalse(transp.close.called)
self.assertTrue(exc_handler.called)
@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del_empty_conector(self):
conn = aiohttp.BaseConnector(loop=self.loop)
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
del conn
self.assertFalse(exc_handler.called)
def test_create_conn(self):
def go():
conn = aiohttp.BaseConnector(loop=self.loop)
with self.assertRaises(NotImplementedError):
yield from conn._create_connection(object())
#.........这里部分代码省略.........