How to use activate_later method in Slash

Best Python code snippet using slash

test_plugin_dependency.py

Source:test_plugin_dependency.py Github

copy

Full Screen

1import pytest2import slash.plugins3from .conftest import Checkpoint4from .utils import maybe_decorate5from slash.plugins import PluginInterface6from gossip.exceptions import CannotResolveDependencies7@pytest.mark.parametrize('needs_decorate_method', [True, False])8@pytest.mark.parametrize('provides_decorate_method', [True, False])9def test_needs_provides_plugin_name(needs_decorate_method, provides_decorate_method, checkpoint1, checkpoint2):10 @slash.plugins.active # pylint: disable=abstract-method, unused-variable11 @maybe_decorate(slash.plugins.needs('p'), not needs_decorate_method)12 @autoname13 class NeedsPlugin(PluginInterface):14 @maybe_decorate(slash.plugins.needs('p'), needs_decorate_method)15 def session_start(self):16 checkpoint2()17 @slash.plugins.active # pylint: disable=abstract-method, unused-variable18 @maybe_decorate(slash.plugins.provides('p'), not provides_decorate_method)19 @autoname20 class ProvidesPlugin(PluginInterface):21 @maybe_decorate(slash.plugins.provides('p'), provides_decorate_method)22 def session_start(self):23 checkpoint1()24 slash.hooks.session_start() # pylint: disable=no-member25 assert checkpoint1.timestamp < checkpoint2.timestamp26def test_provides_globally_needs_globally(checkpoint1, checkpoint2):27 '''28 Plugin A: Provides x at class level29 Plugin B: Needs x at class level30 '''31 @slash.plugins.provides('x')32 class PluginA(slash.plugins.interface.PluginInterface):33 def get_name(self):34 return 'plugin a'35 def session_start(self):36 checkpoint1()37 def test_start(self):38 pass39 @slash.plugins.needs('x')40 class PluginB(slash.plugins.interface.PluginInterface):41 def get_name(self):42 return 'plugin b'43 def session_start(self):44 checkpoint2()45 def error_added(self, result, error): # pylint: disable=unused-argument46 pass47 for plugin_cls in [PluginA, PluginB]:48 slash.plugins.manager.install(plugin_cls(), activate_later=True)49 slash.plugins.manager.activate_pending_plugins()50 slash.hooks.session_start() # pylint: disable=no-member51 assert checkpoint1.timestamp < checkpoint2.timestamp52 slash.plugins.manager.deactivate('plugin a')53 with pytest.raises(CannotResolveDependencies) as caught:54 slash.hooks.session_start() # pylint: disable=no-member55 assert caught.value.unmet_dependencies == set(['x'])56def test_provides_globally_needs_specific_hook(checkpoint1, checkpoint2):57 '''58 Plugin A: Provides x at class level59 Plugin B: Needs x for specific hook60 '''61 @slash.plugins.provides('x')62 class PluginA(slash.plugins.interface.PluginInterface):63 def get_name(self):64 return 'plugin a'65 def session_start(self):66 checkpoint1()67 def test_start(self):68 pass69 class PluginB(slash.plugins.interface.PluginInterface):70 def get_name(self):71 return 'plugin b'72 @slash.plugins.needs('x')73 def session_start(self):74 checkpoint2()75 def error_added(self, result, error): # pylint: disable=unused-argument76 pass77 for plugin_cls in [PluginA, PluginB]:78 slash.plugins.manager.install(plugin_cls(), activate_later=True)79 slash.plugins.manager.activate_pending_plugins()80 slash.hooks.session_start() # pylint: disable=no-member81 assert checkpoint1.timestamp < checkpoint2.timestamp82 slash.plugins.manager.deactivate('plugin a')83 with pytest.raises(CannotResolveDependencies) as caught:84 slash.hooks.session_start() # pylint: disable=no-member85 assert caught.value.unmet_dependencies == set(['x'])86def test_provides_globally_needs_specific_hook_which_does_not_exist_at_a(checkpoint2):87 '''88 Plugin A: Provides x at class level89 Plugin B: Needs x for specific hook, this hook does not definied in A90 Expectations:91 Should work in the empty sense92 all non-needing hooks should work, even when missing from A, the specific hook needs to happen in A before B.93 '''94 @slash.plugins.provides('x')95 class PluginA(slash.plugins.interface.PluginInterface):96 def get_name(self):97 return 'plugin a'98 def test_start(self):99 pass100 class PluginB(slash.plugins.interface.PluginInterface):101 def get_name(self):102 return 'plugin b'103 @slash.plugins.needs('x')104 def session_start(self):105 checkpoint2()106 def error_added(self, result, error): # pylint: disable=unused-argument107 pass108 for plugin_cls in [PluginA, PluginB]:109 slash.plugins.manager.install(plugin_cls(), activate_later=True)110 slash.plugins.manager.activate_pending_plugins()111 slash.hooks.session_start() # pylint: disable=no-member112 assert checkpoint2.called113 slash.plugins.manager.deactivate('plugin a')114 with pytest.raises(CannotResolveDependencies) as caught:115 slash.hooks.session_start() # pylint: disable=no-member116 assert caught.value.unmet_dependencies == set(['x'])117def test_provides_specific_hook_needs_globally(checkpoint1, checkpoint2):118 '''119 Plugin A: Provides x on a specific hook120 Plugin B: Needs x at class level121 Expectations:122 This case should fail, because logically the other hooks don't have anyone to provide X for them123 '''124 class PluginA(slash.plugins.interface.PluginInterface):125 def get_name(self):126 return 'plugin a'127 @slash.plugins.provides('x')128 def session_start(self):129 checkpoint1()130 def test_start(self):131 pass132 @slash.plugins.needs('x')133 class PluginB(slash.plugins.interface.PluginInterface):134 def get_name(self):135 return 'plugin b'136 def session_start(self):137 checkpoint2()138 def error_added(self, result, error): # pylint: disable=unused-argument139 pass140 for plugin_cls in [PluginA, PluginB]:141 slash.plugins.manager.install(plugin_cls(), activate_later=True)142 slash.plugins.manager.activate_pending_plugins()143 slash.hooks.session_start() # pylint: disable=no-member144 with pytest.raises(CannotResolveDependencies) as caught:145 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member146 assert caught.value.unmet_dependencies == set(['x'])147def test_provides_specific_hook_needs_globally_with_this_hook_only(checkpoint1, checkpoint2):148 '''149 Plugin A: Provides x on a specific hook150 Plugin B: Needs x at class level, but only has one hook (the one provided by A)151 '''152 class PluginA(slash.plugins.interface.PluginInterface):153 def get_name(self):154 return 'plugin a'155 @slash.plugins.provides('x')156 def session_start(self):157 checkpoint1()158 def test_start(self):159 pass160 @slash.plugins.needs('x')161 class PluginB(slash.plugins.interface.PluginInterface):162 def get_name(self):163 return 'plugin b'164 def session_start(self):165 checkpoint2()166 for plugin_cls in [PluginA, PluginB]:167 slash.plugins.manager.install(plugin_cls(), activate_later=True)168 slash.plugins.manager.activate_pending_plugins()169 slash.hooks.session_start() # pylint: disable=no-member170 assert checkpoint1.timestamp < checkpoint2.timestamp171 slash.plugins.manager.deactivate('plugin a')172 with pytest.raises(CannotResolveDependencies) as caught:173 slash.hooks.session_start() # pylint: disable=no-member174 assert caught.value.unmet_dependencies == set(['x'])175@pytest.mark.parametrize('needs_parent_level', [True, False])176@pytest.mark.parametrize('provides_parent_level', [True, False])177def test_provides_needs_with_inheritence_on_class_level(checkpoint, checkpoint1, checkpoint2, needs_parent_level, provides_parent_level):178 '''179 Plugin A: Provides x in class level (by it self or by inheritence)180 Plugin b: Needs x in class level (by it self or by inheritence)181 '''182 # pylint: disable=abstract-method183 @maybe_decorate(slash.plugins.provides('x'), provides_parent_level)184 class PluginAParent(slash.plugins.interface.PluginInterface):185 def test_start(self):186 pass187 @maybe_decorate(slash.plugins.provides('x'), not provides_parent_level)188 class PluginA(PluginAParent):189 def get_name(self):190 return 'plugin a'191 def session_start(self):192 checkpoint1()193 @maybe_decorate(slash.plugins.needs('x'), needs_parent_level)194 class PluginBParent(slash.plugins.interface.PluginInterface):195 def error_added(self, result, error): # pylint: disable=unused-argument196 checkpoint()197 @maybe_decorate(slash.plugins.needs('x'), not needs_parent_level)198 class PluginB(PluginBParent):199 def get_name(self):200 return 'plugin b'201 def session_start(self):202 checkpoint2()203 for plugin_cls in [PluginA, PluginB]:204 slash.plugins.manager.install(plugin_cls(), activate_later=True)205 slash.plugins.manager.activate_pending_plugins()206 # session_start hook should be provided the PluginA.session_start method207 slash.hooks.session_start() # pylint: disable=no-member208 assert checkpoint1.timestamp < checkpoint2.timestamp209 # error_added hook should be provided by empty registration of pluginA210 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member211 assert checkpoint.called212 slash.plugins.manager.deactivate('plugin a')213 with pytest.raises(CannotResolveDependencies) as caught:214 slash.hooks.session_start() # pylint: disable=no-member215 assert caught.value.unmet_dependencies == set(['x'])216 with pytest.raises(CannotResolveDependencies) as caught:217 slash.hooks.error_added() # pylint: disable=no-member218 assert caught.value.unmet_dependencies == set(['x'])219 # Ensure only hooks required by PluginB fails220 slash.hooks.test_end() # pylint: disable=no-member221def test_provides_needs_in_both_inheritence_levels(checkpoint, checkpoint1, checkpoint2):222 # pylint: disable=abstract-method223 @slash.plugins.provides('x')224 class PluginAParent(slash.plugins.interface.PluginInterface):225 def test_start(self):226 pass227 @slash.plugins.provides('y')228 class PluginA(PluginAParent):229 def get_name(self):230 return 'plugin a'231 def session_start(self):232 checkpoint1()233 @slash.plugins.needs('x')234 class PluginBParent(slash.plugins.interface.PluginInterface):235 def error_added(self, result, error): # pylint: disable=unused-argument236 checkpoint()237 @slash.plugins.needs('y')238 class PluginB(PluginBParent):239 def get_name(self):240 return 'plugin b'241 def session_start(self):242 checkpoint2()243 for plugin_cls in [PluginA, PluginB]:244 slash.plugins.manager.install(plugin_cls(), activate_later=True)245 slash.plugins.manager.activate_pending_plugins()246 # session_start hook should be provided the PluginA.session_start method247 slash.hooks.session_start() # pylint: disable=no-member248 assert checkpoint1.timestamp < checkpoint2.timestamp249 # error_added hook should be provided by empty registration of pluginA250 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member251 assert checkpoint.called252 slash.plugins.manager.deactivate('plugin a')253 with pytest.raises(CannotResolveDependencies) as caught:254 slash.hooks.session_start() # pylint: disable=no-member255 assert caught.value.unmet_dependencies == set(['x', 'y'])256 with pytest.raises(CannotResolveDependencies) as caught:257 slash.hooks.error_added() # pylint: disable=no-member258 assert caught.value.unmet_dependencies == set(['x', 'y'])259 # Ensure only hooks required by PluginB fails260 slash.hooks.test_end() # pylint: disable=no-member261def test_provides_needs_with_inheritence_on_method_level(checkpoint):262 '''263 Plugin A: Provides x in method level (by it self or by inheritence) to test_start & session_start264 Plugin b: Needs x in method level (by it self or by inheritence) on test_start & session_start265 '''266 # pylint: disable=abstract-method267 session_start_a = Checkpoint()268 session_start_b = Checkpoint()269 test_start_a = Checkpoint()270 test_start_b = Checkpoint()271 class PluginAParent(slash.plugins.interface.PluginInterface):272 @slash.plugins.provides('x')273 def test_start(self):274 test_start_a()275 class PluginA(PluginAParent):276 def get_name(self):277 return 'plugin a'278 @slash.plugins.provides('x')279 def session_start(self):280 session_start_a()281 class PluginBParent(slash.plugins.interface.PluginInterface):282 @slash.plugins.needs('x')283 def session_start(self):284 session_start_b()285 def error_added(self, result, error): # pylint: disable=unused-argument286 checkpoint()287 class PluginB(PluginBParent):288 def get_name(self):289 return 'plugin b'290 @slash.plugins.needs('x')291 def test_start(self):292 test_start_b()293 for plugin_cls in [PluginA, PluginB]:294 slash.plugins.manager.install(plugin_cls(), activate_later=True)295 slash.plugins.manager.activate_pending_plugins()296 slash.hooks.session_start() # pylint: disable=no-member297 assert session_start_a.timestamp < session_start_b.timestamp298 slash.hooks.test_start() # pylint: disable=no-member299 assert test_start_a.timestamp < test_start_b.timestamp300 # error_added hook should not need anything301 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member302 assert checkpoint.called303 slash.plugins.manager.deactivate('plugin a')304 with pytest.raises(CannotResolveDependencies) as caught:305 slash.hooks.session_start() # pylint: disable=no-member306 assert caught.value.unmet_dependencies == set(['x'])307 with pytest.raises(CannotResolveDependencies) as caught:308 slash.hooks.test_start() # pylint: disable=no-member309 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member310 assert caught.value.unmet_dependencies == set(['x'])311def test_provides_needs_with_child_overrides():312 # pylint: disable=line-too-long313 '''314 | Hook Name | Plugin A | Plugin B |315 |---------------+-------------------------------------------------------------------------+------------------------------------------------------------------------|316 | session_start | Child Provides x in method level, overrides parent's empty registration | Needs x (Parent) & y (Child) in class level |317 | test_start | Child Provides x in method level, overrides parent's real registration | Needs x (Parent) & y (Child) in class level |318 | error_added | x is not provided, overrides parent's real registration | Needs x (Parent) & y (Child) in class level |319 | test_end | x is not provided, overrides parent's empty registration | Needs x (Parent) & y (Child) in class level |320 | session_end | Parent provides x, child provides y - both in class level | Needs x (Parent) & y (Child) in class level, z in (child) method level |321 '''322 # pylint: disable=abstract-method323 session_start_a = Checkpoint()324 session_start_b = Checkpoint()325 test_start_a = Checkpoint()326 test_start_b = Checkpoint()327 @slash.plugins.provides('x')328 class PluginAParent(slash.plugins.interface.PluginInterface):329 def test_start(self):330 test_start_a()331 def error_added(self, result, error): # pylint: disable=unused-argument332 pass333 def session_end(self):334 pass335 @slash.plugins.provides('y')336 class PluginA(PluginAParent):337 def get_name(self):338 return 'plugin a'339 @slash.plugins.provides('x')340 def session_start(self):341 # Overrides empty registration of PluginAParent342 session_start_a()343 @slash.plugins.provides('x')344 def test_start(self):345 # Overrides "real" registration of PluginAParent346 test_start_a()347 def error_added(self, result, error): # pylint: disable=unused-argument348 # Overrides "real" registration of PluginAParent349 pass350 def test_end(self):351 # Overrides empty registration of PluginAParent352 pass353 @slash.plugins.needs('x')354 class PluginBParent(slash.plugins.interface.PluginInterface):355 def session_start(self):356 session_start_b()357 def error_added(self, result, error): # pylint: disable=unused-argument358 pass359 def test_start(self):360 test_start_b()361 def test_end(self):362 pass363 @slash.plugins.needs('y')364 class PluginB(PluginBParent):365 def get_name(self):366 return 'plugin b'367 @slash.plugins.needs('z')368 def session_end(self):369 pass370 for plugin_cls in [PluginA, PluginB]:371 slash.plugins.manager.install(plugin_cls(), activate_later=True)372 slash.plugins.manager.activate_pending_plugins()373 slash.hooks.session_start() # pylint: disable=no-member374 assert session_start_a.timestamp < session_start_b.timestamp375 slash.hooks.test_start() # pylint: disable=no-member376 assert test_start_a.timestamp < test_start_b.timestamp377 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member378 slash.hooks.test_end() # pylint: disable=no-member379 with pytest.raises(CannotResolveDependencies) as caught:380 slash.hooks.session_end() # pylint: disable=no-member381 assert caught.value.unmet_dependencies == set(['z'])382 slash.plugins.manager.deactivate('plugin a')383 with pytest.raises(CannotResolveDependencies) as caught:384 slash.hooks.session_start() # pylint: disable=no-member385 assert caught.value.unmet_dependencies == set(['x', 'y'])386 with pytest.raises(CannotResolveDependencies) as caught:387 slash.hooks.test_start() # pylint: disable=no-member388 assert caught.value.unmet_dependencies == set(['x', 'y'])389 with pytest.raises(CannotResolveDependencies) as caught:390 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member391 assert caught.value.unmet_dependencies == set(['x', 'y'])392 with pytest.raises(CannotResolveDependencies) as caught:393 slash.hooks.test_end() # pylint: disable=no-member394 assert caught.value.unmet_dependencies == set(['x', 'y'])395 with pytest.raises(CannotResolveDependencies) as caught:396 slash.hooks.session_end() # pylint: disable=no-member397 assert caught.value.unmet_dependencies == set(['x', 'y', 'z'])398def autoname(plugin):399 def get_name(self):400 return type(self).__name__.lower()401 plugin.get_name = get_name...

