Simplify error reporting code (#505)

* Simplify error reporting code
* tests: Better error message
* Update travis config
This commit is contained in:
INADA Naoki
2016-08-29 22:41:02 +09:00
committed by GitHub
parent 4e36d5f613
commit 02910b74bb
4 changed files with 20 additions and 35 deletions

View File

@@ -4,6 +4,7 @@ python: "3.5"
cache:
directories:
- $HOME/.cache/pip
- $HOME/mysql
env:
matrix:
@@ -23,6 +24,7 @@ matrix:
- TOX_ENV=py27
- EXTRAPKG=mariadb-test
sudo: required
- addons:
mariadb: 10.0
env:
@@ -30,34 +32,34 @@ matrix:
- EXTRAPKG=mariadb-test
- PAMCLEAR=1
sudo: required
- addons:
mariadb: 10.1
env:
- TOX_ENV=py34
- EXTRAPKG=mariadb-test
sudo: required
- env:
- TOX_ENV=py34
- DB=5.6.28
- DB=5.6.32
addons:
apt:
packages:
- libaio-dev
python: 3.3
cache:
directories:
- ${HOME}/mysql
- env:
- TOX_ENV=py34
- DB=5.7.10
- DB=5.7.14
addons:
apt:
packages:
- libaio-dev
python: 3.4
cache:
directories:
- ${HOME}/mysql
allow_failures:
- env: DB=5.7.14
# different py version from 5.6 and 5.7 as cache seems to be based on py version

View File

@@ -91,32 +91,12 @@ _map_error(OperationalError, ER.DBACCESS_DENIED_ERROR, ER.ACCESS_DENIED_ERROR,
ER.CON_COUNT_ERROR, ER.TABLEACCESS_DENIED_ERROR,
ER.COLUMNACCESS_DENIED_ERROR)
del _map_error, ER
def _get_error_info(data):
errno = struct.unpack('<h', data[1:3])[0]
is_41 = data[3:4] == b"#"
if is_41:
# version 4.1
sqlstate = data[4:9].decode("utf8", 'replace')
errorvalue = data[9:].decode("utf8", 'replace')
return (errno, sqlstate, errorvalue)
else:
# version 4.0
return (errno, None, data[3:].decode("utf8", 'replace'))
def _check_mysql_exception(errinfo):
errno, sqlstate, errorvalue = errinfo
errorclass = error_map.get(errno, None)
if errorclass:
raise errorclass(errno, errorvalue)
# couldn't find the right error number
raise InternalError(errno, errorvalue)
def raise_mysql_exception(data):
errinfo = _get_error_info(data)
_check_mysql_exception(errinfo)
errno = struct.unpack('<h', data[1:3])[0]
errval = data[4:].decode('utf-8', 'replace')
errorclass = error_map.get(errno, InternalError)
raise errorclass(errno, errval)

View File

@@ -375,4 +375,5 @@ age = values(age)"""))
cur.execute("drop table if exists no_exists_table")
self.assertEqual(len(ws), 1)
self.assertEqual(ws[0].category, pymysql.Warning)
self.assertTrue(u"no_exists_table" in str(ws[0].message))
if u"no_exists_table" not in str(ws[0].message):
self.fail("'no_exists_table' not in %s" % (str(ws[0].message),))

View File

@@ -80,7 +80,9 @@ class TestLoadLocal(base.PyMySQLTestCase):
"test_load_local FIELDS TERMINATED BY ','").format(filename)
)
self.assertEqual(w[0].category, Warning)
self.assertTrue("Incorrect integer value" in str(w[-1].message))
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()