本文整理汇总了Python中pymysql.Warning方法的典型用法代码示例。如果您正苦于以下问题:Python pymysql.Warning方法的具体用法?Python pymysql.Warning怎么用?Python pymysql.Warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymysql
的用法示例。
在下文中一共展示了pymysql.Warning方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_warnings
# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def test_load_warnings(self):
"""Test load local infile produces the appropriate warnings"""
conn = self.connections[0]
c = conn.cursor()
c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)")
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'data',
'load_local_warn_data.txt')
try:
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
c.execute(
("LOAD DATA LOCAL INFILE '{0}' INTO TABLE " +
"test_load_local FIELDS TERMINATED BY ','").format(filename)
)
self.assertEqual(w[0].category, Warning)
expected_message = "Incorrect integer value"
if expected_message not in str(w[-1].message):
self.fail("%r not in %r" % (expected_message, w[-1].message))
finally:
c.execute("DROP TABLE test_load_local")
c.close()
示例2: test_issue_491
# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def test_issue_491(self):
""" Test warning propagation """
conn = pymysql.connect(charset="utf8", **self.databases[0])
with warnings.catch_warnings():
# Ignore all warnings other than pymysql generated ones
warnings.simplefilter("ignore")
warnings.simplefilter("error", category=pymysql.Warning)
# verify for both buffered and unbuffered cursor types
for cursor_class in (cursors.Cursor, cursors.SSCursor):
c = conn.cursor(cursor_class)
try:
c.execute("SELECT CAST('124b' AS SIGNED)")
c.fetchall()
except pymysql.Warning as e:
# Warnings should have errorcode and string message, just like exceptions
self.assertEqual(len(e.args), 2)
self.assertEqual(e.args[0], 1292)
self.assertTrue(isinstance(e.args[1], text_type))
else:
self.fail("Should raise Warning")
finally:
c.close()
示例3: test_load_warnings
# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def test_load_warnings(self):
"""Test load local infile produces the appropriate warnings"""
conn = self.connections[0]
c = conn.cursor()
c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)")
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'data',
'load_local_warn_data.txt')
try:
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
c.execute(
("LOAD DATA LOCAL INFILE '{0}' INTO TABLE " +
"test_load_local FIELDS TERMINATED BY ','").format(filename)
)
self.assertEqual(w[0].category, Warning)
self.assertTrue("Incorrect integer value" in str(w[-1].message))
finally:
c.execute("DROP TABLE test_load_local")
示例4: test_load_warnings
# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def test_load_warnings(self):
"""Test load local infile produces the appropriate warnings"""
conn = self.connect()
c = conn.cursor()
c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)")
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'data',
'load_local_warn_data.txt')
try:
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
c.execute(
("LOAD DATA LOCAL INFILE '{0}' INTO TABLE " +
"test_load_local FIELDS TERMINATED BY ','").format(filename)
)
self.assertEqual(w[0].category, Warning)
expected_message = "Incorrect integer value"
if expected_message not in str(w[-1].message):
self.fail("%r not in %r" % (expected_message, w[-1].message))
finally:
c.execute("DROP TABLE test_load_local")
c.close()
示例5: test_issue_363
# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def test_issue_363(self):
""" Test binary / geometry types. """
conn = pymysql.connect(charset="utf8", **self.databases[0])
self.safe_create_table(
conn, "issue363",
"CREATE TABLE issue363 ( "
"id INTEGER PRIMARY KEY, geom LINESTRING NOT NULL, "
"SPATIAL KEY geom (geom)) "
"ENGINE=MyISAM default charset=utf8")
cur = conn.cursor()
query = ("INSERT INTO issue363 (id, geom) VALUES"
"(1998, GeomFromText('LINESTRING(1.1 1.1,2.2 2.2)'))")
# From MySQL 5.7, ST_GeomFromText is added and GeomFromText is deprecated.
if self.mysql_server_is(conn, (5, 7, 0)):
with self.assertWarns(pymysql.err.Warning) as cm:
cur.execute(query)
else:
cur.execute(query)
# select WKT
query = "SELECT AsText(geom) FROM issue363"
if self.mysql_server_is(conn, (5, 7, 0)):
with self.assertWarns(pymysql.err.Warning) as cm:
cur.execute(query)
else:
cur.execute(query)
row = cur.fetchone()
self.assertEqual(row, ("LINESTRING(1.1 1.1,2.2 2.2)", ))
# select WKB
query = "SELECT AsBinary(geom) FROM issue363"
if self.mysql_server_is(conn, (5, 7, 0)):
with self.assertWarns(pymysql.err.Warning) as cm:
cur.execute(query)
else:
cur.execute(query)
row = cur.fetchone()
self.assertEqual(row,
(b"\x01\x02\x00\x00\x00\x02\x00\x00\x00"
b"\x9a\x99\x99\x99\x99\x99\xf1?"
b"\x9a\x99\x99\x99\x99\x99\xf1?"
b"\x9a\x99\x99\x99\x99\x99\x01@"
b"\x9a\x99\x99\x99\x99\x99\x01@", ))
# select internal binary
cur.execute("SELECT geom FROM issue363")
row = cur.fetchone()
# don't assert the exact internal binary value, as it could
# vary across implementations
self.assertTrue(isinstance(row[0], bytes))
示例6: driver_path
# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def driver_path(provider, tmpdir, mysql_server):
"""Get a valid, uninitialized driver path for given provider"""
import random
import string
from urllib.parse import urlparse
def validate_con_info(con_info):
return (con_info.scheme == 'mysql'
and con_info.hostname
and con_info.username
and not con_info.path)
def random_string(length):
return ''.join(random.choices(string.ascii_uppercase, k=length))
if provider == 'sqlite':
dbfile = tmpdir.join('test.sqlite')
yield str(dbfile)
elif provider == 'mysql':
if not mysql_server:
return pytest.skip('mysql_server argument not given')
if not mysql_server.startswith('mysql://'):
mysql_server = f'mysql://{mysql_server}'
con_info = urlparse(mysql_server)
if not validate_con_info(con_info):
raise ValueError('invalid value for mysql_server')
dbpath = random_string(24)
import pymysql
try:
with pymysql.connect(con_info.hostname, user=con_info.username,
password=con_info.password) as con:
pass
except pymysql.OperationalError as exc:
raise RuntimeError('error connecting to MySQL server') from exc
try:
yield f'{mysql_server}/{dbpath}'
finally: # cleanup
with pymysql.connect(con_info.hostname, user=con_info.username,
password=con_info.password) as con:
try:
con.execute(f'DROP DATABASE IF EXISTS {dbpath}')
except pymysql.Warning:
pass
else:
return NotImplementedError(f'unknown provider {provider}')