# MySQL Connector/Python - MySQL driver written in Python. # Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. # MySQL Connector/Python is licensed under the terms of the GPLv2 # , like most # MySQL Connectors. There are special exceptions to the terms and # conditions of the GPLv2 as it is applied to this software, see the # FOSS License Exception # . # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """Unittests for mysql.connector.utils """ import struct import tests from mysql.connector import utils class UtilsTests(tests.MySQLConnectorTests): """Testing the helper functions in the utils module. These tests should not make a connection to the database. """ def _check_int_result(self, result, exp, data): if not isinstance(result, bytearray): self.fail("Wrong result. Expected {0}, we got {1}".format( (type(exp), type(result)))) elif exp != result: self.fail("Wrong result. Expected {0}, we got {1}".format( (data, result))) def test_intread(self): """Use intread to read from valid strings.""" try: for i in range(4): utils.intread(bytearray(b'a') * (i + 1)) except ValueError as err: self.fail("intread failed calling 'int{0}read: {1}".format( int(i) + 1, err)) def test_int1store(self): """Use int1store to pack an integer (2^8) as a string.""" data = 2 ** (8 - 1) exp = struct.pack('