Fixing tests with tox 4.2.6

1. Remove basepython from testenv
2. this change also fix unittests because stevedore has dropped pkg_resources[0],
after tox upgraded to 4.0.*, tox with usedevelop parameter installs trove in
develop mode, hence stevedore unable to get the entrypoints from sdist[1].
[0]: d5297167e0
[1]: https://tox.wiki/en/2.8.1/config.html#confval-usedevelop=BOOL

Change-Id: Ie65d099509e3cb7a61a09d975c58c1e95aa12b51
This commit is contained in:
wu.chunyang 2023-01-10 22:58:03 +08:00
parent 1d8231d31f
commit 7a62e826a4
2 changed files with 29 additions and 17 deletions

View File

@ -4,7 +4,6 @@ minversion = 3.18.0
skipsdist = True skipsdist = True
[testenv] [testenv]
basepython = python3
setenv = VIRTUAL_ENV={envdir} setenv = VIRTUAL_ENV={envdir}
PYTHONWARNINGS=default::DeprecationWarning PYTHONWARNINGS=default::DeprecationWarning
OS_TEST_PATH=./trove/tests/unittests OS_TEST_PATH=./trove/tests/unittests

View File

@ -15,9 +15,10 @@
import configparser import configparser
import os import os
import pkg_resources
from unittest import mock from unittest import mock
import importlib.metadata as importlib_metadata
import trove import trove
from trove.common import extensions from trove.common import extensions
from trove.extensions.routes.mgmt import Mgmt from trove.extensions.routes.mgmt import Mgmt
@ -29,11 +30,12 @@ DEFAULT_EXTENSION_MAP = {
'MYSQL': [Mysql, extensions.ExtensionDescriptor] 'MYSQL': [Mysql, extensions.ExtensionDescriptor]
} }
EP_TEXT = ''' INVALID_EXTENSION_MAP = {
mgmt = trove.extensions.routes.mgmt:Mgmt 'mgmt': 'trove.extensions.routes.mgmt:Mgmt',
mysql = trove.extensions.routes.mysql:Mysql 'mysql': 'trove.extensions.routes.mysql:Mysql',
invalid = trove.tests.unittests.api.common.test_extensions:InvalidExtension 'invalid': 'trove.tests.unittests.api.common.'
''' 'test_extensions:InvalidExtension'
}
class InvalidExtension(object): class InvalidExtension(object):
@ -68,8 +70,8 @@ class TestExtensionLoading(trove_testtools.TestCase):
for clazz in DEFAULT_EXTENSION_MAP[alias]: for clazz in DEFAULT_EXTENSION_MAP[alias]:
self.assertIsInstance(ext, clazz, "Improper extension class") self.assertIsInstance(ext, clazz, "Improper extension class")
@mock.patch("pkg_resources.iter_entry_points") @mock.patch("stevedore.enabled.EnabledExtensionManager.list_entry_points")
def test_default_extensions(self, mock_iter_eps): def test_default_extensions(self, mock_extensions):
trove_base = os.path.abspath(os.path.join( trove_base = os.path.abspath(os.path.join(
os.path.dirname(trove.__file__), "..")) os.path.dirname(trove.__file__), ".."))
setup_path = "%s/setup.cfg" % trove_base setup_path = "%s/setup.cfg" % trove_base
@ -79,20 +81,31 @@ class TestExtensionLoading(trove_testtools.TestCase):
parser.read(setup_path) parser.read(setup_path)
entry_points = parser.get( entry_points = parser.get(
'entry_points', extensions.ExtensionManager.EXT_NAMESPACE) 'entry_points', extensions.ExtensionManager.EXT_NAMESPACE)
eps = pkg_resources.EntryPoint.parse_group('plugins', entry_points) test_extensions = list()
mock_iter_eps.return_value = eps.values() for entry in entry_points.split('\n')[1:]:
name = entry.split("=")[0].strip()
value = entry.split("=")[1].strip()
test_extensions.append(importlib_metadata.EntryPoint(
name=name,
value=value,
group=extensions.ExtensionManager.EXT_NAMESPACE))
mock_extensions.return_value = test_extensions
extension_mgr = extensions.ExtensionManager() extension_mgr = extensions.ExtensionManager()
self.assertEqual(sorted(DEFAULT_EXTENSION_MAP.keys()), self.assertEqual(sorted(DEFAULT_EXTENSION_MAP.keys()),
sorted(extension_mgr.extensions.keys()), sorted(extension_mgr.extensions.keys()),
"Invalid extension names") "Invalid extension names")
self._assert_default_extensions(extension_mgr.extensions) self._assert_default_extensions(extension_mgr.extensions)
@mock.patch("pkg_resources.iter_entry_points") @mock.patch("stevedore.enabled.EnabledExtensionManager.list_entry_points")
def test_invalid_extension(self, mock_iter_eps): def test_invalid_extension(self, mock_extensions):
eps = pkg_resources.EntryPoint.parse_group('mock', EP_TEXT) test_extensions = list()
mock_iter_eps.return_value = eps.values() for k, v in INVALID_EXTENSION_MAP.items():
test_extensions.append(importlib_metadata.EntryPoint(
name=k,
value=v,
group=extensions.ExtensionManager.EXT_NAMESPACE))
mock_extensions.return_value = test_extensions
extension_mgr = extensions.ExtensionManager() extension_mgr = extensions.ExtensionManager()
self.assertEqual(len(DEFAULT_EXTENSION_MAP.keys()), self.assertEqual(2, len(extension_mgr.extensions),
len(extension_mgr.extensions),
"Loaded invalid extensions") "Loaded invalid extensions")
self._assert_default_extensions(extension_mgr.extensions) self._assert_default_extensions(extension_mgr.extensions)