From d56281c66fba85a9b446d7aeb35d4e56e798f753 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Wed, 22 Apr 2015 22:34:30 +0300 Subject: [PATCH] Add test for Pool.__del__ --- aiopg/pool.py | 2 +- tests/test_cursor.py | 14 ++++++++++++++ tests/test_pool.py | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/aiopg/pool.py b/aiopg/pool.py index a20dc620..5a6b5b7d 100644 --- a/aiopg/pool.py +++ b/aiopg/pool.py @@ -250,7 +250,7 @@ def __iter__(self): conn = yield from self.acquire() return _ConnectionContextManager(self, conn) - if PY_34: + if PY_34: # pragma: no branch def __del__(self): try: self._free diff --git a/tests/test_cursor.py b/tests/test_cursor.py index 662b651f..7528a7ca 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -485,3 +485,17 @@ def go(): self.assertEqual(item, tst) self.loop.run_until_complete(go()) + + def test_echo_callproc(self): + @asyncio.coroutine + def go(): + conn = yield from self.connect(echo=True) + cur = yield from conn.cursor() + + # TODO: check log records + yield from cur.callproc('inc', [1]) + ret = yield from cur.fetchone() + self.assertEqual((2,), ret) + cur.close() + + self.loop.run_until_complete(go()) diff --git a/tests/test_pool.py b/tests/test_pool.py index 43c182bf..6092c6f8 100644 --- a/tests/test_pool.py +++ b/tests/test_pool.py @@ -1,6 +1,7 @@ import asyncio import unittest from unittest import mock +import sys from psycopg2.extensions import TRANSACTION_STATUS_INTRANS @@ -526,3 +527,15 @@ def go(): 0.1, loop=self.loop) self.loop.run_until_complete(go()) + + @unittest.skipIf(sys.version_info < (3, 4), + "Python 3.3 doesnt support __del__ calls from GC") + def test___del__(self): + @asyncio.coroutine + def go(): + pool = yield from self.create_pool() + self.pool = None # drop reference + with self.assertWarns(ResourceWarning): + del pool + + self.loop.run_until_complete(go())