/usr/share/pyshared/nose2/plugins/printhooks.py is in python-nose2 0.4.7-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | """
This plugin is primarily useful for plugin authors who want to debug
their plugins.
It prints each hook that is called to stderr, along with details of
the event that was passed to the hook.
To do that, this plugin overrides :meth:`nose2.events.Plugin.register`
and, after registration, replaces all existing
:class:`nose2.events.Hook` instances in ``session.hooks`` with
instances of a Hook subclass that prints information about each call.
"""
import sys
from nose2 import events
INDENT = []
__unittest = True
class PrintHooks(events.Plugin):
"""Print hooks as they are called"""
configSection = 'print-hooks'
commandLineSwitch = (None, 'print-hooks',
'Print names of hooks in order of execution')
def register(self):
"""Override to inject noisy hook instances.
Replaces Hook instances in ``self.session.hooks.hooks`` with
noisier objects.
"""
super(PrintHooks, self).register()
# now we can be sure that all other plugins have loaded
# and this plugin is active, patch in our hook class
self.session.hooks.hookClass = NoisyHook
for attr, hook in self.session.hooks.hooks.items():
newhook = NoisyHook(attr)
newhook.plugins = hook.plugins
self.session.hooks.hooks[attr] = newhook
class NoisyHook(events.Hook):
def __call__(self, event):
_report(self.method, event)
_indent()
try:
return super(NoisyHook, self).__call__(event)
finally:
_dedent()
def _report(method, event):
sys.stderr.write("\n%s%s: %s" % (''.join(INDENT), method, event))
def _indent():
INDENT.append(' ')
def _dedent():
if INDENT:
INDENT.pop()
|