rename "api" into "hook" in most places.

--HG--
branch : trunk
This commit is contained in:
holger krekel
2009-05-07 18:01:53 +02:00
parent 1f14aacbc2
commit 8182d341a5
37 changed files with 126 additions and 126 deletions
+12 -12
View File
@@ -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)
+3 -3
View File
@@ -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()
+1 -1
View File
@@ -162,5 +162,5 @@ class TestDoctests:
def test_generic(plugintester):
plugintester.apicheck(DoctestPlugin)
plugintester.hookcheck(DoctestPlugin)
+1 -1
View File
@@ -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("""
+1 -1
View File
@@ -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):
+1 -1
View File
@@ -55,7 +55,7 @@ class FigleafPlugin:
def test_generic(plugintester):
plugintester.apicheck(FigleafPlugin)
plugintester.hookcheck(FigleafPlugin)
def test_functional(testdir):
py.test.importorskip("figleaf")
+1 -1
View File
@@ -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):
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -41,7 +41,7 @@ class PocooPlugin:
def test_apicheck(plugintester):
plugintester.apicheck(PocooPlugin)
plugintester.hookcheck(PocooPlugin)
def test_toproxy(testdir, monkeypatch):
l = []
+1 -1
View File
@@ -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>
+6 -6
View File
@@ -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:
+3 -3
View File
@@ -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'
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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("""
+4 -4
View File
@@ -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):
+24 -24
View File
@@ -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)
+1 -1
View File
@@ -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")
+1 -1
View File
@@ -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("""
+1 -1
View File
@@ -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()