def test_should_raise_exception_when_importing_plugin_and_plugin_not_found(self): self.plugin_loader_mock.load_plugin.side_effect = MissingPluginException("not_found") self.assertRaises( MissingPluginException, self.reactor.import_plugin, PluginDef("not_found")) self.plugin_loader_mock.load_plugin.assert_called_with(ANY, PluginDef("not_found"))
def require_plugin(self, plugin, version=None, plugin_module_name=None): if plugin not in self._plugins: self._plugins.append(plugin) plugin_def = PluginDef(plugin, version, plugin_module_name) self._deferred_plugins.add_plugin(plugin_def) self._pending_plugin_installs.append(plugin_def)
def test_should_import_plugin_when_requiring_plugin_and_plugin_is_found_as_builtin( self, load): load.return_value = Mock() plugin_module = self.loader.load_plugin(self.project, PluginDef("spam")) load.assert_called_with("pybuilder.plugins.spam_plugin", "spam") self.assertEqual(load.return_value, plugin_module)
def test_ensure_second_delegatee_will_not_try_when_first_delegatee_loads_plugin( self): result = "result" self.first_delegatee.load_plugin.return_value = result pd = PluginDef("spam") self.assertEqual(result, self.loader.load_plugin(self.project, pd)) self.first_delegatee.load_plugin.assert_called_with(self.project, pd) self.second_delegatee.load_plugin.assert_not_called()
def test_should_raise_error_when_protocol_is_invalid(self): logger = Mock() reactor = Mock() pyb_env = Mock() reactor.python_env_registry = {"pybuilder": pyb_env} reactor.pybuilder_venv = pyb_env downloader = DownloadingPluginLoader(logger) self.assertRaises(MissingPluginException, downloader.install_plugin, reactor, PluginDef("some-plugin"))
def test_should_raise_exception_when_requiring_plugin_and_plugin_is_not_found( self, load): logger = Mock() project = Mock() downloader = DownloadingPluginLoader(logger) load.side_effect = MissingPluginException("Load boom") self.assertRaises(MissingPluginException, downloader.load_plugin, project, PluginDef("spam")) load.assert_called_with("spam", "spam")
def test_should_return_module_returned_by_second_loader_when_first_delegatee_raises_exception( self): result = "result" self.first_delegatee.load_plugin.side_effect = MissingPluginException( "spam") self.second_delegatee.load_plugin.return_value = result pd = PluginDef("spam") self.assertEqual(result, self.loader.load_plugin(self.project, pd)) self.first_delegatee.load_plugin.assert_called_with(self.project, pd) self.second_delegatee.load_plugin.assert_called_with(self.project, pd)
def test_should_raise_exception_when_requiring_plugin_and_plugin_is_not_found( self, load): load.side_effect = MissingPluginException( "pybuilder.plugins.spam_plugin") self.assertRaises(MissingPluginException, self.loader.load_plugin, self.project, PluginDef("spam")) load.assert_has_calls([ call("pybuilder.plugins.spam_plugin", "spam"), call("spam", "spam") ])
def test_should_import_plugin_only_once(self): plugin_module = ModuleType("mock_module") self.plugin_loader_mock.load_plugin.return_value = plugin_module self.reactor.require_plugin("spam") self.reactor.require_plugin("spam") self.reactor._load_deferred_plugins() self.assertEqual(["spam"], self.reactor.get_plugins()) self.plugin_loader_mock.load_plugin.assert_called_with(ANY, PluginDef("spam"))
def test_should_download_module_from_pypi(self, load): logger = Mock() reactor = Mock() pyb_env = Mock() reactor.python_env_registry = {"pybuilder": pyb_env} reactor.pybuilder_venv = pyb_env pd = PluginDef("pypi:external_plugin") pl = DownloadingPluginLoader(logger) pl.install_plugin(reactor, pd) pyb_env.install_dependencies.assert_called_with( [Dependency("external_plugin")], package_type="plugin")
def test_should_raise_exception_when_all_delegatees_raise_exception(self): self.first_delegatee.load_plugin.side_effect = MissingPluginException( "spam") self.second_delegatee.load_plugin.side_effect = MissingPluginException( "spam") pd = PluginDef("spam") self.assertRaises(MissingPluginException, self.loader.load_plugin, self.project, pd) self.first_delegatee.load_plugin.assert_called_with(self.project, pd) self.second_delegatee.load_plugin.assert_called_with(self.project, pd)
def test_should_install_plugin_with_vcs_and_version(self): logger = Mock() reactor = Mock() pyb_env = Mock() reactor.python_env_registry = {"pybuilder": pyb_env} reactor.pybuilder_venv = pyb_env pd = PluginDef("vcs:some-plugin URL", "===1.2.3", "module_name") downloader = DownloadingPluginLoader(logger) downloader.install_plugin(reactor, pd) pyb_env.install_dependencies.assert_called_with([pd.dependency], package_type="plugin")
def test_should_install_upgrade_plugin_with_non_exact_version(self): logger = Mock() reactor = Mock() pyb_env = Mock() reactor.python_env_registry = {"pybuilder": pyb_env} reactor.pybuilder_venv = pyb_env pd = PluginDef("pypi:some-plugin", "~=1.2.3") downloader = DownloadingPluginLoader(logger) downloader.install_plugin(reactor, pd) pyb_env.install_dependencies.assert_called_with([pd.dependency], package_type="plugin")
def test_should_load_module_after_downloading_with_pypi_when_download_succeeds( self, load): logger = Mock() reactor = Mock() pyb_env = Mock() reactor.python_env_registry = {"pybuilder": pyb_env} reactor.pybuilder_venv = pyb_env downloader = DownloadingPluginLoader(logger) pd = PluginDef("pypi:external_plugin") plugin = downloader.load_plugin(reactor, pd) load.assert_called_with("external_plugin", pd.name) self.assertEqual(plugin, load.return_value)
def test_should_import_plugin_when_requiring_plugin_and_plugin_is_found_as_third_party( self, load): logger = Mock() reactor = Mock() pyb_env = Mock() reactor.python_env_registry = {"pybuilder": pyb_env} reactor.pybuilder_venv = pyb_env load.return_value = Mock() downloader = DownloadingPluginLoader(logger) self.assertEqual(load.return_value, downloader.load_plugin(reactor, PluginDef("spam"))) pyb_env.install_dependencies.assert_not_called() self.assertEqual(pyb_env.install_dependencies.call_count, 0)
def test_should_not_load_module_twice_after_downloading_when_pypi_download_fails( self, load): logger = Mock() reactor = Mock() pyb_env = Mock() reactor.python_env_registry = {"pybuilder": pyb_env} reactor.pybuilder_venv = pyb_env pyb_env.install_dependencies.side_effect = MissingPluginException( "PyPI Install Boom") load.side_effect = MissingPluginException("PyPI Load Boom") downloader = DownloadingPluginLoader(logger) pd = PluginDef("pypi:external_plugin") self.assertRaises(MissingPluginException, downloader.load_plugin, Mock(), pd) self.assertEqual(load.call_count, 1)