Skip to content

Commit f0af044

Browse files
committed
BUG31060730: Skip pure Python tests if Protobuf is not available
Some X DevAPI tests fail if Python Protobuf is not installed. This patch skip tests that require the pure Python implementation of Protobuf.
1 parent e989612 commit f0af044

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/mysqlx/protobuf/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -196,7 +196,7 @@
196196
[(_MESSAGES[key], val) for key, val in _SERVER_MESSAGES_TUPLES]
197197
)
198198
HAVE_PROTOBUF = True
199-
199+
HAVE_PROTOBUF_ERROR = None
200200

201201
class _mysqlxpb_pure(object):
202202
"""This class implements the methods in pure Python used by the
@@ -236,10 +236,11 @@ def parse_server_message(msg_type, payload):
236236
msg = _mysqlxpb_pure.new_message(msg_type_name)
237237
msg.ParseFromString(payload)
238238
return msg
239-
except ImportError:
239+
except ImportError as err:
240240
HAVE_PROTOBUF = False
241+
HAVE_PROTOBUF_ERROR = err
241242
if not HAVE_MYSQLXPB_CEXT:
242-
raise ImportError("Protobuf is not available")
243+
raise ImportError("Protobuf is not available: {}".format(err))
243244

244245
CRUD_PREPARE_MAPPING = {
245246
"Mysqlx.ClientMessages.Type.CRUD_FIND": (
@@ -271,7 +272,8 @@ def set_use_pure(use_pure):
271272
use_pure (bool): `True` to use pure Python implementation.
272273
"""
273274
if use_pure and not HAVE_PROTOBUF:
274-
raise ImportError("Protobuf is not available")
275+
raise ImportError("Protobuf is not available: {}"
276+
"".format(HAVE_PROTOBUF_ERROR))
275277
elif not use_pure and not HAVE_MYSQLXPB_CEXT:
276278
raise ImportError("MySQL X Protobuf C extension is not available")
277279
Protobuf.mysqlxpb = _mysqlxpb_pure if use_pure else _mysqlxpb

tests/test_mysqlx_connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
from mysqlx.errors import InterfaceError, OperationalError, ProgrammingError
5454
from mysqlx.protocol import (Message, MessageReader, MessageWriter, Protocol,
5555
HAVE_LZ4)
56-
from mysqlx.protobuf import HAVE_MYSQLXPB_CEXT, mysqlxpb_enum, Protobuf
56+
from mysqlx.protobuf import (HAVE_MYSQLXPB_CEXT, HAVE_PROTOBUF, mysqlxpb_enum,
57+
Protobuf)
5758
from mysql.connector.utils import linux_distribution
5859
from mysql.connector.version import VERSION, LICENSE
5960

@@ -1330,6 +1331,7 @@ def test_disabled_x_protocol(self):
13301331
self.assertRaises(ProgrammingError, mysqlx.get_session, settings)
13311332

13321333
@unittest.skipIf(HAVE_MYSQLXPB_CEXT == False, "C Extension not available")
1334+
@unittest.skipUnless(HAVE_PROTOBUF, "Protobuf not available")
13331335
def test_use_pure(self):
13341336
settings = self.connect_kwargs.copy()
13351337
settings["use-pure"] = False
@@ -1752,6 +1754,7 @@ def test_initial_empty_notice_cext(self):
17521754
self.assertEqual(rows[0][0], "information_schema")
17531755
session.close()
17541756

1757+
@unittest.skipUnless(HAVE_PROTOBUF, "Protobuf not available")
17551758
def test_initial_empty_notice_pure(self):
17561759
connect_kwargs = self.connect_kwargs.copy()
17571760
host = "localhost"
@@ -1785,6 +1788,7 @@ def test_initial_notice_cext(self):
17851788
self.assertEqual(rows[0][0], "information_schema")
17861789
session.close()
17871790

1791+
@unittest.skipUnless(HAVE_PROTOBUF, "Protobuf not available")
17881792
def test_initial_notice_pure(self):
17891793
connect_kwargs = self.connect_kwargs.copy()
17901794
host = "localhost"

0 commit comments

Comments
 (0)