Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add driver property to DriverManager

Provide an easy way to get direct access to the driver
that was loaded for callers that don't want to use
the __call__() API, or who need richer access to the
object.

Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
  • Loading branch information...
commit 90314340fdfaab25b29c077f8ed72c9c42900269 1 parent 1e21f32
@dhellmann dhellmann authored
View
1  docs/source/history.rst
@@ -5,6 +5,7 @@
0.4
- Removed the ``name`` argument to plugin constructors.
+ - Added ``driver`` property to :class:`~stevedore.driver.DriverManager`.
0.3
View
9 stevedore/driver.py
@@ -31,7 +31,7 @@ def __init__(self, namespace, name,
invoke_kwds=invoke_kwds,
)
if not self.extensions:
- raise RuntimeError('No %r driver found' % namespace)
+ raise RuntimeError('No %r driver found, looking for %r' % (namespace, name))
if len(self.extensions) > 1:
raise RuntimeError('Multiple %r drivers found: %s' %
(namespace,
@@ -60,3 +60,10 @@ def func(ext, *args, **kwds):
results = self.map(func, *args, **kwds)
if results:
return results[0]
+
+ @property
+ def driver(self):
+ """Returns the driver being used by this manager.
+ """
+ ext = self.extensions[0]
+ return ext.obj if ext.obj else ext.plugin
View
17 stevedore/tests/test_driver.py
@@ -2,6 +2,7 @@
"""
from stevedore import driver
+from stevedore.tests import test_extension
def test_detect_plugins():
@@ -18,8 +19,22 @@ def invoke(ext, *args, **kwds):
assert result == ('t1', ('a',), {'b': 'C'})
+def test_driver_property_not_invoked_on_load():
+ em = driver.DriverManager('stevedore.test.extension', 't1',
+ invoke_on_load=False)
+ d = em.driver
+ assert d is test_extension.FauxExtension
+
+
+def test_driver_property_invoked_on_load():
+ em = driver.DriverManager('stevedore.test.extension', 't1',
+ invoke_on_load=True)
+ d = em.driver
+ assert isinstance(d, test_extension.FauxExtension)
+
+
def test_no_drivers():
try:
driver.DriverManager('stevedore.test.extension.none', 't1')
except RuntimeError as err:
- assert "No 'stevedore.test.extension.none' driver found" == str(err)
+ assert "No 'stevedore.test.extension.none' driver found" in str(err)
Please sign in to comment.
Something went wrong with that request. Please try again.