1
# MySQL Connector/Python - MySQL driver written in Python.
2
# Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
4
# MySQL Connector/Python is licensed under the terms of the GPLv2
5
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
6
# MySQL Connectors. There are special exceptions to the terms and
7
# conditions of the GPLv2 as it is applied to this software, see the
8
# FOSS License Exception
9
# <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
11
# This program is free software; you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License as published by
13
# the Free Software Foundation.
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU General Public License
21
# along with this program; if not, write to the Free Software
22
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
"""Unittests for mysql.connector.errorcode
27
from datetime import datetime
29
from mysql.connector import errorcode
32
class ErrorCodeTests(tests.MySQLConnectorTests):
34
def test__GENERATED_ON(self):
35
self.assertTrue(isinstance(errorcode._GENERATED_ON, str))
37
generatedon = datetime.strptime(errorcode._GENERATED_ON,
39
except ValueError as err:
42
delta = (datetime.now().date() - generatedon).days
45
"errorcode.py is more than 120 days old ({0})".format(delta))
47
def test__MYSQL_VERSION(self):
49
self.assertTrue(isinstance(errorcode._MYSQL_VERSION, tuple))
50
self.assertTrue(len(errorcode._MYSQL_VERSION) == 3)
51
self.assertTrue(errorcode._MYSQL_VERSION >= minimum)
53
def _check_code(self, code, num):
55
self.assertEqual(getattr(errorcode, code), num)
56
except AttributeError as err:
59
def test_server_error_codes(self):
62
'ER_TRG_INVALID_CREATION_CTX': 1604,
63
'ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION': 1792,
66
for code, num in cases.items():
67
self._check_code(code, num)
69
def test_client_error_codes(self):
71
'CR_UNKNOWN_ERROR': 2000,
72
'CR_PROBE_SLAVE_STATUS': 2022,
73
'CR_AUTH_PLUGIN_CANNOT_LOAD': 2059,
76
for code, num in cases.items():
77
self._check_code(code, num)