Last active
December 18, 2015 17:39
-
-
Save drocco007/5819897 to your computer and use it in GitHub Desktop.
initial thoughts on creating test extension managers
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
class TestExtensionManagerMixin(object): | |
"""Mixin base class for test extension managers.""" | |
def over(self, extensions): | |
"""Set the Extensions used by this manager. | |
:param extensions: Pre-configured Extension instances to use | |
instead of loading them from entry points. | |
:type extensions: list of :class:`~stevedore.extension.Extension` | |
:returns: this extension manager instance to allow chaining on | |
the constructor | |
""" | |
self.extensions = extensions | |
return self | |
def _load_plugins(self, invoke_on_load, | |
invoke_args, | |
invoke_kwds): | |
return [] | |
class TestExtensionManager(TestExtensionManagerMixin, | |
extension.ExtensionManager): | |
pass | |
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
from mock import Mock | |
from stevedore.tests.manager import TestExtensionManager | |
from stevedore.extension import Extension | |
test_extension = Extension('test_extension', None, None, None) | |
def test_manager_should_allow_name_access(): | |
em = TestExtensionManager('').over([test_extension]) | |
assert test_extension == em[test_extension.name] | |
def test_manager_should_call(): | |
em = TestExtensionManager('').over([test_extension]) | |
func = Mock() | |
em.map(func) | |
func.assert_called_once_with(test_extension) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment