Best Python code snippet using slash
test_plugin_dependency.py
Source:test_plugin_dependency.py
...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:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!