Skip to content

Commit 6ecddc5

Browse files
committed
Fix failing tests on 5.6
1 parent cb936bb commit 6ecddc5

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

lib/mysql/connector/connection_cext.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ def _open_connection(self):
170170
use_unicode=self._use_unicode,
171171
auth_plugin=self._auth_plugin)
172172

173+
if not self.isset_client_flag(ClientFlag.CONNECT_ARGS):
174+
self._conn_attrs = {}
173175
cnx_kwargs = {
174176
'host': self._host,
175177
'user': self._user,

tests/test_abstracts.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from tests import PY2, foreach_cnx
3838

3939
from mysql.connector.connection import MySQLConnection
40-
from mysql.connector.constants import RefreshOption
40+
from mysql.connector.constants import RefreshOption, ClientFlag
4141
from mysql.connector import errors
4242

4343
try:
@@ -169,6 +169,8 @@ def test_cmd_init_db(self):
169169
self.cnx.cmd_init_db('myconnpy')
170170
self.assertEqual(u'myconnpy', self.cnx.database)
171171

172+
@unittest.skipIf(tests.MYSQL_VERSION < (5, 7, 2),
173+
"reset command not available")
172174
@foreach_cnx()
173175
def test_reset_session(self):
174176
exp = [True, u'STRICT_ALL_TABLES', u'-09:00', 33]

tests/test_bugs.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ def _setup(self):
317317
@foreach_cnx()
318318
def test_default(self):
319319
self._setup()
320-
for flag in constants.ClientFlag.default:
320+
flags = constants.ClientFlag.default
321+
for flag in flags:
321322
self.assertTrue(self.cnx._client_flags & flag)
322323

323324
@foreach_cnx()
@@ -326,6 +327,8 @@ def test_set_unset(self):
326327
orig = self.cnx._client_flags
327328

328329
exp = self.default_flags | constants.ClientFlag.COMPRESS
330+
if tests.MYSQL_VERSION < (5, 7):
331+
exp = exp & ~constants.ClientFlag.CONNECT_ARGS
329332
self.cnx.set_client_flags([constants.ClientFlag.COMPRESS])
330333
for flag in constants.ClientFlag.default:
331334
self.assertTrue(self.cnx._client_flags & flag)
@@ -1961,6 +1964,8 @@ def setUp(self):
19611964
self.config = tests.get_mysql_config()
19621965
self.config['pool_name'] = 'test'
19631966
self.config['pool_size'] = 3
1967+
if tests.MYSQL_VERSION < (5, 7):
1968+
self.config["client_flags"] = [-constants.ClientFlag.CONNECT_ARGS]
19641969

19651970
def tearDown(self):
19661971
# Remove pools created by test
@@ -1998,6 +2003,8 @@ def test_get_connection(self):
19982003
connection from a pool for which the MySQL server is not running.
19992004
"""
20002005
config = tests.get_mysql_config().copy()
2006+
if tests.MYSQL_VERSION < (5, 7):
2007+
config["client_flags"] = [-constants.ClientFlag.CONNECT_ARGS]
20012008
config['connection_timeout'] = 2
20022009
cnxpool = pooling.MySQLConnectionPool(
20032010
pool_name='test', pool_size=1, **config)
@@ -2212,8 +2219,11 @@ class BugOra18040042(tests.MySQLConnectorTests):
22122219
"""BUG#18040042: Reset session closing pooled Connection"""
22132220

22142221
def test_clear_session(self):
2222+
pool_config = tests.get_mysql_config()
2223+
if tests.MYSQL_VERSION < (5, 7):
2224+
pool_config["client_flags"] = [-constants.ClientFlag.CONNECT_ARGS]
22152225
cnxpool = pooling.MySQLConnectionPool(
2216-
pool_name='test', pool_size=1, **tests.get_mysql_config())
2226+
pool_name='test', pool_size=1, **pool_config)
22172227

22182228
pcnx = cnxpool.get_connection()
22192229
exp_session_id = pcnx.connection_id
@@ -3151,6 +3161,8 @@ def test_unsupported_arguments(self):
31513161
option_file_dir = os.path.join('tests', 'data', 'option_files')
31523162
opt_file = os.path.join(option_file_dir, 'pool.cnf')
31533163
config = tests.get_mysql_config()
3164+
if tests.MYSQL_VERSION < (5, 7):
3165+
config["client_flags"] = [-constants.ClientFlag.CONNECT_ARGS]
31543166

31553167
conn = mysql.connector.connect(option_files=opt_file,
31563168
option_groups=['pooling'], **config)

tests/test_pooling.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -41,6 +41,7 @@
4141
from mysql.connector import errors
4242
from mysql.connector.connection import MySQLConnection
4343
from mysql.connector import pooling
44+
from mysql.connector.constants import ClientFlag
4445

4546

4647
class PoolingTests(tests.MySQLConnectorTests):
@@ -73,6 +74,8 @@ def tearDown(self):
7374

7475
def test___init__(self):
7576
dbconfig = tests.get_mysql_config()
77+
if tests.MYSQL_VERSION < (5, 7):
78+
dbconfig["client_flags"] = [-ClientFlag.CONNECT_ARGS]
7679
cnxpool = pooling.MySQLConnectionPool(pool_size=1, **dbconfig)
7780
self.assertRaises(TypeError, pooling.PooledMySQLConnection)
7881
cnx = MySQLConnection(**dbconfig)
@@ -87,6 +90,8 @@ def test___init__(self):
8790

