class ThirdPartyPluginLoaderTest (unittest.TestCase):

    def setUp(self):
        super(ThirdPartyPluginLoaderTest, self).setUp()
        self.project = mock()
        self.loader = ThirdPartyPluginLoader(mock())

    def tearDown(self):
        super(ThirdPartyPluginLoaderTest, self).tearDown()
        unstub()

    def test_should_raise_exception_when_requiring_plugin_and_plugin_is_not_found(self):
        when(builtin_module).__import__(
            "spam").thenRaise(ImportError())

        self.assertRaises(
            MissingPluginException, self.loader.load_plugin, self.project, "spam")

        verify(builtin_module).__import__("spam")

    def test_should_import_plugin_when_requiring_plugin_and_plugin_is_found_as_third_party(self):
        old_module = sys.modules.get("spam")
        try:
            plugin_module = mock()
            sys.modules["spam"] = plugin_module
            when(builtin_module).__import__(
                "spam").thenReturn(plugin_module)

            self.loader.load_plugin(self.project, "spam")

            verify(builtin_module).__import__("spam")
        finally:
            del sys.modules["spam"]
            if old_module:
                sys.modules["spam"] = old_module
class ThirdPartyPluginLoaderTest(unittest.TestCase):
    def setUp(self):
        self.project = mock()
        self.loader = ThirdPartyPluginLoader(mock())

    def tearDown(self):
        unstub()

    def test_should_raise_exception_when_requiring_plugin_and_plugin_is_not_found(
            self):
        when(builtin_module).__import__("spam").thenRaise(ImportError())

        self.assertRaises(MissingPluginException, self.loader.load_plugin,
                          self.project, "spam")

        verify(builtin_module).__import__("spam")

    def test_should_import_plugin_when_requiring_plugin_and_plugin_is_found_as_third_party(
            self):
        old_module = sys.modules.get("spam")
        try:
            plugin_module = mock()
            plugin_module.pyb_version = None
            sys.modules["spam"] = plugin_module
            when(builtin_module).__import__("spam").thenReturn(plugin_module)

            self.loader.load_plugin(self.project, "spam")

            verify(builtin_module).__import__("spam")
        finally:
            del sys.modules["spam"]
            if old_module:
                sys.modules["spam"] = old_module

    def test_should_remove_pypi_protocol_when_importing(self):
        old_module = sys.modules.get("spam")
        try:
            plugin_module = mock()
            plugin_module.pyb_version = None
            sys.modules["spam"] = plugin_module
            when(builtin_module).__import__("pypi:spam").thenReturn(
                plugin_module)

            self.loader.load_plugin(self.project, "spam")

            verify(builtin_module).__import__("spam")
        finally:
            del sys.modules["spam"]
            if old_module:
                sys.modules["spam"] = old_module
Exemple #3
0
 def __init__(self, logger, execution_manager, plugin_loader=None):
     self.logger = logger
     self.execution_manager = execution_manager
     if not plugin_loader:
         builtin_plugin_loader = BuiltinPluginLoader(self.logger)
         installed_thirdparty_plugin_loader = ThirdPartyPluginLoader(
             self.logger)
         downloading_thirdparty_plugin_loader = DownloadingPluginLoader(
             self.logger)
         self.plugin_loader = DispatchingPluginLoader(
             self.logger, builtin_plugin_loader,
             installed_thirdparty_plugin_loader,
             downloading_thirdparty_plugin_loader)
     else:
         self.plugin_loader = plugin_loader
     self._plugins = []
     self.project = None
 def setUp(self):
     self.project = mock()
     self.loader = ThirdPartyPluginLoader(mock())
 def setUp(self):
     self.project = mock()
     self.loader = ThirdPartyPluginLoader(mock())
 def setUp(self):
     super(ThirdPartyPluginLoaderTest, self).setUp()
     self.project = mock()
     self.loader = ThirdPartyPluginLoader(mock())