def setUp(self): import gc db = connection_factory(**self.connect_kwargs) self.connection = db self.cursor = db.cursor() self.BLOBUText = u''.join([chr(i) for i in range(16384)]) self.BLOBBinary = self.db_module.Binary((u''.join([chr(i) for i in range(256)] * 16)).encode('latin1'))
def setUp(self): import gc db = connection_factory(**self.connect_kwargs) self.connection = db self.cursor = db.cursor() self.BLOBUText = u''.join([unichr(i) for i in range(16384)]) self.BLOBBinary = self.db_module.Binary((u''.join([unichr(i) for i in range(256)] * 16)).encode('latin1'))
def test_multi_statements_default_true(): conn = connection_factory() cursor = conn.cursor() cursor.execute("select 17; select 2") rows = cursor.fetchall() assert rows == ((17,),)
def setUp(self): import gc db = connection_factory(**self.connect_kwargs) self.connection = db self.cursor = db.cursor() # TODO: this needs to be re-evaluated for Python 3 self.BLOBText = ''.join([chr(i) for i in range(256)] * 100); self.BLOBUText = u''.join([unichr(i) for i in range(16384)]) self.BLOBBinary = self.db_module.Binary(''.join([chr(i) for i in range(256)] * 16))
def test_multi_statements_false(): conn = connection_factory(multi_statements=False) cursor = conn.cursor() with pytest.raises(ProgrammingError): cursor.execute("select 17; select 2") cursor.execute("select 17") rows = cursor.fetchall() assert rows == ((17,),)
def test_client_flag(self): conn = connection_factory( use_unicode=True, client_flag=MySQLdb.constants.CLIENT.FOUND_ROWS) self.assertIsInstance(conn.client_flag, (int, MySQLdb.compat.long)) self.assertTrue(conn.client_flag & MySQLdb.constants.CLIENT.FOUND_ROWS) with self.assertRaises( TypeError if MySQLdb.compat.PY2 else AttributeError): conn.client_flag = 0 conn.close()
def test_client_flag(self): conn = connection_factory( use_unicode=True, client_flag=MySQLdb.constants.CLIENT.FOUND_ROWS) self.assertIsInstance(conn.client_flag, (int, MySQLdb.compat.long)) self.assertTrue(conn.client_flag & MySQLdb.constants.CLIENT.FOUND_ROWS) with self.assertRaises(TypeError if MySQLdb.compat.PY2 else AttributeError): conn.client_flag = 0 conn.close()
def test_client_flag(self): conn = connection_factory( use_unicode=True, client_flag=MySQLdb.constants.CLIENT.FOUND_ROWS ) self.assertIsInstance(conn.client_flag, int) self.assertTrue(conn.client_flag & MySQLdb.constants.CLIENT.FOUND_ROWS) with self.assertRaises(AttributeError): conn.client_flag = 0 conn.close()
def test_binary_prefix(self): # verify prefix behaviour when enabled, disabled and for default (disabled) for binary_prefix in (True, False, None): kwargs = self.connect_kwargs.copy() # needs to be set to can guarantee CHARSET response for normal strings kwargs['charset'] = 'utf8' if binary_prefix != None: kwargs['binary_prefix'] = binary_prefix with closing(connection_factory(**kwargs)) as conn: with closing(conn.cursor()) as c: c.execute('SELECT CHARSET(%s)', (MySQLdb.Binary(b'raw bytes'),)) self.assertEqual(c.fetchall()[0][0], 'binary' if binary_prefix else 'utf8') # normal strings should not get prefix c.execute('SELECT CHARSET(%s)', ('str',)) self.assertEqual(c.fetchall()[0][0], 'utf8')
def test_binary_prefix(self): # verify prefix behaviour when enabled, disabled and for default (disabled) for binary_prefix in (True, False, None): kwargs = self.connect_kwargs.copy() # needs to be set to can guarantee CHARSET response for normal strings kwargs["charset"] = "utf8" if binary_prefix is not None: kwargs["binary_prefix"] = binary_prefix with closing(connection_factory(**kwargs)) as conn: with closing(conn.cursor()) as c: c.execute("SELECT CHARSET(%s)", (tiledb.sql.Binary(b"raw bytes"), )) self.assertEqual(c.fetchall()[0][0], "binary" if binary_prefix else "utf8") # normal strings should not get prefix c.execute("SELECT CHARSET(%s)", ("str", )) self.assertEqual(c.fetchall()[0][0], "utf8")
def setUp(self): self.conn = connection_factory(use_unicode=True)
def connect(**kwargs): conn = connection_factory(**kwargs) _conns.append(conn) return conn
def test_context_manager(self): with connection_factory() as conn: self.assertFalse(conn.closed) self.assertTrue(conn.closed)
def setUp(self): self.conn = connection_factory()