Full Screen

Full Screen

test_plugin_activation.py

Source:test_plugin_activation.py Github

copy

Full Screen

...102 plugins.manager.uninstall(plugin)103def test_pending_activation(plugin):104 plugins.manager.install(plugin)105 assert not plugins.manager.get_active_plugins()106 plugins.manager.activate_later(plugin)107 assert not plugins.manager.get_active_plugins()108 plugins.manager.activate_pending_plugins()109 assert plugin.get_name() in plugins.manager.get_active_plugins()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

test_project_customization.py

Source:test_project_customization.py Github

copy

Full Screen

...8 assert result.data['customized']9def test_plugin_activation_deactivate_via_commandline(customized_suite, suite_test):10 @customized_suite.slashrc.include11 def __code__():12 slash.plugins.manager.activate_later('custom')13 result = customized_suite.run(additional_args=['--without-custom']).session.results.global_result14 assert 'customized' not in result.data15def test_plugin_activation_from_configure_hook(customized_suite, suite_test):16 @customized_suite.slashrc.include17 def __code__():18 @slash.hooks.configure.register19 def configure_hook():20 slash.plugins.manager.activate_later('custom')21 result = customized_suite.run().session.results.global_result22 assert 'customized' in result.data23def test_plugin_deactivation_override_configure_hook(customized_suite, suite_test):24 @customized_suite.slashrc.include25 def __code__():26 @slash.hooks.configure.register27 def configure_hook():28 slash.plugins.manager.activate_later('custom')29 result = customized_suite.run(additional_args=['--without-custom']).session.results.global_result30 assert 'customized' not in result.data31def test_configure_hook_depends_on_configuration_cmdline(customized_suite, suite_test):32 @customized_suite.slashrc.include33 def __code__():34 slash.config.extend({35 'some_config': 1 // slash.conf.Cmdline(arg='--some-config'),36 })37 @slash.hooks.configure.register38 def configure_hook():39 assert slash.config.root.some_config == 100040 result = customized_suite.run(additional_args=['--some-config=1000']).session.results.global_result41@pytest.fixture42def customized_suite(suite):...

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