How to use deactivate_later method in Slash

Best Python code snippet using slash

plugin_manager.py

Source:plugin_manager.py Github

copy

Full Screen

...114 return False115 def configure_for_parallel_mode(self):116 for plugin in self.get_installed_plugins().values():117 if self._is_parallel_supported(plugin):118 self.deactivate_later(plugin)119 def install(self, plugin, activate=False, activate_later=False, is_internal=False):120 """121 Installs a plugin object to the plugin mechanism. ``plugin`` must be an object deriving from122 :class:`slash.plugins.PluginInterface`.123 """124 if not isinstance(plugin, PluginInterface):125 raise IncompatiblePlugin("Invalid plugin type: {!r}".format(type(plugin)))126 plugin_name = plugin.get_name()127 if re.search(r'[^A-Za-z0-9_ -]', plugin_name):128 raise IllegalPluginName("Illegal plugin name: {}".format(plugin_name))129 if any(char in plugin_name for char in _DEPRECATED_CHARACTERS):130 warn_deprecation("In the future, dashes and underscore will not be allowed in plugin names - "131 "spaces should be used instead (plugin name: {!r})".format(plugin_name))132 self._configure(plugin)133 self._installed[plugin_name] = PluginInfo(plugin, is_internal)134 self._cmd_line_to_name[self.normalize_command_line_name(plugin_name)] = plugin_name135 self._config_to_name[self.normalize_config_name(plugin_name)] = plugin_name136 if not hasattr(plugin, '__toggles__'):137 plugin.__toggles__ = {138 'session': gossip.Toggle(),139 }140 if activate:141 try:142 self.activate(plugin_name)143 except IncompatiblePlugin:144 exc_info = sys.exc_info()145 self.uninstall(plugin)146 reraise(*exc_info)147 if activate_later:148 self.activate_later(plugin_name)149 def install_builtin_plugins(self):150 for builtin_plugin_module in self._iter_builtin_plugin_modules():151 module = __import__(152 "slash.plugins.builtin.{}".format(builtin_plugin_module),153 fromlist=[""]154 )155 self.install(module.Plugin())156 def _iter_builtin_plugin_modules(self):157 builtin_dir = os.path.join(os.path.dirname(__file__), "builtin")158 for filename in os.listdir(builtin_dir):159 if filename.startswith("_") or filename.startswith(".") or not filename.endswith(".py"):160 continue161 yield filename[:-3]162 def uninstall(self, plugin):163 """164 Uninstalls a plugin165 """166 plugin = self._get_installed_plugin(plugin)167 try:168 self.deactivate(plugin)169 except IncompatiblePlugin:170 pass171 self._unconfigure(plugin)172 plugin_name = plugin.get_name()173 self._installed.pop(plugin_name)174 cmd_name = self.normalize_command_line_name(plugin_name)175 self._cmd_line_to_name.pop(cmd_name, None)176 config_name = self.normalize_config_name(plugin_name)177 self._config_to_name.pop(config_name, None)178 def uninstall_all(self):179 """180 Uninstalls all installed plugins181 """182 for plugin_info in list(self._installed.values()):183 self.uninstall(plugin_info.plugin_instance)184 assert not self._installed185 def activate(self, plugin):186 """187 Activates a plugin, registering its hook callbacks to their respective hooks.188 :param plugin: either a plugin object or a plugin name189 """190 plugin = self._get_installed_plugin(plugin)191 plugin_name = plugin.get_name()192 if self._is_parallel_supported(plugin):193 _logger.warn("Activating plugin {} though it's configuration for parallel mode doesn't fit to current session".format(plugin.get_name()))194 plugin.activate()195 for hook, callback, kwargs in self._get_plugin_registrations(plugin):196 hook.register(callback, **kwargs)197 self._active.add(plugin_name)198 def activate_later(self, plugin):199 """200 Adds a plugin to the set of plugins pending activation. It can be remvoed from the queue with :meth:`.deactivate_later`201 .. seealso:: :meth:`.activate_pending_plugins`202 """203 self._pending_activation.add(self._get_installed_plugin(plugin).get_name())204 def deactivate_later(self, plugin):205 """206 Removes a plugin from the set of plugins pending activation.207 .. seealso:: :meth:`.activate_pending_plugins`208 """209 self._pending_deactivation.add(self._get_installed_plugin(plugin).get_name())210 def activate_pending_plugins(self):211 """212 Activates all plugins queued with :meth:`.activate_later`213 """214 while self._pending_activation:215 plugin_name = self._pending_activation.pop()216 if plugin_name not in self._pending_deactivation:217 self.activate(plugin_name)218 while self._pending_deactivation:...

Full Screen

Full Screen

test_plugin_activation.py

Source:test_plugin_activation.py Github

copy

Full Screen

...110 assert plugin._activate_called111def test_pending_activation_deactivation(plugin):112 plugins.manager.install(plugin)113 plugins.manager.activate_later(plugin)114 plugins.manager.deactivate_later(plugin)115 assert plugin.get_name() in plugins.manager._pending_activation116 assert plugin.get_name() in plugins.manager._pending_deactivation117 plugins.manager.activate_pending_plugins()118 assert not plugin._activate_called119def test_install_activate_later(plugin):120 plugins.manager.install(plugin, activate_later=True)121 assert plugin.get_name() in plugins.manager._pending_activation122@pytest.mark.parametrize('activate_later_first', [True, False])123def test_deactivate_later_already_activated(plugin, activate_later_first):124 plugins.manager.install(plugin, activate=True)125 if activate_later_first:126 plugins.manager.activate_later(plugin)127 plugins.manager.deactivate_later(plugin)128 plugins.manager.activate_pending_plugins()129 assert plugin.get_name() not in plugins.manager.get_active_plugins()130 assert plugin._activate_called131 assert plugin._deactivate_called132def test_pending_activation_not_exists(plugin):133 with pytest.raises(UnknownPlugin):134 plugins.manager.activate_later(plugin)135 with pytest.raises(UnknownPlugin):136 plugins.manager.activate_later(plugin.get_name())137def test_pending_deactivation_not_exists(plugin):138 with pytest.raises(UnknownPlugin):139 plugins.manager.deactivate_later(plugin)140 with pytest.raises(UnknownPlugin):141 plugins.manager.deactivate_later(plugin.get_name())142def _assert_hooks_not_registered(plugin):143 hooks.session_start() # pylint: disable=no-member...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful