Fixes reporting the error when drivers have the same name
Resolves issue #25 Change-Id: I944800fc2da0018b5b3bb076d296c38126fe97bf
This commit is contained in:
parent
5b22dba30a
commit
7ab52e5475
@ -2,6 +2,11 @@
|
||||
History
|
||||
=========
|
||||
|
||||
dev
|
||||
|
||||
- Fixes an exception when reporting on an error where multiple drivers
|
||||
have the same name (:issue:`25`, solution provided by clayg).
|
||||
|
||||
0.11
|
||||
|
||||
- Fixes logging configuration under Python 2.6 with a NullHandler.
|
||||
|
@ -36,7 +36,8 @@ class DriverManager(NamedExtensionManager):
|
||||
if len(self.extensions) > 1:
|
||||
raise RuntimeError('Multiple %r drivers found: %s' %
|
||||
(namespace,
|
||||
','.join('%s:%s' % (e.module_name, e.attrs[0])
|
||||
','.join('%s:%s' % (e.entry_point.module_name,
|
||||
e.entry_point.attrs[0])
|
||||
for e in self.extensions))
|
||||
)
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
"""Tests for stevedore.extension
|
||||
"""
|
||||
|
||||
import mock
|
||||
import pkg_resources
|
||||
|
||||
from stevedore import driver
|
||||
from stevedore.tests import test_extension
|
||||
|
||||
@ -38,3 +41,21 @@ def test_no_drivers():
|
||||
driver.DriverManager('stevedore.test.extension.none', 't1')
|
||||
except RuntimeError as err:
|
||||
assert "No 'stevedore.test.extension.none' driver found" in str(err)
|
||||
|
||||
|
||||
def test_multiple_drivers():
|
||||
# The idea for this test was contributed by clayg:
|
||||
# https://gist.github.com/clayg/6311348
|
||||
fep_name = 'stevedore.extension.ExtensionManager._find_entry_points'
|
||||
with mock.patch(fep_name) as fep:
|
||||
fep.return_value = [
|
||||
pkg_resources.EntryPoint.parse('backend = pkg1:driver'),
|
||||
pkg_resources.EntryPoint.parse('backend = pkg2:driver'),
|
||||
]
|
||||
for ep in fep.return_value:
|
||||
ep.load = lambda: 'pkg backend'
|
||||
try:
|
||||
driver.DriverManager('stevedore.test.multiple_drivers', 'backend')
|
||||
except RuntimeError as err:
|
||||
assert "Multiple" in str(err), str(err)
|
||||
fep.assert_called_with('stevedore.test.multiple_drivers')
|
||||
|
Loading…
Reference in New Issue
Block a user