本文整理汇总了Python中tests.get_mysql_config函数的典型用法代码示例。如果您正苦于以下问题:Python get_mysql_config函数的具体用法?Python get_mysql_config怎么用?Python get_mysql_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_mysql_config函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dates
def test_dates(self):
"""examples/dates.py"""
try:
import examples.dates as example
except Exception as err:
self.fail(err)
output = example.main(tests.get_mysql_config())
exp = [' 1 | 1977-06-14 | 1977-06-14 21:10:00 | 21:10:00 |',
' 2 | None | None | 0:00:00 |',
' 3 | None | None | 0:00:00 |']
self.assertEqual(output, exp)
example.DATA.append(('0000-00-00', None, '00:00:00'),)
self.assertRaises(mysql.connector.errors.IntegrityError,
example.main, tests.get_mysql_config())
示例2: test_connect
def test_connect(self):
"""Interface exports the connect()-function"""
self.assertTrue(inspect.isfunction(myconn.connect),
"Module does not export the connect()-function")
cnx = myconn.connect(use_pure=True, **tests.get_mysql_config())
self.assertTrue(isinstance(cnx, myconn.connection.MySQLConnection),
"connect() not returning by default pure "
"MySQLConnection object")
if tests.MYSQL_CAPI:
# By default use_pure=False
cnx = myconn.connect(**tests.get_mysql_config())
self.assertTrue(isinstance(cnx,
myconn.connection_cext.CMySQLConnection),
"The connect()-method returns incorrect instance")
示例3: test_get_connection
def test_get_connection(self):
dbconfig = tests.get_mysql_config()
cnxpool = pooling.MySQLConnectionPool(pool_size=2, pool_name='test')
self.assertRaises(errors.PoolError, cnxpool.get_connection)
cnxpool = pooling.MySQLConnectionPool(pool_size=1, **dbconfig)
# Get connection from pool
pcnx = cnxpool.get_connection()
self.assertTrue(isinstance(pcnx, pooling.PooledMySQLConnection))
self.assertRaises(errors.PoolError, cnxpool.get_connection)
self.assertEqual(pcnx._cnx._pool_config_version,
cnxpool._config_version)
prev_config_version = pcnx._pool_config_version
prev_thread_id = pcnx.connection_id
pcnx.close()
# Change configuration
config_version = cnxpool._config_version
cnxpool.set_config(autocommit=True)
self.assertNotEqual(config_version, cnxpool._config_version)
pcnx = cnxpool.get_connection()
self.assertNotEqual(
pcnx._cnx._pool_config_version, prev_config_version)
self.assertNotEqual(prev_thread_id, pcnx.connection_id)
self.assertEqual(1, pcnx.autocommit)
pcnx.close()
示例4: setUp
def setUp(self):
config = tests.get_mysql_config()
config['raw'] = True
config['buffered'] = True
self.connection = connection.MySQLConnection(**config)
self.cur = self.connection.cursor()
示例5: test_connect
def test_connect(self):
"""Interface exports the connect()-function"""
self.assertTrue(inspect.isfunction(myconn.connect),
"Module does not export the connect()-function")
cnx = myconn.connect(**tests.get_mysql_config())
self.assertTrue(isinstance(cnx, myconn.connection.MySQLConnection),
"The connect()-method returns incorrect instance")
示例6: test_add_connection
def test_add_connection(self):
cnxpool = pooling.MySQLConnectionPool(pool_name='test')
self.assertRaises(errors.PoolError, cnxpool.add_connection)
dbconfig = tests.get_mysql_config()
cnxpool = pooling.MySQLConnectionPool(pool_size=2, pool_name='test')
cnxpool.set_config(**dbconfig)
cnxpool.add_connection()
pcnx = pooling.PooledMySQLConnection(
cnxpool,
cnxpool._cnx_queue.get(block=False))
self.assertTrue(isinstance(pcnx._cnx, MySQLConnection))
self.assertEqual(cnxpool, pcnx._cnx_pool)
self.assertEqual(cnxpool._config_version,
pcnx._cnx._pool_config_version)
cnx = pcnx._cnx
pcnx.close()
# We should get the same connectoin back
self.assertEqual(cnx, cnxpool._cnx_queue.get(block=False))
cnxpool.add_connection(cnx)
# reach max connections
cnxpool.add_connection()
self.assertRaises(errors.PoolError, cnxpool.add_connection)
# fail connecting
cnxpool._remove_connections()
cnxpool._cnx_config['port'] = 9999999
cnxpool._cnx_config['unix_socket'] = '/ham/spam/foobar.socket'
self.assertRaises(errors.InterfaceError, cnxpool.add_connection)
self.assertRaises(errors.PoolError, cnxpool.add_connection, cnx=str)
示例7: test__handle_result
def test__handle_result(self):
"""MySQLCursor object _handle_result()-method"""
self.connection = connection.MySQLConnection(**tests.get_mysql_config())
self.cur = self.connection.cursor()
self.assertRaises(errors.InterfaceError, self.cur._handle_result, None)
self.assertRaises(errors.InterfaceError, self.cur._handle_result,
'spam')
self.assertRaises(errors.InterfaceError, self.cur._handle_result,
{'spam': 5})
cases = [
{'affected_rows': 99999,
'insert_id': 10,
'warning_count': 100,
'server_status': 8,
},
{'eof': {'status_flag': 0, 'warning_count': 0},
'columns': [('1', 8, None, None, None, None, 0, 129)]
},
]
self.cur._handle_result(cases[0])
self.assertEqual(cases[0]['affected_rows'], self.cur.rowcount)
self.assertFalse(self.cur._connection.unread_result)
self.assertFalse(self.cur._have_unread_result())
self.cur._handle_result(cases[1])
self.assertEqual(cases[1]['columns'], self.cur.description)
self.assertTrue(self.cur._connection.unread_result)
self.assertTrue(self.cur._have_unread_result())
示例8: setUp
def setUp(self):
self.table_name = 'Bug21449996'
cnx = mysql.connector.connect(**tests.get_mysql_config())
cnx.cmd_query("DROP TABLE IF EXISTS %s" % self.table_name)
cnx.cmd_query("CREATE TABLE {0} (c1 BLOB) DEFAULT CHARSET=latin1"
"".format(self.table_name))
cnx.close()
示例9: test_fetchall
def test_fetchall(self):
"""MySQLCursor object fetchall()-method"""
self.check_method(self.cur, 'fetchall')
self.assertRaises(errors.InterfaceError, self.cur.fetchall)
self.connection = connection.MySQLConnection(**tests.get_mysql_config())
tbl = 'myconnpy_fetch'
self._test_execute_setup(self.connection, tbl)
stmt_insert = (
"INSERT INTO {table} (col1,col2) "
"VALUES (%s,%s)".format(table=tbl))
stmt_select = (
"SELECT col1,col2 FROM {table} "
"ORDER BY col1 ASC".format(table=tbl))
self.cur = self.connection.cursor()
self.cur.execute("SELECT * FROM {table}".format(table=tbl))
self.assertEqual([], self.cur.fetchall(),
"fetchall() with empty result should return []")
nrrows = 10
data = [(i, str(i * 100)) for i in range(0, nrrows)]
self.cur.executemany(stmt_insert, data)
self.cur.execute(stmt_select)
self.assertTrue(tests.cmp_result(data, self.cur.fetchall()),
"Fetching all rows failed.")
self.assertEqual(None, self.cur.fetchone())
self._test_execute_cleanup(self.connection, tbl)
self.cur.close()
示例10: test___init__
def test___init__(self):
dbconfig = tests.get_mysql_config()
self.assertRaises(errors.PoolError, pooling.MySQLConnectionPool)
self.assertRaises(AttributeError, pooling.MySQLConnectionPool,
pool_name='test',
pool_size=-1)
self.assertRaises(AttributeError, pooling.MySQLConnectionPool,
pool_name='test',
pool_size=0)
self.assertRaises(AttributeError, pooling.MySQLConnectionPool,
pool_name='test',
pool_size=(pooling.CNX_POOL_MAXSIZE + 1))
cnxpool = pooling.MySQLConnectionPool(pool_name='test')
self.assertEqual(5, cnxpool._pool_size)
self.assertEqual('test', cnxpool._pool_name)
self.assertEqual({}, cnxpool._cnx_config)
self.assertTrue(isinstance(cnxpool._cnx_queue, Queue))
self.assertTrue(isinstance(cnxpool._config_version, uuid.UUID))
cnxpool = pooling.MySQLConnectionPool(pool_size=10, pool_name='test')
self.assertEqual(10, cnxpool._pool_size)
cnxpool = pooling.MySQLConnectionPool(pool_size=10, **dbconfig)
self.assertEqual(dbconfig, cnxpool._cnx_config,
"Connection configuration not saved correctly")
self.assertEqual(10, cnxpool._cnx_queue.qsize())
self.assertTrue(isinstance(cnxpool._config_version, uuid.UUID))
示例11: test__process_params
def test__process_params(self):
"""MySQLCursor object _process_params()-method"""
self.check_method(self.cur, '_process_params')
self.assertRaises(
errors.ProgrammingError, self.cur._process_params, 'foo')
self.assertRaises(errors.ProgrammingError, self.cur._process_params, ())
st_now = time.localtime()
data = (
None,
int(128),
int(1281288),
float(3.14),
Decimal('3.14'),
r'back\slash',
'newline\n',
'return\r',
"'single'",
'"double"',
'windows\032',
"Strings are sexy",
'\u82b1',
datetime.datetime(2008, 5, 7, 20, 0o1, 23),
datetime.date(2008, 5, 7),
datetime.time(20, 0o3, 23),
st_now,
datetime.timedelta(hours=40, minutes=30, seconds=12),
)
exp = (
b'NULL',
b'128',
b'1281288',
b'3.14',
b"'3.14'",
b"'back\\\\slash'",
b"'newline\\n'",
b"'return\\r'",
b"'\\'single\\''",
b'\'\\"double\\"\'',
b"'windows\\\x1a'",
b"'Strings are sexy'",
b"'\xe8\x8a\xb1'",
b"'2008-05-07 20:01:23'",
b"'2008-05-07'",
b"'20:03:23'",
b"'" + time.strftime('%Y-%m-%d %H:%M:%S', st_now).encode('ascii')
+ b"'",
b"'40:30:12'",
)
self.cnx = connection.MySQLConnection(**tests.get_mysql_config())
self.cur = self.cnx.cursor()
self.assertEqual((), self.cur._process_params(()),
"_process_params() should return a tuple")
res = self.cur._process_params(data)
for (i, exped) in enumerate(exp):
self.assertEqual(exped, res[i])
self.cur.close()
示例12: test_use_unicode
def test_use_unicode(self):
"""lp:499410 Disabling unicode does not work"""
config = tests.get_mysql_config()
config['use_unicode'] = False
cnx = connection.MySQLConnection(**config)
self.assertEqual(False, cnx._use_unicode)
cnx.close()
示例13: setUp
def setUp(self):
config = tests.get_mysql_config()
self.cnx = connection.MySQLConnection(**config)
self.cur = self.cnx.cursor()
self.table = "⽃⽄⽅⽆⽇⽈⽉⽊"
self.cur.execute("DROP TABLE IF EXISTS {0}".format(self.table))
self.cur.execute("CREATE TABLE {0} (c1 VARCHAR(100)) "
"CHARACTER SET 'utf8'".format(self.table))
示例14: setUp
def setUp(self):
dbconfig = tests.get_mysql_config()
self.conn = mysql.connector.connect(**dbconfig)
self.cnx = DatabaseWrapper(settings.DATABASES['default'])
self.cur = self.cnx.cursor()
self.tbl = "BugOra20106629"
self.cur.execute("DROP TABLE IF EXISTS {0}".format(self.tbl), ())
self.cur.execute("CREATE TABLE {0}(col1 TEXT, col2 BLOB)".format(self.tbl), ())
示例15: test_ssl_cipher_in_option_file
def test_ssl_cipher_in_option_file(self):
config = tests.get_mysql_config()
config['ssl_ca'] = TEST_SSL['ca']
config['use_pure'] = False
cnx = mysql.connector.connect(**config)
cnx.cmd_query("SHOW STATUS LIKE 'Ssl_cipher'")
self.assertNotEqual(cnx.get_row()[1], '') # Ssl_cipher must have a value