8891
def test___getattr__(self):
8992
dbconfig = tests.get_mysql_config()
93+
if tests.MYSQL_VERSION < (5, 7):
94+
dbconfig["client_flags"] = [-ClientFlag.CONNECT_ARGS]
9095
cnxpool = pooling.MySQLConnectionPool(pool_size=1, pool_name='test')
9196
cnx = MySQLConnection(**dbconfig)
9297
pcnx = pooling.PooledMySQLConnection(cnxpool, cnx)
@@ -110,6 +115,8 @@ def test___getattr__(self):
110115

111116
def test_close(self):
112117
dbconfig = tests.get_mysql_config()
118+
if tests.MYSQL_VERSION < (5, 7):
119+
dbconfig["client_flags"] = [-ClientFlag.CONNECT_ARGS]
113120
cnxpool = pooling.MySQLConnectionPool(pool_size=1, **dbconfig)
114121

115122
cnxpool._original_cnx = None
@@ -118,7 +125,8 @@ def dummy_add_connection(self, cnx=None):
118125
self._original_cnx = cnx
119126
cnxpool.add_connection = dummy_add_connection.__get__(
120127
cnxpool, pooling.MySQLConnectionPool)
121-
128+
if tests.MYSQL_VERSION < (5, 7):
129+
dbconfig["client_flags"] = [-ClientFlag.CONNECT_ARGS]
122130
pcnx = pooling.PooledMySQLConnection(cnxpool,
123131
MySQLConnection(**dbconfig))
124132

@@ -141,6 +149,8 @@ def tearDown(self):
141149

142150
def test___init__(self):
143151
dbconfig = tests.get_mysql_config()
152+
if tests.MYSQL_VERSION < (5, 7):
153+
dbconfig["client_flags"] = [-ClientFlag.CONNECT_ARGS]
144154
self.assertRaises(errors.PoolError, pooling.MySQLConnectionPool)
145155

146156
self.assertRaises(AttributeError, pooling.MySQLConnectionPool,
@@ -180,14 +190,6 @@ def test_pool_name(self):
180190
cnxpool = pooling.MySQLConnectionPool(pool_name=pool_name)
181191
self.assertEqual(pool_name, cnxpool.pool_name)
182192

183-
def test_reset_session(self):
184-
"""Test MySQLConnectionPool.reset_session property"""
185-
cnxpool = pooling.MySQLConnectionPool(pool_name='test',
186-
pool_reset_session=False)
187-
self.assertFalse(cnxpool.reset_session)
188-
cnxpool._reset_session = True
189-
self.assertTrue(cnxpool.reset_session)
190-
191193
def test_pool_size(self):
192194
"""Test MySQLConnectionPool.pool_size property"""
193195
pool_size = 4
@@ -226,6 +228,8 @@ def test_add_connection(self):
226228
self.assertRaises(errors.PoolError, cnxpool.add_connection)
227229

228230
dbconfig = tests.get_mysql_config()
231+
if tests.MYSQL_VERSION < (5, 7):
232+
dbconfig["client_flags"] = [-ClientFlag.CONNECT_ARGS]
229233
cnxpool = pooling.MySQLConnectionPool(pool_size=2, pool_name='test')
230234
cnxpool.set_config(**dbconfig)
231235

@@ -258,6 +262,8 @@ def test_add_connection(self):
258262

259263
def test_set_config(self):
260264
dbconfig = tests.get_mysql_config()
265+
if tests.MYSQL_VERSION < (5, 7):
266+
dbconfig["client_flags"] = [-ClientFlag.CONNECT_ARGS]
261267
cnxpool = pooling.MySQLConnectionPool(pool_name='test')
262268

263269
# No configuration changes
@@ -283,6 +289,8 @@ def test_set_config(self):
283289

284290
def test_get_connection(self):
285291
dbconfig = tests.get_mysql_config()
292+
if tests.MYSQL_VERSION < (5, 7):
293+
dbconfig["client_flags"] = [-ClientFlag.CONNECT_ARGS]
286294
cnxpool = pooling.MySQLConnectionPool(pool_size=2, pool_name='test')
287295

288296
self.assertRaises(errors.PoolError, cnxpool.get_connection)
@@ -313,6 +321,8 @@ def test_get_connection(self):
313321

314322
def test__remove_connections(self):
315323
dbconfig = tests.get_mysql_config()
324+
if tests.MYSQL_VERSION < (5, 7):
325+
dbconfig["client_flags"] = [-ClientFlag.CONNECT_ARGS]
316326
cnxpool = pooling.MySQLConnectionPool(
317327
pool_size=2, pool_name='test', **dbconfig)
318328
pcnx = cnxpool.get_connection()
@@ -355,6 +365,8 @@ def test__get_pooled_connection(self):
355365

356366
def test_connect(self):
357367
dbconfig = tests.get_mysql_config()
368+
if tests.MYSQL_VERSION < (5, 7):
369+
dbconfig["client_flags"] = [-ClientFlag.CONNECT_ARGS]
358370
cnx = mysql.connector.connect(pool_size=1, pool_name='ham', **dbconfig)
359371
exp = cnx.connection_id
360372
cnx.close()

0 commit comments

Comments
 (0)