-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check the names of plugins before importing them
Update NamedExtensionManager to check the names of the plugins before loading any code to avoid importing anything we are not going to use. Fixes issue #4 Change-Id: I27b19cb42ca3d165ce45953281b82e394c4539a2 Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
- Loading branch information
Doug Hellmann
committed
Jan 5, 2013
1 parent
42fbe31
commit 83098c7
Showing
3 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
from stevedore import named | ||
|
||
import mock | ||
|
||
|
||
def test_named(): | ||
em = named.NamedExtensionManager( | ||
'stevedore.test.extension', | ||
['t1'], | ||
names=['t1'], | ||
invoke_on_load=True, | ||
invoke_args=('a',), | ||
invoke_kwds={'b': 'B'}, | ||
) | ||
assert len(em.extensions) == 1 | ||
assert em.names() == ['t1'] | ||
actual = em.names() | ||
assert actual == ['t1'] | ||
|
||
|
||
def test_enabled_before_load(): | ||
# Set up the constructor for the FauxExtension to cause an | ||
# AssertionError so the test fails if the class is instantiated, | ||
# which should only happen if it is loaded before the name of the | ||
# extension is compared against the names that should be loaded by | ||
# the manager. | ||
init_name = 'stevedore.tests.test_extension.FauxExtension.__init__' | ||
with mock.patch(init_name) as m: | ||
m.side_effect = AssertionError | ||
em = named.NamedExtensionManager( | ||
'stevedore.test.extension', | ||
# Look for an extension that does not exist so the | ||
# __init__ we mocked should never be invoked. | ||
names=['no-such-extension'], | ||
invoke_on_load=True, | ||
invoke_args=('a',), | ||
invoke_kwds={'b': 'B'}, | ||
) | ||
actual = em.names() | ||
assert actual == [] |