From 3ffa7735d9762d0df743f9250609455e083ac79a Mon Sep 17 00:00:00 2001 From: hpk Date: Thu, 2 Apr 2009 21:16:57 +0200 Subject: [PATCH] [svn r63550] * move hook and event API definitions to py/test/plugin/api.py * make "py.test" work on "doc" directory again. --HG-- branch : trunk --- py/test/plugin/api.py | 120 ++++++++++++++++++++++++++ py/test/plugin/pytest_plugintester.py | 113 +----------------------- py/test/plugin/pytest_restdoc.py | 14 +++ 3 files changed, 137 insertions(+), 110 deletions(-) create mode 100644 py/test/plugin/api.py diff --git a/py/test/plugin/api.py b/py/test/plugin/api.py new file mode 100644 index 000000000..b347ea7da --- /dev/null +++ b/py/test/plugin/api.py @@ -0,0 +1,120 @@ +""" +API definitions for pytest plugin hooks and events +""" + +class PluginHooks: + # ------------------------------------------------------------------------------ + # Command line and configuration hooks + # ------------------------------------------------------------------------------ + def pytest_addoption(self, parser): + """ called before commandline parsing. """ + + def pytest_configure(self, config): + """ called after command line options have been parsed. + and all plugins and initial conftest files been loaded. + ``config`` provides access to all such configuration values. + """ + def pytest_unconfigure(self, config): + """ called before test process is exited. + """ + + + # ------------------------------------------------------------------------------ + # collection hooks + # ------------------------------------------------------------------------------ + def pytest_collect_file(self, path, parent): + """ return Collection node or None. """ + + def pytest_collect_recurse(self, path, parent): + """ return True/False to cause/prevent recursion into given directory. + return None if you do not want to make the decision. + """ + + def pytest_collect_directory(self, path, parent): + """ return Collection node or None. """ + + def pytest_pymodule_makeitem(self, modcol, name, obj): + """ return custom item/collector for a python object in a module, or None. """ + + # ------------------------------------------------------------------------------ + # runtest related hooks + # ------------------------------------------------------------------------------ + + def pytest_pyfunc_call(self, pyfuncitem, args, kwargs): + """ return True if we consumed/did the call to the python function item. """ + + def pytest_item_makereport(self, item, excinfo, when, outerr): + """ return ItemTestReport event for the given test outcome. """ + + # reporting hooks (invoked from pytest_terminal.py) + def pytest_report_teststatus(self, event): + """ return shortletter and verbose word. """ + + def pytest_terminal_summary(self, terminalreporter): + """ add additional section in terminal summary reporting. """ + +class Events: + # Events + def pyevent(self, eventname, *args, **kwargs): + """ generically called for each notification event. """ + + def pyevent__gateway_init(self, gateway): + """ called after a gateway has been initialized. """ + + def pyevent__gateway_exit(self, gateway): + """ called when gateway is being exited. """ + + def pyevent__gwmanage_rsyncstart(self, source, gateways): + """ called before rsyncing a directory to remote gateways takes place. """ + + def pyevent__gwmanage_rsyncfinish(self, source, gateways): + """ called after rsyncing a directory to remote gateways takes place. """ + + def pyevent__trace(self, category, msg): + """ called for tracing events. """ + + def pyevent__internalerror(self, event): + """ called for internal errors. """ + + def pyevent__itemstart(self, item, node): + """ test item gets collected. """ + + def pyevent__itemtestreport(self, event): + """ test has been run. """ + + def pyevent__deselected(self, event): + """ item has been dselected. """ + + def pyevent__collectionstart(self, event): + """ collector starts collecting. """ + + def pyevent__collectionreport(self, event): + """ collector finished collecting. """ + + def pyevent__testrunstart(self, event): + """ whole test run starts. """ + + def pyevent__testrunfinish(self, event): + """ whole test run finishes. """ + + def pyevent__gwmanage_newgateway(self, gateway): + """ execnet gateway manager has instantiated a gateway. + The gateway will have an 'id' attribute that is unique + within the gateway manager context. + """ + def pyevent__testnodeready(self, node): + """ Test Node is ready to operate. """ + + def pyevent__testnodedown(self, node, error): + """ Test Node is down. """ + + def pyevent__rescheduleitems(self, event): + """ reschedule Items from a node that went down. """ + + def pyevent__looponfailinfo(self, event): + """ info for repeating failing tests. """ + + def pyevent__plugin_registered(self, plugin): + """ a new py lib plugin got registered. """ + + diff --git a/py/test/plugin/pytest_plugintester.py b/py/test/plugin/pytest_plugintester.py index 94ee31235..11380009b 100644 --- a/py/test/plugin/pytest_plugintester.py +++ b/py/test/plugin/pytest_plugintester.py @@ -2,6 +2,7 @@ plugin with support classes and functions for testing pytest functionality """ import py +from py.__.test.plugin import api class PlugintesterPlugin: """ test support code for testing pytest plugins. """ @@ -43,7 +44,8 @@ class PluginTester(Support): fail = False pm = py.test._PytestPlugins() methods = collectattr(pluginclass) - hooks = collectattr(PytestPluginHooks) + hooks = collectattr(api.PluginHooks) + hooks.update(collectattr(api.Events)) getargs = py.std.inspect.getargs def isgenerichook(name): @@ -92,115 +94,6 @@ def formatdef(func): py.std.inspect.formatargspec(*py.std.inspect.getargspec(func)) ) - -class PytestPluginHooks: - def __init__(self): - """ usually called only once per test process. """ - - def pytest_addoption(self, parser): - """ called before commandline parsing. """ - - def pytest_configure(self, config): - """ called after command line options have been parsed. - and all plugins and initial conftest files been loaded. - ``config`` provides access to all such configuration values. - """ - def pytest_unconfigure(self, config): - """ called before test process is exited. - """ - - def pytest_pyfunc_call(self, pyfuncitem, args, kwargs): - """ return True if we consumed/did the call to the python function item. """ - - def pytest_item_makereport(self, item, excinfo, when, outerr): - """ return ItemTestReport event for the given test outcome. """ - - # collection hooks - def pytest_collect_file(self, path, parent): - """ return Collection node or None. """ - - def pytest_collect_recurse(self, path, parent): - """ return True/False to cause/prevent recursion into given directory. - return None if you do not want to make the decision. - """ - - def pytest_collect_directory(self, path, parent): - """ return Collection node or None. """ - - def pytest_pymodule_makeitem(self, modcol, name, obj): - """ return custom item/collector for a python object in a module, or None. """ - - # reporting hooks (invoked from pytest_terminal.py) - def pytest_report_teststatus(self, event): - """ return shortletter and verbose word. """ - - def pytest_terminal_summary(self, terminalreporter): - """ add additional section in terminal summary reporting. """ - - # Events - def pyevent(self, eventname, *args, **kwargs): - """ called for each testing event. """ - - def pyevent__gateway_init(self, gateway): - """ called after a gateway has been initialized. """ - - def pyevent__gateway_exit(self, gateway): - """ called when gateway is being exited. """ - - def pyevent__gwmanage_rsyncstart(self, source, gateways): - """ called before rsyncing a directory to remote gateways takes place. """ - - def pyevent__gwmanage_rsyncfinish(self, source, gateways): - """ called after rsyncing a directory to remote gateways takes place. """ - - def pyevent__trace(self, category, msg): - """ called for tracing events. """ - - def pyevent__internalerror(self, event): - """ called for internal errors. """ - - def pyevent__itemstart(self, item, node): - """ test item gets collected. """ - - def pyevent__itemtestreport(self, event): - """ test has been run. """ - - def pyevent__deselected(self, event): - """ item has been dselected. """ - - def pyevent__collectionstart(self, event): - """ collector starts collecting. """ - - def pyevent__collectionreport(self, event): - """ collector finished collecting. """ - - def pyevent__testrunstart(self, event): - """ whole test run starts. """ - - def pyevent__testrunfinish(self, event): - """ whole test run finishes. """ - - def pyevent__gwmanage_newgateway(self, gateway): - """ execnet gateway manager has instantiated a gateway. - The gateway will have an 'id' attribute that is unique - within the gateway manager context. - """ - def pyevent__testnodeready(self, node): - """ Node is ready to operate. """ - - def pyevent__testnodedown(self, node, error): - """ Node is down. """ - - def pyevent__rescheduleitems(self, event): - """ Items from a node that went down. """ - - def pyevent__looponfailinfo(self, event): - """ info for repeating failing tests. """ - - def pyevent__plugin_registered(self, plugin): - """ a new py lib plugin got registered. """ - - # =============================================================================== # plugin tests # =============================================================================== diff --git a/py/test/plugin/pytest_restdoc.py b/py/test/plugin/pytest_restdoc.py index 2e6235a22..211b0a5b5 100644 --- a/py/test/plugin/pytest_restdoc.py +++ b/py/test/plugin/pytest_restdoc.py @@ -85,6 +85,18 @@ class ReSTSyntaxTest(py.test.collect.Item): directive.register_linkrole('api', self.resolve_linkrole) directive.register_linkrole('source', self.resolve_linkrole) + # XXX fake sphinx' "toctree" and refs + directive.register_linkrole('ref', self.resolve_linkrole) + + from docutils.parsers.rst import directives + def toctree_directive(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + return [] + toctree_directive.content = 1 + toctree_directive.options = {'maxdepth': int, 'glob': directives.flag, + 'hidden': directives.flag} + directives.register_directive('toctree', toctree_directive) + def resolve_linkrole(self, name, text, check=True): apigen_relpath = self.project.apigen_relpath @@ -125,6 +137,8 @@ class ReSTSyntaxTest(py.test.collect.Item): else: relpath += '.html' return (text, apigen_relpath + 'source/%s' % (relpath,)) + elif name == 'ref': + return ("", "") def _checkskip(self, lpath, htmlpath=None): if not self.config.getvalue("forcegen"):