test async_ instead of async keyword

re-enable test for 3.7 and test for async_
This commit is contained in:
j 2018-07-01 13:15:34 +01:00
parent 6becf0ef55
commit 558975fa58
2 changed files with 20 additions and 22 deletions

View File

@ -56,8 +56,7 @@ from . import test_types_basic
from . import test_types_extras from . import test_types_extras
from . import test_with from . import test_with
if sys.version_info[:2] < (3, 6): from . import test_async_keyword
from . import test_async_keyword
def test_suite(): def test_suite():
@ -74,7 +73,6 @@ def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(test_async.test_suite()) suite.addTest(test_async.test_suite())
if sys.version_info[:2] < (3, 6):
suite.addTest(test_async_keyword.test_suite()) suite.addTest(test_async_keyword.test_suite())
suite.addTest(test_bugX000.test_suite()) suite.addTest(test_bugX000.test_suite())
suite.addTest(test_bug_gc.test_suite()) suite.addTest(test_bug_gc.test_suite())

View File

@ -41,7 +41,7 @@ class AsyncTests(ConnectingTestCase):
ConnectingTestCase.setUp(self) ConnectingTestCase.setUp(self)
self.sync_conn = self.conn self.sync_conn = self.conn
self.conn = self.connect(async=True) self.conn = self.connect(async_=True)
self.wait(self.conn) self.wait(self.conn)
@ -57,8 +57,8 @@ class AsyncTests(ConnectingTestCase):
sync_cur = self.sync_conn.cursor() sync_cur = self.sync_conn.cursor()
del cur, sync_cur del cur, sync_cur
self.assert_(self.conn.async) self.assert_(self.conn.async_)
self.assert_(not self.sync_conn.async) self.assert_(not self.sync_conn.async_)
# the async connection should be autocommit # the async connection should be autocommit
self.assert_(self.conn.autocommit) self.assert_(self.conn.autocommit)
@ -70,17 +70,17 @@ class AsyncTests(ConnectingTestCase):
def test_async_subclass(self): def test_async_subclass(self):
class MyConn(psycopg2.extensions.connection): class MyConn(psycopg2.extensions.connection):
def __init__(self, dsn, async=0): def __init__(self, dsn, async_=0):
psycopg2.extensions.connection.__init__(self, dsn, async=async) psycopg2.extensions.connection.__init__(self, dsn, async_=async_)
conn = self.connect(connection_factory=MyConn, async=True) conn = self.connect(connection_factory=MyConn, async_=True)
self.assert_(isinstance(conn, MyConn)) self.assert_(isinstance(conn, MyConn))
self.assert_(conn.async) self.assert_(conn.async_)
conn.close() conn.close()
def test_async_connection_error_message(self): def test_async_connection_error_message(self):
try: try:
cnn = psycopg2.connect('dbname=thisdatabasedoesntexist', async=True) cnn = psycopg2.connect('dbname=thisdatabasedoesntexist', async_=True)
self.wait(cnn) self.wait(cnn)
except psycopg2.Error as e: except psycopg2.Error as e:
self.assertNotEqual(str(e), "asynchronous connection failed", self.assertNotEqual(str(e), "asynchronous connection failed",
@ -103,7 +103,7 @@ class CancelTests(ConnectingTestCase):
@slow @slow
@skip_before_postgres(8, 2) @skip_before_postgres(8, 2)
def test_async_cancel(self): def test_async_cancel(self):
async_conn = psycopg2.connect(dsn, async=True) async_conn = psycopg2.connect(dsn, async_=True)
self.assertRaises(psycopg2.OperationalError, async_conn.cancel) self.assertRaises(psycopg2.OperationalError, async_conn.cancel)
extras.wait_select(async_conn) extras.wait_select(async_conn)
cur = async_conn.cursor() cur = async_conn.cursor()
@ -118,7 +118,7 @@ class CancelTests(ConnectingTestCase):
self.assertEqual(cur.fetchall(), [(1, )]) self.assertEqual(cur.fetchall(), [(1, )])
def test_async_connection_cancel(self): def test_async_connection_cancel(self):
async_conn = psycopg2.connect(dsn, async=True) async_conn = psycopg2.connect(dsn, async_=True)
async_conn.close() async_conn.close()
self.assertTrue(async_conn.closed) self.assertTrue(async_conn.closed)
@ -127,8 +127,8 @@ class ConnectTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.args = None self.args = None
def connect_stub(dsn, connection_factory=None, async=False): def connect_stub(dsn, connection_factory=None, async_=False):
self.args = (dsn, connection_factory, async) self.args = (dsn, connection_factory, async_)
self._connect_orig = psycopg2._connect self._connect_orig = psycopg2._connect
psycopg2._connect = connect_stub psycopg2._connect = connect_stub
@ -139,12 +139,12 @@ class ConnectTestCase(unittest.TestCase):
def test_there_has_to_be_something(self): def test_there_has_to_be_something(self):
self.assertRaises(TypeError, psycopg2.connect) self.assertRaises(TypeError, psycopg2.connect)
self.assertRaises(TypeError, psycopg2.connect, self.assertRaises(TypeError, psycopg2.connect,
connection_factory=lambda dsn, async=False: None) connection_factory=lambda dsn, async_=False: None)
self.assertRaises(TypeError, psycopg2.connect, self.assertRaises(TypeError, psycopg2.connect,
async=True) async_=True)
def test_factory(self): def test_factory(self):
def f(dsn, async=False): def f(dsn, async_=False):
pass pass
psycopg2.connect(database='foo', host='baz', connection_factory=f) psycopg2.connect(database='foo', host='baz', connection_factory=f)
@ -158,12 +158,12 @@ class ConnectTestCase(unittest.TestCase):
self.assertEqual(self.args[2], False) self.assertEqual(self.args[2], False)
def test_async(self): def test_async(self):
psycopg2.connect(database='foo', host='baz', async=1) psycopg2.connect(database='foo', host='baz', async_=1)
self.assertDsnEqual(self.args[0], 'dbname=foo host=baz') self.assertDsnEqual(self.args[0], 'dbname=foo host=baz')
self.assertEqual(self.args[1], None) self.assertEqual(self.args[1], None)
self.assert_(self.args[2]) self.assert_(self.args[2])
psycopg2.connect("dbname=foo host=baz", async=True) psycopg2.connect("dbname=foo host=baz", async_=True)
self.assertDsnEqual(self.args[0], 'dbname=foo host=baz') self.assertDsnEqual(self.args[0], 'dbname=foo host=baz')
self.assertEqual(self.args[1], None) self.assertEqual(self.args[1], None)
self.assert_(self.args[2]) self.assert_(self.args[2])
@ -174,7 +174,7 @@ class AsyncReplicationTest(ReplicationTestCase):
@skip_repl_if_green @skip_repl_if_green
def test_async_replication(self): def test_async_replication(self):
conn = self.repl_connect( conn = self.repl_connect(
connection_factory=LogicalReplicationConnection, async=1) connection_factory=LogicalReplicationConnection, async_=1)
if conn is None: if conn is None:
return return