def test_shutdown_hook_callable(self): _registered_exit_funcs = [] def _fake_atexit_register(what): _registered_exit_funcs.append(what) #Temporary replace atexit.register _real_register = atexit.register atexit.register = _fake_atexit_register # Temporary replace the hooks namespace so we register hooks only for this test original_hooks, tg.hooks = tg.hooks, _TGGlobalHooksNamespace() try: executed = [] def func(): executed.append(True) tg.hooks.register('shutdown', func) milestones.config_ready.reach() # This forces hook registration assert func in tg.hooks._hooks['shutdown'] assert len(_registered_exit_funcs), _registered_exit_funcs _registered_exit_funcs[0]() assert True in executed, executed finally: tg.hooks = original_hooks atexit.register = _real_register
def test_render_hooks(): old_hooks, tg.hooks = tg.hooks, _TGGlobalHooksNamespace() calls = [] def render_call_hook(*args, **kw): calls.append(1) base_config = TestConfig(folder='rendering', values={ 'use_sqlalchemy': False, 'use_legacy_renderer': False, # this is specific to mako to make sure inheritance works 'use_dotted_templatenames': False, 'use_toscawidgets': False, 'use_toscawidgets2': False }) milestones._reset_all() base_config.register_hook('before_render_call', render_call_hook) base_config.register_hook('after_render_call', render_call_hook) app = app_from_config(base_config, reset_milestones=False) app.get('/') try: assert len(calls) == 2 finally: tg.hooks = old_hooks
def test_startup_hook_with_exception(self): # Temporary replace the hooks namespace so we register hooks only for this test original_hooks, tg.hooks = tg.hooks, _TGGlobalHooksNamespace() try: def func(): raise Exception tg.hooks.register('startup', func) conf = AppConfig(minimal=True) app = conf.make_wsgi_app() finally: tg.hooks = original_hooks
def test_startup_hook(self): # Temporary replace the hooks namespace so we register hooks only for this test original_hooks, tg.hooks = tg.hooks, _TGGlobalHooksNamespace() try: executed = [] def func(): executed.append(True) tg.hooks.register('startup', func) conf = AppConfig(minimal=True) app = conf.make_wsgi_app() assert True in executed, executed finally: tg.hooks = original_hooks
def teardown(self): milestones._reset_all() tg.hooks = _TGGlobalHooksNamespace() # Reset hooks
def tearDown(self): milestones._reset_all() tg.hooks = _TGGlobalHooksNamespace()
def setUp(self): milestones._reset_all() tg.hooks = _TGGlobalHooksNamespace()