[svn r63808] * refinements/renames to new PluginAPI

* have pytest_runner start to use it, passes the main test

--HG--
branch : trunk
This commit is contained in:
hpk 2009-04-07 22:46:50 +02:00
parent 50664c1e17
commit f14fc582e9
8 changed files with 31 additions and 21 deletions

View File

@ -25,8 +25,8 @@ version = "1.0.0b1"
initpkg(__name__,
description = "pylib and py.test: agile development and test support library",
revision = int('$LastChangedRevision: 63806 $'.split(':')[1][:-1]),
lastchangedate = '$LastChangedDate: 2009-04-07 22:22:52 +0200 (Tue, 07 Apr 2009) $',
revision = int('$LastChangedRevision: 63808 $'.split(':')[1][:-1]),
lastchangedate = '$LastChangedDate: 2009-04-07 22:46:50 +0200 (Tue, 07 Apr 2009) $',
version = version,
url = "http://pylib.org",
download_url = "http://codespeak.net/py/%s/download.html" % version,
@ -57,7 +57,7 @@ initpkg(__name__,
'_com.PyPlugins' : ('./_com.py', 'PyPlugins'),
'_com.MultiCall' : ('./_com.py', 'MultiCall'),
'_com.pyplugins' : ('./_com.py', 'pyplugins'),
'_com.MultiAPI' : ('./_com.py', 'MultiAPI'),
'_com.PluginAPI' : ('./_com.py', 'PluginAPI'),
# py lib cmdline tools
'cmdline.pytest' : ('./cmdline/pytest.py', 'main',),

View File

@ -159,14 +159,16 @@ class PyPlugins:
MultiCall(self.listattr("pyevent"), eventname, args, kwargs).execute()
class MultiAPI:
def __init__(self, apiclass, plugins, prefix):
for fullname in vars(apiclass):
if fullname[:2] != "__":
assert fullname.startswith(prefix)
name = fullname[len(prefix):]
mm = CallMaker(plugins, fullname)
class PluginAPI:
def __init__(self, apiclass, plugins):
self._apiclass = apiclass
self._plugins = plugins
for name in vars(apiclass):
if name[:2] != "__":
mm = CallMaker(plugins, name)
setattr(self, name, mm)
def __repr__(self):
return "<PluginAPI %r %r>" %(self._apiclass, self._plugins)
class CallMaker:
def __init__(self, plugins, name):

View File

@ -2,7 +2,7 @@
import py
import os
from py._com import PyPlugins, MultiCall
from py._com import MultiAPI
from py._com import PluginAPI
pytest_plugins = "xfail"
@ -254,15 +254,14 @@ class TestMulticallMaker:
def test_happypath(self):
plugins = PyPlugins()
class Api:
def xyz_hello(self, arg):
def hello(self, arg):
pass
mcm = MultiAPI(apiclass=Api, plugins=plugins, prefix="xyz_")
mcm = PluginAPI(apiclass=Api, plugins=plugins)
assert hasattr(mcm, 'hello')
assert repr(mcm.hello).find("xyz_hello") != -1
assert not hasattr(mcm, 'xyz_hello')
assert repr(mcm.hello).find("hello") != -1
class Plugin:
def xyz_hello(self, arg):
def hello(self, arg):
return arg + 1
plugins.register(Plugin())
l = mcm.hello(3)

View File

@ -42,6 +42,7 @@ class Config(object):
self.pytestplugins = pytestplugins
self._conftest = Conftest(onimport=self._onimportconftest)
self._setupstate = SetupState()
self.api = pytestplugins._getapi()
def _onimportconftest(self, conftestmodule):
self.trace("loaded conftestmodule %r" %(conftestmodule,))

View File

@ -39,6 +39,10 @@ class PluginHooks:
def pytest_itemrun(self, item, pdb=None):
""" run given test item and return test report. """
def pytest_item_runtest_finished(self, item, excinfo, outerr):
""" called in-process after runtest() returned. """
# ------------------------------------------------------------------------------
# runtest related hooks
# ------------------------------------------------------------------------------

View File

@ -17,7 +17,7 @@ class DefaultPlugin:
from py.__.test import runner
return runner.ItemTestReport(item, excinfo, when, outerr)
def pyevent__item_runtest_finished(self, item, excinfo, outerr):
def pytest_item_runtest_finished(self, item, excinfo, outerr):
from py.__.test import runner
rep = runner.ItemTestReport(item, excinfo, "execute", outerr)
item.config.pytestplugins.notify("itemtestreport", rep)

View File

@ -1,4 +1,5 @@
import py
from outcome import Skipped
class RunnerPlugin:
def pytest_configure(self, config):
@ -15,7 +16,7 @@ class RunnerPlugin:
item.config.pytestplugins.notify("itemsetupreport", rep)
else:
call = item.config.guardedcall(lambda: item.runtest())
item.config.mc.pytest_item_runtest_finished(
item.config.api.pytest_item_runtest_finished(
item=item, excinfo=call.excinfo, outerr=call.outerr)
call = item.config.guardedcall(lambda: self.teardown_exact(item))
if call.excinfo:
@ -203,17 +204,15 @@ class TestSetupState:
assert not hasattr(item.parent.obj, 'x')
class TestRunnerPlugin:
disabled = True
def test_pytest_item_setup_and_runtest(self, testdir):
item = testdir.getitem("""def test_func(): pass""")
plugin = RunnerPlugin()
plugin.pytest_configure(item.config)
sorter = testdir.geteventrecorder(item.config)
plugin.pytest_item_setup_and_runtest(item)
rep = sorter.getreport("itemtestreport")
rep = sorter.getcall("itemtestreport").rep
assert rep.passed
class TestSetupEvents:
disabled = True

View File

@ -2,6 +2,7 @@
handling py.test plugins.
"""
import py
from py.__.test.plugin import api
class PytestPlugins(object):
def __init__(self, pyplugins=None):
@ -11,6 +12,10 @@ class PytestPlugins(object):
self.MultiCall = self.pyplugins.MultiCall
self._plugins = {}
def _getapi(self):
return py._com.PluginAPI(apiclass=api.PluginHooks,
plugins=self.pyplugins)
def register(self, plugin):
self.pyplugins.register(plugin)
def unregister(self, plugin):