rename "api" into "hook" in most places.
--HG-- branch : trunk
This commit is contained in:
parent
1f14aacbc2
commit
8182d341a5
|
@ -54,10 +54,10 @@ initpkg(__name__,
|
|||
exportdefs = {
|
||||
|
||||
# py lib events and plugins
|
||||
'_com.Registry' : ('./_com.py', 'Registry'),
|
||||
'_com.Registry' : ('./_com.py', 'Registry'),
|
||||
'_com.MultiCall' : ('./_com.py', 'MultiCall'),
|
||||
'_com.comregistry' : ('./_com.py', 'comregistry'),
|
||||
'_com.PluginAPI' : ('./_com.py', 'PluginAPI'),
|
||||
'_com.comregistry' : ('./_com.py', 'comregistry'),
|
||||
'_com.Hooks' : ('./_com.py', 'Hooks'),
|
||||
|
||||
# py lib cmdline tools
|
||||
'cmdline.pytest' : ('./cmdline/pytest.py', 'main',),
|
||||
|
@ -146,7 +146,7 @@ initpkg(__name__,
|
|||
|
||||
# gateways into remote contexts
|
||||
'execnet.__doc__' : ('./execnet/__init__.py', '__doc__'),
|
||||
'execnet._API' : ('./execnet/gateway.py', 'ExecnetAPI'),
|
||||
'execnet._HookSpecs' : ('./execnet/gateway.py', 'ExecnetAPI'),
|
||||
'execnet.SocketGateway' : ('./execnet/register.py', 'SocketGateway'),
|
||||
'execnet.PopenGateway' : ('./execnet/register.py', 'PopenGateway'),
|
||||
'execnet.SshGateway' : ('./execnet/register.py', 'SshGateway'),
|
||||
|
|
16
py/_com.py
16
py/_com.py
|
@ -108,21 +108,21 @@ class Registry:
|
|||
*args, **kwargs).execute(firstresult=True)
|
||||
|
||||
|
||||
class PluginAPI:
|
||||
def __init__(self, apiclass, registry=None):
|
||||
self._apiclass = apiclass
|
||||
class Hooks:
|
||||
def __init__(self, hookspecs, registry=None):
|
||||
self._hookspecs = hookspecs
|
||||
if registry is None:
|
||||
registry = comregistry
|
||||
self.registry = registry
|
||||
for name, method in vars(apiclass).items():
|
||||
for name, method in vars(hookspecs).items():
|
||||
if name[:2] != "__":
|
||||
firstresult = getattr(method, 'firstresult', False)
|
||||
mm = ApiCall(registry, name, firstresult=firstresult)
|
||||
mm = HookCall(registry, name, firstresult=firstresult)
|
||||
setattr(self, name, mm)
|
||||
def __repr__(self):
|
||||
return "<PluginAPI %r %r>" %(self._apiclass, self._plugins)
|
||||
return "<Hooks %r %r>" %(self._hookspecs, self._plugins)
|
||||
|
||||
class ApiCall:
|
||||
class HookCall:
|
||||
def __init__(self, registry, name, firstresult):
|
||||
self.registry = registry
|
||||
self.name = name
|
||||
|
@ -130,7 +130,7 @@ class ApiCall:
|
|||
|
||||
def __repr__(self):
|
||||
mode = self.firstresult and "firstresult" or "each"
|
||||
return "<ApiCall %r mode=%s %s>" %(self.name, mode, self.registry)
|
||||
return "<HookCall %r mode=%s %s>" %(self.name, mode, self.registry)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
if args:
|
||||
|
|
|
@ -88,10 +88,10 @@ class Gateway(object):
|
|||
self._channelfactory = ChannelFactory(self, _startcount)
|
||||
self._cleanup.register(self)
|
||||
if _startcount == 1: # only import 'py' on the "client" side
|
||||
from py._com import PluginAPI
|
||||
self.api = PluginAPI(ExecnetAPI)
|
||||
from py._com import Hooks
|
||||
self.hook = Hooks(ExecnetAPI)
|
||||
else:
|
||||
self.api = ExecnetAPI()
|
||||
self.hook = ExecnetAPI()
|
||||
|
||||
def _initreceive(self, requestqueue=False):
|
||||
if requestqueue:
|
||||
|
@ -353,7 +353,7 @@ class Gateway(object):
|
|||
self._cleanup.unregister(self)
|
||||
self._stopexec()
|
||||
self._stopsend()
|
||||
self.api.pyexecnet_gateway_exit(gateway=self)
|
||||
self.hook.pyexecnet_gateway_exit(gateway=self)
|
||||
|
||||
def _remote_redirect(self, stdout=None, stderr=None):
|
||||
""" return a handle representing a redirection of a remote
|
||||
|
|
|
@ -21,7 +21,7 @@ class GatewayManager:
|
|||
if not spec.chdir and not spec.popen:
|
||||
spec.chdir = defaultchdir
|
||||
self.specs.append(spec)
|
||||
self.api = py._com.PluginAPI(py.execnet._API)
|
||||
self.hook = py._com.Hooks(py.execnet._HookSpecs)
|
||||
|
||||
def makegateways(self):
|
||||
assert not self.gateways
|
||||
|
@ -29,7 +29,7 @@ class GatewayManager:
|
|||
gw = py.execnet.makegateway(spec)
|
||||
self.gateways.append(gw)
|
||||
gw.id = "[%s]" % len(self.gateways)
|
||||
self.api.pyexecnet_gwmanage_newgateway(
|
||||
self.hook.pyexecnet_gwmanage_newgateway(
|
||||
gateway=gw, platinfo=gw._rinfo())
|
||||
|
||||
def getgateways(self, remote=True, inplacelocal=True):
|
||||
|
@ -75,12 +75,12 @@ class GatewayManager:
|
|||
rsync.add_target_host(gateway, finished=finished)
|
||||
seen[spec] = gateway
|
||||
if seen:
|
||||
self.api.pyexecnet_gwmanage_rsyncstart(
|
||||
self.hook.pyexecnet_gwmanage_rsyncstart(
|
||||
source=source,
|
||||
gateways=seen.values(),
|
||||
)
|
||||
rsync.send()
|
||||
self.api.pyexecnet_gwmanage_rsyncfinish(
|
||||
self.hook.pyexecnet_gwmanage_rsyncfinish(
|
||||
source=source,
|
||||
gateways=seen.values()
|
||||
)
|
||||
|
|
|
@ -40,7 +40,7 @@ class InstallableGateway(gateway.Gateway):
|
|||
super(InstallableGateway, self).__init__(io=io, _startcount=1)
|
||||
# XXX we dissallow execution form the other side
|
||||
self._initreceive(requestqueue=False)
|
||||
self.api.pyexecnet_gateway_init(gateway=self)
|
||||
self.hook.pyexecnet_gateway_init(gateway=self)
|
||||
|
||||
def _remote_bootstrap_gateway(self, io, extra=''):
|
||||
""" return Gateway with a asynchronously remotely
|
||||
|
|
|
@ -21,7 +21,7 @@ class TestGatewayManagerPopen:
|
|||
assert spec.chdir == "abc"
|
||||
|
||||
def test_popen_makegateway_events(self, _pytest):
|
||||
rec = _pytest.getcallrecorder(py.execnet._API)
|
||||
rec = _pytest.getcallrecorder(py.execnet._HookSpecs)
|
||||
hm = GatewayManager(["popen"] * 2)
|
||||
hm.makegateways()
|
||||
call = rec.popcall("pyexecnet_gwmanage_newgateway")
|
||||
|
@ -63,7 +63,7 @@ class TestGatewayManagerPopen:
|
|||
|
||||
def test_hostmanage_rsync_same_popen_twice(self, mysetup, _pytest):
|
||||
source, dest = mysetup.source, mysetup.dest
|
||||
rec = _pytest.getcallrecorder(py.execnet._API)
|
||||
rec = _pytest.getcallrecorder(py.execnet._HookSpecs)
|
||||
hm = GatewayManager(["popen//chdir=%s" %dest] * 2)
|
||||
hm.makegateways()
|
||||
source.ensure("dir1", "dir2", "hello")
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import py
|
||||
import os
|
||||
from py._com import Registry, MultiCall
|
||||
from py._com import PluginAPI
|
||||
from py._com import Hooks
|
||||
|
||||
pytest_plugins = "xfail"
|
||||
|
||||
|
@ -144,14 +144,14 @@ class TestRegistry:
|
|||
def test_api_and_defaults():
|
||||
assert isinstance(py._com.comregistry, Registry)
|
||||
|
||||
class TestPluginAPI:
|
||||
class TestHooks:
|
||||
def test_happypath(self):
|
||||
registry = Registry()
|
||||
class Api:
|
||||
def hello(self, arg):
|
||||
pass
|
||||
|
||||
mcm = PluginAPI(apiclass=Api, registry=registry)
|
||||
mcm = Hooks(hookspecs=Api, registry=registry)
|
||||
assert hasattr(mcm, 'hello')
|
||||
assert repr(mcm.hello).find("hello") != -1
|
||||
class Plugin:
|
||||
|
@ -167,7 +167,7 @@ class TestPluginAPI:
|
|||
class Api:
|
||||
def hello(self, arg):
|
||||
pass
|
||||
mcm = PluginAPI(apiclass=Api, registry=registry)
|
||||
mcm = Hooks(hookspecs=Api, registry=registry)
|
||||
excinfo = py.test.raises(TypeError, "mcm.hello(3)")
|
||||
assert str(excinfo.value).find("only keyword arguments") != -1
|
||||
assert str(excinfo.value).find("hello(self, arg)")
|
||||
|
@ -178,7 +178,7 @@ class TestPluginAPI:
|
|||
def hello(self, arg): pass
|
||||
hello.firstresult = True
|
||||
|
||||
mcm = PluginAPI(apiclass=Api, registry=registry)
|
||||
mcm = Hooks(hookspecs=Api, registry=registry)
|
||||
class Plugin:
|
||||
def hello(self, arg):
|
||||
return arg + 1
|
||||
|
@ -188,5 +188,5 @@ class TestPluginAPI:
|
|||
|
||||
def test_default_plugins(self):
|
||||
class Api: pass
|
||||
mcm = PluginAPI(apiclass=Api)
|
||||
mcm = Hooks(hookspecs=Api)
|
||||
assert mcm.registry == py._com.comregistry
|
||||
|
|
|
@ -409,14 +409,14 @@ class Directory(FSCollector):
|
|||
return res
|
||||
|
||||
def consider_file(self, path):
|
||||
return self.config.api.pytest_collect_file(path=path, parent=self)
|
||||
return self.config.hook.pytest_collect_file(path=path, parent=self)
|
||||
|
||||
def consider_dir(self, path, usefilters=None):
|
||||
if usefilters is not None:
|
||||
py.log._apiwarn("0.99", "usefilters argument not needed")
|
||||
res = self.config.api.pytest_collect_recurse(path=path, parent=self)
|
||||
res = self.config.hook.pytest_collect_recurse(path=path, parent=self)
|
||||
if res is None or res:
|
||||
return self.config.api.pytest_collect_directory(
|
||||
return self.config.hook.pytest_collect_directory(
|
||||
path=path, parent=self)
|
||||
|
||||
class Item(Node):
|
||||
|
|
|
@ -42,7 +42,7 @@ class Config(object):
|
|||
self.pluginmanager = pluginmanager
|
||||
self._conftest = Conftest(onimport=self._onimportconftest)
|
||||
self._setupstate = SetupState()
|
||||
self.api = pluginmanager.api
|
||||
self.hook = pluginmanager.hook
|
||||
|
||||
def _onimportconftest(self, conftestmodule):
|
||||
self.trace("loaded conftestmodule %r" %(conftestmodule,))
|
||||
|
@ -50,7 +50,7 @@ class Config(object):
|
|||
|
||||
def trace(self, msg):
|
||||
if getattr(self.option, 'traceconfig', None):
|
||||
self.api.pytest_trace(category="config", msg=msg)
|
||||
self.hook.pytest_trace(category="config", msg=msg)
|
||||
|
||||
def _processopt(self, opt):
|
||||
if hasattr(opt, 'default') and opt.dest:
|
||||
|
|
|
@ -97,7 +97,7 @@ class DSession(Session):
|
|||
|
||||
callname, args, kwargs = eventcall
|
||||
if callname is not None:
|
||||
call = getattr(self.config.api, callname)
|
||||
call = getattr(self.config.hook, callname)
|
||||
assert not args
|
||||
call(**kwargs)
|
||||
|
||||
|
@ -114,7 +114,7 @@ class DSession(Session):
|
|||
# events other than HostDown upstream
|
||||
eventname, args, kwargs = self.queue.get()
|
||||
if eventname == "pytest_testnodedown":
|
||||
self.config.api.pytest_testnodedown(**kwargs)
|
||||
self.config.hook.pytest_testnodedown(**kwargs)
|
||||
self.removenode(kwargs['node'])
|
||||
if not self.node2pending:
|
||||
# finished
|
||||
|
@ -176,7 +176,7 @@ class DSession(Session):
|
|||
if isinstance(next, py.test.collect.Item):
|
||||
senditems.append(next)
|
||||
else:
|
||||
self.config.api.pytest_collectstart(collector=next)
|
||||
self.config.hook.pytest_collectstart(collector=next)
|
||||
self.queueevent("pytest_collectreport", rep=basic_collect_report(next))
|
||||
if self.config.option.dist == "each":
|
||||
self.senditems_each(senditems)
|
||||
|
@ -199,7 +199,7 @@ class DSession(Session):
|
|||
pending.extend(sending)
|
||||
for item in sending:
|
||||
self.item2nodes.setdefault(item, []).append(node)
|
||||
self.config.api.pytest_itemstart(item=item, node=node)
|
||||
self.config.hook.pytest_itemstart(item=item, node=node)
|
||||
tosend[:] = tosend[room:] # update inplace
|
||||
if tosend:
|
||||
# we have some left, give it to the main loop
|
||||
|
@ -218,7 +218,7 @@ class DSession(Session):
|
|||
# "sending same item %r to multiple "
|
||||
# "not implemented" %(item,))
|
||||
self.item2nodes.setdefault(item, []).append(node)
|
||||
self.config.api.pytest_itemstart(item=item, node=node)
|
||||
self.config.hook.pytest_itemstart(item=item, node=node)
|
||||
pending.extend(sending)
|
||||
tosend[:] = tosend[room:] # update inplace
|
||||
if not tosend:
|
||||
|
@ -241,7 +241,7 @@ class DSession(Session):
|
|||
longrepr = "!!! Node %r crashed during running of test %r" %(node, item)
|
||||
rep = ItemTestReport(item, when="???", excinfo=longrepr)
|
||||
rep.node = node
|
||||
self.config.api.pytest_itemtestreport(rep=rep)
|
||||
self.config.hook.pytest_itemtestreport(rep=rep)
|
||||
|
||||
def setup(self):
|
||||
""" setup any neccessary resources ahead of the test run. """
|
||||
|
|
|
@ -15,7 +15,7 @@ class NodeManager(object):
|
|||
self._nodesready = py.std.threading.Event()
|
||||
|
||||
def trace(self, msg):
|
||||
self.config.api.pytest_trace(category="nodemanage", msg=msg)
|
||||
self.config.hook.pytest_trace(category="nodemanage", msg=msg)
|
||||
|
||||
def config_getignores(self):
|
||||
return self.config.getconftest_pathlist("rsyncignore")
|
||||
|
|
|
@ -147,7 +147,7 @@ def slave_runsession(channel, config, fullwidth, hasmarkup):
|
|||
|
||||
DEBUG("SLAVE: starting session.main()")
|
||||
session.main(colitems)
|
||||
session.config.api.pytest_looponfailinfo(
|
||||
session.config.hook.pytest_looponfailinfo(
|
||||
failreports=list(failreports),
|
||||
rootdirs=[config.topdir])
|
||||
channel.send([x.colitem._totrail() for x in failreports])
|
||||
|
|
|
@ -8,11 +8,11 @@ class PytestArg:
|
|||
def __init__(self, request):
|
||||
self.request = request
|
||||
|
||||
def getcallrecorder(self, apiclass, comregistry=None):
|
||||
def getcallrecorder(self, hookspecs, comregistry=None):
|
||||
if comregistry is None:
|
||||
comregistry = self.request.config.pluginmanager.comregistry
|
||||
callrecorder = CallRecorder(comregistry)
|
||||
callrecorder.start_recording(apiclass)
|
||||
callrecorder.start_recording(hookspecs)
|
||||
self.request.addfinalizer(callrecorder.finalize)
|
||||
return callrecorder
|
||||
|
||||
|
@ -35,17 +35,17 @@ class CallRecorder:
|
|||
self.calls = []
|
||||
self._recorders = {}
|
||||
|
||||
def start_recording(self, apiclass):
|
||||
assert apiclass not in self._recorders
|
||||
def start_recording(self, hookspecs):
|
||||
assert hookspecs not in self._recorders
|
||||
class RecordCalls:
|
||||
_recorder = self
|
||||
for name, method in vars(apiclass).items():
|
||||
for name, method in vars(hookspecs).items():
|
||||
if name[0] != "_":
|
||||
setattr(RecordCalls, name, self._getcallparser(method))
|
||||
recorder = RecordCalls()
|
||||
self._recorders[apiclass] = recorder
|
||||
self._recorders[hookspecs] = recorder
|
||||
self._comregistry.register(recorder)
|
||||
self.api = py._com.PluginAPI(apiclass, registry=self._comregistry)
|
||||
self.hook = py._com.Hooks(hookspecs, registry=self._comregistry)
|
||||
|
||||
def finalize(self):
|
||||
for recorder in self._recorders.values():
|
||||
|
@ -53,8 +53,8 @@ class CallRecorder:
|
|||
self._recorders.clear()
|
||||
|
||||
def recordsmethod(self, name):
|
||||
for apiclass in self._recorders:
|
||||
if hasattr(apiclass, name):
|
||||
for hookspecs in self._recorders:
|
||||
if hasattr(hookspecs, name):
|
||||
return True
|
||||
|
||||
def _getcallparser(self, method):
|
||||
|
@ -97,7 +97,7 @@ class CallRecorder:
|
|||
return l
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(_pytestPlugin)
|
||||
plugintester.hookcheck(_pytestPlugin)
|
||||
|
||||
def test_callrecorder_basic():
|
||||
comregistry = py._com.Registry()
|
||||
|
@ -106,7 +106,7 @@ def test_callrecorder_basic():
|
|||
def xyz(self, arg):
|
||||
pass
|
||||
rec.start_recording(ApiClass)
|
||||
rec.api.xyz(arg=123)
|
||||
rec.hook.xyz(arg=123)
|
||||
call = rec.popcall("xyz")
|
||||
assert call.arg == 123
|
||||
assert call._name == "xyz"
|
||||
|
@ -124,7 +124,7 @@ def test_functional(testdir, linecomp):
|
|||
def xyz(self, arg):
|
||||
return arg + 1
|
||||
rec._comregistry.register(Plugin())
|
||||
res = rec.api.xyz(arg=41)
|
||||
res = rec.hook.xyz(arg=41)
|
||||
assert res == [42]
|
||||
""")
|
||||
sorter.assertoutcome(passed=1)
|
||||
|
|
|
@ -10,7 +10,7 @@ class DefaultPlugin:
|
|||
else:
|
||||
runner = basic_run_report
|
||||
report = runner(item, pdb=pdb)
|
||||
item.config.api.pytest_itemtestreport(rep=report)
|
||||
item.config.hook.pytest_itemtestreport(rep=report)
|
||||
return True
|
||||
|
||||
def pytest_item_makereport(self, item, excinfo, when, outerr):
|
||||
|
@ -20,7 +20,7 @@ class DefaultPlugin:
|
|||
def pytest_item_runtest_finished(self, item, excinfo, outerr):
|
||||
from py.__.test import runner
|
||||
rep = runner.ItemTestReport(item, excinfo, "execute", outerr)
|
||||
item.config.api.pytest_itemtestreport(rep=rep)
|
||||
item.config.hook.pytest_itemtestreport(rep=rep)
|
||||
|
||||
def pytest_pyfunc_call(self, pyfuncitem, args, kwargs):
|
||||
pyfuncitem.obj(*args, **kwargs)
|
||||
|
@ -187,7 +187,7 @@ def test_implied_different_sessions(tmpdir):
|
|||
assert x('-f') == 'LooponfailingSession'
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(DefaultPlugin)
|
||||
plugintester.hookcheck(DefaultPlugin)
|
||||
|
||||
def test_plugin_specify(testdir):
|
||||
testdir.chdir()
|
||||
|
|
|
@ -162,5 +162,5 @@ class TestDoctests:
|
|||
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(DoctestPlugin)
|
||||
plugintester.hookcheck(DoctestPlugin)
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class EventlogPlugin:
|
|||
|
||||
@py.test.mark.xfail
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(EventlogPlugin)
|
||||
plugintester.hookcheck(EventlogPlugin)
|
||||
|
||||
testdir = plugintester.testdir()
|
||||
testdir.makepyfile("""
|
||||
|
|
|
@ -43,7 +43,7 @@ class ExecnetcleanupPlugin:
|
|||
return res
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(ExecnetcleanupPlugin)
|
||||
plugintester.hookcheck(ExecnetcleanupPlugin)
|
||||
|
||||
@py.test.mark.xfail("clarify plugin registration/unregistration")
|
||||
def test_execnetplugin(testdir):
|
||||
|
|
|
@ -55,7 +55,7 @@ class FigleafPlugin:
|
|||
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(FigleafPlugin)
|
||||
plugintester.hookcheck(FigleafPlugin)
|
||||
|
||||
def test_functional(testdir):
|
||||
py.test.importorskip("figleaf")
|
||||
|
|
|
@ -26,7 +26,7 @@ class Capture:
|
|||
return res
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(IocapturePlugin)
|
||||
plugintester.hookcheck(IocapturePlugin)
|
||||
|
||||
class TestCapture:
|
||||
def test_std_functional(self, testdir):
|
||||
|
|
|
@ -25,7 +25,7 @@ class PluginTester:
|
|||
# break
|
||||
return crunner
|
||||
|
||||
def apicheck(self, pluginclass):
|
||||
def hookcheck(self, pluginclass):
|
||||
print "loading and checking", pluginclass
|
||||
fail = False
|
||||
pm = py.test._PluginManager()
|
||||
|
@ -84,4 +84,4 @@ def formatdef(func):
|
|||
# ===============================================================================
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(PlugintesterPlugin)
|
||||
plugintester.hookcheck(PlugintesterPlugin)
|
||||
|
|
|
@ -41,7 +41,7 @@ class PocooPlugin:
|
|||
|
||||
|
||||
def test_apicheck(plugintester):
|
||||
plugintester.apicheck(PocooPlugin)
|
||||
plugintester.hookcheck(PocooPlugin)
|
||||
|
||||
def test_toproxy(testdir, monkeypatch):
|
||||
l = []
|
||||
|
|
|
@ -51,7 +51,7 @@ class PylintItem(py.test.collect.Item):
|
|||
print rating
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(PylintPlugin)
|
||||
plugintester.hookcheck(PylintPlugin)
|
||||
|
||||
#def test_functional <pull from figleaf plugin>
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class PytesterPlugin:
|
|||
return evrec
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(PytesterPlugin)
|
||||
plugintester.hookcheck(PytesterPlugin)
|
||||
|
||||
class RunResult:
|
||||
def __init__(self, ret, outlines, errlines):
|
||||
|
@ -78,7 +78,7 @@ class TmpTestdir:
|
|||
sorter = EventRecorder(registry)
|
||||
sorter.callrecorder = CallRecorder(registry)
|
||||
sorter.callrecorder.start_recording(api.PluginHooks)
|
||||
sorter.api = sorter.callrecorder.api
|
||||
sorter.hook = sorter.callrecorder.hook
|
||||
self.request.addfinalizer(sorter.callrecorder.finalize)
|
||||
return sorter
|
||||
|
||||
|
@ -385,7 +385,7 @@ def test_eventrecorder(testdir):
|
|||
rep = runner.ItemTestReport(None, None)
|
||||
rep.passed = False
|
||||
rep.failed = True
|
||||
recorder.api.pytest_itemtestreport(rep=rep)
|
||||
recorder.hook.pytest_itemtestreport(rep=rep)
|
||||
failures = recorder.getfailures()
|
||||
assert failures == [rep]
|
||||
failures = recorder.getfailures()
|
||||
|
@ -394,12 +394,12 @@ def test_eventrecorder(testdir):
|
|||
rep = runner.ItemTestReport(None, None)
|
||||
rep.passed = False
|
||||
rep.skipped = True
|
||||
recorder.api.pytest_itemtestreport(rep=rep)
|
||||
recorder.hook.pytest_itemtestreport(rep=rep)
|
||||
|
||||
rep = runner.CollectReport(None, None)
|
||||
rep.passed = False
|
||||
rep.failed = True
|
||||
recorder.api.pytest_itemtestreport(rep=rep)
|
||||
recorder.hook.pytest_itemtestreport(rep=rep)
|
||||
|
||||
passed, skipped, failed = recorder.listoutcomes()
|
||||
assert not passed and skipped and failed
|
||||
|
@ -412,7 +412,7 @@ def test_eventrecorder(testdir):
|
|||
recorder.unregister()
|
||||
recorder.clear()
|
||||
assert not recorder.getfailures()
|
||||
recorder.api.pytest_itemtestreport(rep=rep)
|
||||
recorder.hook.pytest_itemtestreport(rep=rep)
|
||||
assert not recorder.getfailures()
|
||||
|
||||
class LineComp:
|
||||
|
|
|
@ -142,7 +142,7 @@ class ReSTSyntaxTest(py.test.collect.Item):
|
|||
directives.register_directive('sourcecode', pygments_directive)
|
||||
|
||||
def resolve_linkrole(self, name, text, check=True):
|
||||
apigen_relpath = self.project.apigen_relpath
|
||||
apigen_relpath = self.project.hookgen_relpath
|
||||
|
||||
if name == 'api':
|
||||
if text == 'py':
|
||||
|
@ -201,7 +201,7 @@ class DoctestText(py.test.collect.Item):
|
|||
|
||||
def runtest(self):
|
||||
content = self._normalize_linesep()
|
||||
newcontent = self.config.api.pytest_doctest_prepare_content(content=content)
|
||||
newcontent = self.config.hook.pytest_doctest_prepare_content(content=content)
|
||||
if newcontent is not None:
|
||||
content = newcontent
|
||||
s = content
|
||||
|
@ -346,7 +346,7 @@ def localrefcheck(tryfn, path, lineno):
|
|||
# PLUGIN tests
|
||||
#
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(RestdocPlugin)
|
||||
plugintester.hookcheck(RestdocPlugin)
|
||||
|
||||
def test_deindent():
|
||||
assert deindent('foo') == 'foo'
|
||||
|
|
|
@ -365,7 +365,7 @@ class TestWithFunctionIntegration:
|
|||
assert 'ValueError' in entry
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(ResultdbPlugin)
|
||||
plugintester.hookcheck(ResultdbPlugin)
|
||||
testdir = plugintester.testdir()
|
||||
testdir.makepyfile("""
|
||||
import py
|
||||
|
|
|
@ -224,7 +224,7 @@ class TestWithFunctionIntegration:
|
|||
assert 'ValueError' in entry
|
||||
|
||||
def test_generic(plugintester, LineMatcher):
|
||||
plugintester.apicheck(ResultlogPlugin)
|
||||
plugintester.hookcheck(ResultlogPlugin)
|
||||
testdir = plugintester.testdir()
|
||||
testdir.plugins.append("resultlog")
|
||||
testdir.makepyfile("""
|
||||
|
|
|
@ -13,15 +13,15 @@ class RunnerPlugin:
|
|||
call = item.config.guardedcall(lambda: setupstate.prepare(item))
|
||||
if call.excinfo:
|
||||
rep = ItemSetupReport(item, call.excinfo, call.outerr)
|
||||
item.config.api.pytest_itemsetupreport(rep=rep)
|
||||
item.config.hook.pytest_itemsetupreport(rep=rep)
|
||||
else:
|
||||
call = item.config.guardedcall(lambda: item.runtest())
|
||||
item.config.api.pytest_item_runtest_finished(
|
||||
item.config.hook.pytest_item_runtest_finished(
|
||||
item=item, excinfo=call.excinfo, outerr=call.outerr)
|
||||
call = item.config.guardedcall(lambda: self.teardown_exact(item))
|
||||
if call.excinfo:
|
||||
rep = ItemSetupReport(item, call.excinfo, call.outerr)
|
||||
item.config.api.pytest_itemsetupreport(rep=rep)
|
||||
item.config.hook.pytest_itemsetupreport(rep=rep)
|
||||
|
||||
def pytest_collector_collect(self, collector):
|
||||
call = item.config.guardedcall(lambda x: collector._memocollect())
|
||||
|
@ -146,7 +146,7 @@ class SetupState(object):
|
|||
# ===============================================================================
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(RunnerPlugin())
|
||||
plugintester.hookcheck(RunnerPlugin())
|
||||
|
||||
class TestSetupState:
|
||||
def test_setup_prepare(self, testdir):
|
||||
|
|
|
@ -61,7 +61,7 @@ class TerminalReporter:
|
|||
self._tw.sep(sep, title, **markup)
|
||||
|
||||
def getcategoryletterword(self, rep):
|
||||
res = self.config.api.pytest_report_teststatus(rep=rep)
|
||||
res = self.config.hook.pytest_report_teststatus(rep=rep)
|
||||
if res:
|
||||
return res
|
||||
for cat in 'skipped failed passed ???'.split():
|
||||
|
@ -228,7 +228,7 @@ class TerminalReporter:
|
|||
if exitstatus in (0, 1, 2):
|
||||
self.summary_failures()
|
||||
self.summary_skips()
|
||||
self.config.api.pytest_terminal_summary(terminalreporter=self)
|
||||
self.config.hook.pytest_terminal_summary(terminalreporter=self)
|
||||
if excrepr is not None:
|
||||
self.summary_final_exc(excrepr)
|
||||
if exitstatus == 2:
|
||||
|
@ -389,15 +389,15 @@ class TestTerminal:
|
|||
""")
|
||||
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
||||
rep.config.pluginmanager.register(rep)
|
||||
rep.config.api.pytest_testrunstart()
|
||||
rep.config.hook.pytest_testrunstart()
|
||||
|
||||
for item in testdir.genitems([modcol]):
|
||||
ev = runner.basic_run_report(item)
|
||||
rep.config.api.pytest_itemtestreport(rep=ev)
|
||||
rep.config.hook.pytest_itemtestreport(rep=ev)
|
||||
linecomp.assert_contains_lines([
|
||||
"*test_pass_skip_fail.py .sF"
|
||||
])
|
||||
rep.config.api.pytest_testrunfinish(exitstatus=1)
|
||||
rep.config.hook.pytest_testrunfinish(exitstatus=1)
|
||||
linecomp.assert_contains_lines([
|
||||
" def test_func():",
|
||||
"> assert 0",
|
||||
|
@ -416,21 +416,21 @@ class TestTerminal:
|
|||
""", configargs=("-v",))
|
||||
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
||||
rep.config.pluginmanager.register(rep)
|
||||
rep.config.api.pytest_testrunstart()
|
||||
rep.config.hook.pytest_testrunstart()
|
||||
items = modcol.collect()
|
||||
rep.config.option.debug = True #
|
||||
for item in items:
|
||||
rep.config.api.pytest_itemstart(item=item, node=None)
|
||||
rep.config.hook.pytest_itemstart(item=item, node=None)
|
||||
s = linecomp.stringio.getvalue().strip()
|
||||
assert s.endswith(item.name)
|
||||
rep.config.api.pytest_itemtestreport(rep=runner.basic_run_report(item))
|
||||
rep.config.hook.pytest_itemtestreport(rep=runner.basic_run_report(item))
|
||||
|
||||
linecomp.assert_contains_lines([
|
||||
"*test_pass_skip_fail_verbose.py:2: *test_ok*PASS*",
|
||||
"*test_pass_skip_fail_verbose.py:4: *test_skip*SKIP*",
|
||||
"*test_pass_skip_fail_verbose.py:6: *test_func*FAIL*",
|
||||
])
|
||||
rep.config.api.pytest_testrunfinish(exitstatus=1)
|
||||
rep.config.hook.pytest_testrunfinish(exitstatus=1)
|
||||
linecomp.assert_contains_lines([
|
||||
" def test_func():",
|
||||
"> assert 0",
|
||||
|
@ -441,13 +441,13 @@ class TestTerminal:
|
|||
modcol = testdir.getmodulecol("import xyz")
|
||||
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
||||
rep.config.pluginmanager.register(rep)
|
||||
rep.config.api.pytest_testrunstart()
|
||||
rep.config.hook.pytest_testrunstart()
|
||||
l = list(testdir.genitems([modcol]))
|
||||
assert len(l) == 0
|
||||
linecomp.assert_contains_lines([
|
||||
"*test_collect_fail.py F*"
|
||||
])
|
||||
rep.config.api.pytest_testrunfinish(exitstatus=1)
|
||||
rep.config.hook.pytest_testrunfinish(exitstatus=1)
|
||||
linecomp.assert_contains_lines([
|
||||
"> import xyz",
|
||||
"E ImportError: No module named xyz"
|
||||
|
@ -537,11 +537,11 @@ class TestTerminal:
|
|||
""", configargs=("--tb=%s" % tbopt,))
|
||||
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
||||
rep.config.pluginmanager.register(rep)
|
||||
rep.config.api.pytest_testrunstart()
|
||||
rep.config.hook.pytest_testrunstart()
|
||||
for item in testdir.genitems([modcol]):
|
||||
rep.config.api.pytest_itemtestreport(
|
||||
rep.config.hook.pytest_itemtestreport(
|
||||
rep=runner.basic_run_report(item))
|
||||
rep.config.api.pytest_testrunfinish(exitstatus=1)
|
||||
rep.config.hook.pytest_testrunfinish(exitstatus=1)
|
||||
s = linecomp.stringio.getvalue()
|
||||
if tbopt == "long":
|
||||
print s
|
||||
|
@ -561,7 +561,7 @@ class TestTerminal:
|
|||
item = testdir.getitem("def test_func(): pass")
|
||||
rep = TerminalReporter(item.config, file=linecomp.stringio)
|
||||
item.config.pluginmanager.register(rep)
|
||||
rep.config.api.pytest_itemstart(item=item)
|
||||
rep.config.hook.pytest_itemstart(item=item)
|
||||
linecomp.assert_contains_lines([
|
||||
"*test_show_path_before_running_test.py*"
|
||||
])
|
||||
|
@ -578,10 +578,10 @@ class TestTerminal:
|
|||
#""", configargs=("--showskipsummary",) + ("-v",)*verbose)
|
||||
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
||||
modcol.config.pluginmanager.register(rep)
|
||||
modcol.config.api.pytest_testrunstart()
|
||||
modcol.config.hook.pytest_testrunstart()
|
||||
try:
|
||||
for item in testdir.genitems([modcol]):
|
||||
modcol.config.api.pytest_itemtestreport(
|
||||
modcol.config.hook.pytest_itemtestreport(
|
||||
rep=runner.basic_run_report(item))
|
||||
except KeyboardInterrupt:
|
||||
excinfo = py.code.ExceptionInfo()
|
||||
|
@ -590,7 +590,7 @@ class TestTerminal:
|
|||
s = linecomp.stringio.getvalue()
|
||||
if not verbose:
|
||||
assert s.find("_keyboard_interrupt.py Fs") != -1
|
||||
modcol.config.api.pytest_testrunfinish(exitstatus=2, excrepr=excinfo.getrepr())
|
||||
modcol.config.hook.pytest_testrunfinish(exitstatus=2, excrepr=excinfo.getrepr())
|
||||
text = linecomp.stringio.getvalue()
|
||||
linecomp.assert_contains_lines([
|
||||
" def test_foobar():",
|
||||
|
@ -640,16 +640,16 @@ class TestCollectonly:
|
|||
rep = CollectonlyReporter(modcol.config, out=linecomp.stringio)
|
||||
modcol.config.pluginmanager.register(rep)
|
||||
indent = rep.indent
|
||||
rep.config.api.pytest_collectstart(collector=modcol)
|
||||
rep.config.hook.pytest_collectstart(collector=modcol)
|
||||
linecomp.assert_contains_lines([
|
||||
"<Module 'test_collectonly_basic.py'>"
|
||||
])
|
||||
item = modcol.join("test_func")
|
||||
rep.config.api.pytest_itemstart(item=item)
|
||||
rep.config.hook.pytest_itemstart(item=item)
|
||||
linecomp.assert_contains_lines([
|
||||
" <Function 'test_func'>",
|
||||
])
|
||||
rep.config.api.pytest_collectreport(
|
||||
rep.config.hook.pytest_collectreport(
|
||||
rep=runner.CollectReport(modcol, [], excinfo=None))
|
||||
assert rep.indent == indent
|
||||
|
||||
|
@ -687,6 +687,6 @@ def test_repr_python_version(monkeypatch):
|
|||
assert repr_pythonversion() == str(x)
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(TerminalPlugin)
|
||||
plugintester.apicheck(TerminalReporter)
|
||||
plugintester.apicheck(CollectonlyReporter)
|
||||
plugintester.hookcheck(TerminalPlugin)
|
||||
plugintester.hookcheck(TerminalReporter)
|
||||
plugintester.hookcheck(CollectonlyReporter)
|
||||
|
|
|
@ -24,7 +24,7 @@ class TmpdirPlugin:
|
|||
# ===============================================================================
|
||||
#
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(TmpdirPlugin)
|
||||
plugintester.hookcheck(TmpdirPlugin)
|
||||
|
||||
def test_funcarg(testdir):
|
||||
item = testdir.getitem("def test_func(tmpdir): pass")
|
||||
|
|
|
@ -71,7 +71,7 @@ class UnitTestFunction(py.test.collect.Function):
|
|||
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(UnittestPlugin)
|
||||
plugintester.hookcheck(UnittestPlugin)
|
||||
|
||||
def test_simple_unittest(testdir):
|
||||
testpath = testdir.makepyfile("""
|
||||
|
|
|
@ -57,7 +57,7 @@ class XfailPlugin(object):
|
|||
# ===============================================================================
|
||||
|
||||
def test_generic(plugintester):
|
||||
plugintester.apicheck(XfailPlugin)
|
||||
plugintester.hookcheck(XfailPlugin)
|
||||
|
||||
def test_xfail(plugintester, linecomp):
|
||||
testdir = plugintester.testdir()
|
||||
|
|
|
@ -12,17 +12,17 @@ class PluginManager(object):
|
|||
self.MultiCall = self.comregistry.MultiCall
|
||||
self.impname2plugin = {}
|
||||
|
||||
self.api = py._com.PluginAPI(
|
||||
apiclass=api.PluginHooks,
|
||||
self.hook = py._com.Hooks(
|
||||
hookspecs=api.PluginHooks,
|
||||
registry=self.comregistry)
|
||||
|
||||
def register(self, plugin):
|
||||
self.api.pytest_plugin_registered(plugin=plugin)
|
||||
self.hook.pytest_plugin_registered(plugin=plugin)
|
||||
import types
|
||||
self.comregistry.register(plugin)
|
||||
|
||||
def unregister(self, plugin):
|
||||
self.api.pytest_plugin_unregistered(plugin=plugin)
|
||||
self.hook.pytest_plugin_unregistered(plugin=plugin)
|
||||
self.comregistry.unregister(plugin)
|
||||
|
||||
def isregistered(self, plugin):
|
||||
|
@ -95,7 +95,7 @@ class PluginManager(object):
|
|||
if excinfo is None:
|
||||
excinfo = py.code.ExceptionInfo()
|
||||
excrepr = excinfo.getrepr(funcargs=True, showlocals=True)
|
||||
return self.api.pytest_internalerror(excrepr=excrepr)
|
||||
return self.hook.pytest_internalerror(excrepr=excrepr)
|
||||
|
||||
def do_addoption(self, parser):
|
||||
methods = self.comregistry.listattr("pytest_addoption", reverse=True)
|
||||
|
@ -115,12 +115,12 @@ class PluginManager(object):
|
|||
assert not hasattr(self, '_config')
|
||||
config.pluginmanager.register(self)
|
||||
self._config = config
|
||||
config.api.pytest_configure(config=self._config)
|
||||
config.hook.pytest_configure(config=self._config)
|
||||
|
||||
def do_unconfigure(self, config):
|
||||
config = self._config
|
||||
del self._config
|
||||
config.api.pytest_unconfigure(config=config)
|
||||
config.hook.pytest_unconfigure(config=config)
|
||||
config.pluginmanager.unregister(self)
|
||||
|
||||
def do_itemrun(self, item, pdb=None):
|
||||
|
|
|
@ -135,7 +135,7 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
|
|||
return self.join(name)
|
||||
|
||||
def makeitem(self, name, obj):
|
||||
res = self.config.api.pytest_pymodule_makeitem(
|
||||
res = self.config.hook.pytest_pymodule_makeitem(
|
||||
modcol=self, name=name, obj=obj)
|
||||
if res:
|
||||
return res
|
||||
|
@ -345,7 +345,7 @@ class Function(FunctionMixin, py.test.collect.Item):
|
|||
|
||||
def runtest(self):
|
||||
""" execute the given test function. """
|
||||
self.config.api.pytest_pyfunc_call(pyfuncitem=self,
|
||||
self.config.hook.pytest_pyfunc_call(pyfuncitem=self,
|
||||
args=self._args, kwargs=self.funcargs)
|
||||
|
||||
def setup(self):
|
||||
|
|
|
@ -32,7 +32,7 @@ def basic_run_report(item, pdb=None):
|
|||
raise
|
||||
except:
|
||||
excinfo = py.code.ExceptionInfo()
|
||||
testrep = item.config.api.pytest_item_makereport(
|
||||
testrep = item.config.hook.pytest_item_makereport(
|
||||
item=item, excinfo=excinfo, when=when, outerr=outerr)
|
||||
if pdb and testrep.failed:
|
||||
tw = py.io.TerminalWriter()
|
||||
|
|
|
@ -37,16 +37,16 @@ class Session(object):
|
|||
if isinstance(next, Item):
|
||||
remaining = self.filteritems([next])
|
||||
if remaining:
|
||||
self.config.api.pytest_itemstart(item=next)
|
||||
self.config.hook.pytest_itemstart(item=next)
|
||||
yield next
|
||||
else:
|
||||
assert isinstance(next, Collector)
|
||||
self.config.api.pytest_collectstart(collector=next)
|
||||
self.config.hook.pytest_collectstart(collector=next)
|
||||
rep = basic_collect_report(next)
|
||||
if rep.passed:
|
||||
for x in self.genitems(rep.result, keywordexpr):
|
||||
yield x
|
||||
self.config.api.pytest_collectreport(rep=rep)
|
||||
self.config.hook.pytest_collectreport(rep=rep)
|
||||
if self.shouldstop:
|
||||
break
|
||||
|
||||
|
@ -66,7 +66,7 @@ class Session(object):
|
|||
continue
|
||||
remaining.append(colitem)
|
||||
if deselected:
|
||||
self.config.api.pytest_deselected(items=deselected)
|
||||
self.config.hook.pytest_deselected(items=deselected)
|
||||
if self.config.option.keyword.endswith(":"):
|
||||
self._nomatch = True
|
||||
return remaining
|
||||
|
@ -78,7 +78,7 @@ class Session(object):
|
|||
|
||||
def sessionstarts(self):
|
||||
""" setup any neccessary resources ahead of the test run. """
|
||||
self.config.api.pytest_testrunstart()
|
||||
self.config.hook.pytest_testrunstart()
|
||||
|
||||
def pytest_itemtestreport(self, rep):
|
||||
if rep.failed:
|
||||
|
@ -89,7 +89,7 @@ class Session(object):
|
|||
|
||||
def sessionfinishes(self, exitstatus=0, excinfo=None):
|
||||
""" teardown any resources after a test run. """
|
||||
self.config.api.pytest_testrunfinish(
|
||||
self.config.hook.pytest_testrunfinish(
|
||||
exitstatus=exitstatus,
|
||||
excrepr=excinfo and excinfo.getrepr() or None
|
||||
)
|
||||
|
|
|
@ -11,4 +11,4 @@ class TestPyfuncHooks:
|
|||
return True
|
||||
config.pluginmanager.register(MyPlugin1())
|
||||
config.pluginmanager.register(MyPlugin2())
|
||||
config.api.pytest_pyfunc_call(pyfuncitem=item)
|
||||
config.hook.pytest_pyfunc_call(pyfuncitem=item)
|
||||
|
|
|
@ -84,7 +84,7 @@ class TestBootstrapping:
|
|||
#syspath.prepend(aplugin.dirpath())
|
||||
py.std.sys.path.insert(0, str(aplugin.dirpath()))
|
||||
pluginmanager.consider_module(mod)
|
||||
call = sorter.getcall(pluginmanager.api.pytest_plugin_registered.name)
|
||||
call = sorter.getcall(pluginmanager.hook.pytest_plugin_registered.name)
|
||||
assert call.plugin.__class__.__name__ == "APlugin"
|
||||
|
||||
# check that it is not registered twice
|
||||
|
|
Loading…
Reference in New Issue