mirror of
				https://github.com/yweber/lodel2.git
				synced 2025-10-31 19:49:02 +01:00 
			
		
		
		
	Writing tests on hooks
This commit is contained in:
		
					parent
					
						
							
								9b27bd1911
							
						
					
				
			
			
				commit
				
					
						196d959188
					
				
			
		
					 2 changed files with 44 additions and 0 deletions
				
			
		|  | @ -10,6 +10,7 @@ from lodel.plugin.extensions import Extension | |||
| from lodel.settings.settings import Settings | ||||
| import tests.loader_utils | ||||
| 
 | ||||
| ##@todo write tests about discovering | ||||
| class PluginTestCase(unittest.TestCase): | ||||
|     """ Test case grouping all tests on Plugin class init procedures """ | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										43
									
								
								tests/plugin/tests_hooks.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								tests/plugin/tests_hooks.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,43 @@ | |||
| #-*- coding: utf-8 -*- | ||||
| 
 | ||||
| import unittest | ||||
| from unittest.mock import MagicMock | ||||
| 
 | ||||
| from lodel.plugin.plugins import Plugin, PluginError | ||||
| from lodel.plugin.hooks import LodelHook | ||||
| 
 | ||||
| testhook = 'are_we_sure_that_this_name_is_uniq' | ||||
| 
 | ||||
| class HookTestCase(unittest.TestCase): | ||||
| 
 | ||||
|     def setUp(self): | ||||
|         LodelHook.__reset__() | ||||
| 
 | ||||
|     def test_registration(self): | ||||
|         """ Testing hook registration using decorator (checking using hook_list() """ | ||||
|         hook_list = LodelHook.hook_list(testhook) | ||||
|         self.assertEqual({}, hook_list) | ||||
|         #hook_registration | ||||
|         @LodelHook(testhook,42) | ||||
|         def funny_fun_test_hook(hook_name, caller, payload): | ||||
|             pass | ||||
|         hook_list = LodelHook.hook_list(testhook) | ||||
|         self.assertEqual({testhook: [(funny_fun_test_hook, 42)]}, hook_list) | ||||
| 
 | ||||
|     def test_call(self): | ||||
|         """ Testing LodelHook.call_hook() """ | ||||
|         #manual registration using a mock | ||||
|         mmock = MagicMock(return_value = '4242') | ||||
|         mmock.__name__ = 'mmock' | ||||
|         hooking = LodelHook(testhook, 1337) | ||||
|         hooking(mmock) | ||||
|         res = LodelHook.call_hook(testhook, 'Caller', 'payload') | ||||
|         #Check returned value | ||||
|         self.assertEqual( | ||||
|             res, | ||||
|             '4242', | ||||
|             'Expected value was "4242" but found %s' % res) | ||||
|         #Checks call | ||||
|         mmock.assert_called_once_with(testhook, 'Caller', 'payload') | ||||
| 
 | ||||
| 
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yann
				Yann