Skip to content

Commit 1a847cc

Browse files
committedApr 22, 2015
Add test for Connection.__del__
1 parent 19a4843 commit 1a847cc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎aiopg/connection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def echo(self):
395395
"""Return echo mode status."""
396396
return self._echo
397397

398-
if PY_34:
398+
if PY_34: # pragma: no branch
399399
def __del__(self):
400400
if not self._conn.closed:
401401
warnings.warn("Unclosed connection {!r}".format(self),

‎tests/test_connection.py

+16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import random
77
import unittest
88
import time
9+
import sys
910

1011
from aiopg.connection import Connection, TIMEOUT
1112
from aiopg.cursor import Cursor
@@ -622,3 +623,18 @@ def go():
622623
self.assertTrue(conn.echo)
623624

624625
self.loop.run_until_complete(go())
626+
627+
@unittest.skipIf(sys.version_info < (3, 4),
628+
"Python 3.3 doesnt support __del__ calls from GC")
629+
def test___del__(self):
630+
@asyncio.coroutine
631+
def go():
632+
conn = yield from aiopg.connect(database='aiopg',
633+
user='aiopg',
634+
password='passwd',
635+
host='127.0.0.1',
636+
loop=self.loop)
637+
with self.assertWarns(ResourceWarning):
638+
del conn
639+
640+
self.loop.run_until_complete(go())

0 commit comments

Comments
 (0)
Please sign in to comment.