[svn r63887] move rest of events

--HG--
branch : trunk
This commit is contained in:
hpk 2009-04-09 02:12:10 +02:00
parent 2dd3ea7041
commit 0c4fc99a6f
14 changed files with 23 additions and 54 deletions

View File

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

View File

@ -15,7 +15,7 @@ class NodeManager(object):
self._nodesready = py.std.threading.Event()
def trace(self, msg):
self.config.bus.notify("trace", "nodemanage", msg)
self.config.api.pytest_trace(category="nodemanage", msg=msg)
def config_getignores(self):
return self.config.getconftest_pathlist("rsyncignore")

View File

@ -198,15 +198,6 @@ class TestDSession:
session.loop_once(loopstate)
assert len(session.node2pending) == 1
def test_event_propagation(self, testdir):
item = testdir.getitem("def test_func(): pass")
session = DSession(item.config)
evrec = testdir.geteventrecorder(session.bus)
session.queueevent("NOP", 42)
session.loop_once(session._initloopstate([]))
assert evrec.getcall('NOP')
def runthrough(self, item):
session = DSession(item.config)
node = MockNode()

View File

@ -104,11 +104,10 @@ class TestNodeManager:
config = py.test.config._reparse([source, '--debug'])
assert config.option.debug
nodemanager = NodeManager(config, specs)
sorter = testdir.geteventrecorder(config.bus)
sorter = testdir.geteventrecorder(config.bus).callrecorder
nodemanager.setup_nodes(putevent=[].append)
for spec in nodemanager.gwmanager.specs:
l = sorter.getcalls("trace")
print sorter.events
l = sorter.getcalls("pytest_trace")
assert l
nodemanager.teardown_nodes()

View File

@ -9,9 +9,6 @@ class EventQueue:
self.queue = queue
bus.register(self)
def pyevent(self, eventname, args, kwargs):
self.queue.put((eventname, args, kwargs))
def geteventargs(self, eventname, timeout=2.0):
events = []
while 1:
@ -30,7 +27,7 @@ class EventQueue:
return args
return kwargs
events.append(name)
if name == "internalerror":
if name == "pytest_internalerror":
print str(kwargs["excrepr"])
class MySetup:
@ -113,7 +110,7 @@ class TestMasterSlaveConnection:
node = mysetup.makenode(item.config)
node.channel.close()
py.test.raises(IOError, "node.send(item)")
#ev = self.getcalls("internalerror")
#ev = self.getcalls(pytest_internalerror)
#assert ev.excinfo.errisinstance(IOError)
def test_send_one(self, testdir, mysetup):

View File

@ -130,5 +130,5 @@ class SlaveNode(object):
raise
except:
er = py.code.ExceptionInfo().getrepr(funcargs=True, showlocals=True)
self.sendevent("internalerror", excrepr=er)
self.sendevent("pytest_internalerror", excrepr=er)
raise

View File

@ -113,19 +113,9 @@ class PluginHooks:
def pytest_looponfailinfo(self, failreports, rootdirs):
""" info for repeating failing tests. """
class Events:
# Events
def pyevent(self, eventname, args, kwargs):
""" generically called for each notification event. """
def pyevent__NOP(self, *args, **kwargs):
""" the no-operation call. """
def pyevent__trace(self, category, msg):
""" called for tracing events. """
def pyevent__internalerror(self, excrepr):
def pytest_internalerror(self, excrepr):
""" called for internal errors. """
def pytest_trace(self, category, msg):
""" called for tracing events. """

View File

@ -45,7 +45,6 @@ class PluginTester(Support):
pm = py.test._PytestPlugins()
methods = collectattr(pluginclass)
hooks = collectattr(api.PluginHooks)
hooks.update(collectattr(api.Events))
getargs = py.std.inspect.getargs
def isgenerichook(name):
@ -78,7 +77,7 @@ class PluginTester(Support):
if fail:
py.test.fail("Plugin API error")
def collectattr(obj, prefixes=("pytest_", "pyevent__")):
def collectattr(obj, prefixes=("pytest_",)):
methods = {}
for apiname in vars(obj):
for prefix in prefixes:

View File

@ -285,13 +285,6 @@ class EventRecorder(object):
self.debug = debug
pyplugins.register(self)
def pyevent(self, name, args, kwargs):
if name == "plugin_registered" and args == (self,):
return
if self.debug:
print "[event: %s]: %s **%s" %(name, ", ".join(map(str, args)), kwargs,)
self.events.append(Event(name, args, kwargs))
def popcall(self, name):
for i, event in py.builtin.enumerate(self.events):
if event.name == name:

View File

@ -349,7 +349,7 @@ class TestWithFunctionIntegration:
except ValueError:
excinfo = py.code.ExceptionInfo()
reslog = ResultDB(StringIO.StringIO())
reslog.pyevent__internalerror(excinfo.getrepr)
reslog.pytest_internalerror(excinfo.getrepr)
entry = reslog.logfile.getvalue()
entry_lines = entry.splitlines()

View File

@ -78,7 +78,7 @@ class ResultLog(object):
longrepr = str(rep.longrepr.reprcrash)
self.log_outcome(rep, code, longrepr)
def pyevent__internalerror(self, excrepr):
def pytest_internalerror(self, excrepr):
path = excrepr.reprcrash.path
self.write_log_entry(path, '!', str(excrepr))
@ -214,7 +214,7 @@ class TestWithFunctionIntegration:
except ValueError:
excinfo = py.code.ExceptionInfo()
reslog = ResultLog(StringIO.StringIO())
reslog.pyevent__internalerror(excinfo.getrepr())
reslog.pytest_internalerror(excinfo.getrepr())
entry = reslog.logfile.getvalue()
entry_lines = entry.splitlines()

View File

@ -82,7 +82,7 @@ class TerminalReporter:
else:
return "???", dict(red=True)
def pyevent__internalerror(self, excrepr):
def pytest_internalerror(self, excrepr):
for line in str(excrepr).split("\n"):
self.write_line("INTERNALERROR> " + line)
@ -131,7 +131,7 @@ class TerminalReporter:
if error:
self.write_line("%s node down, error: %s" %(node.gateway.id, error))
def pyevent__trace(self, category, msg):
def pytest_trace(self, category, msg):
if self.config.option.debug or \
self.config.option.traceconfig and category.find("config") != -1:
self.write_line("[%s] %s" %(category, msg))
@ -437,7 +437,7 @@ class TestTerminal:
modcol = testdir.getmodulecol("def test_one(): pass")
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
excinfo = py.test.raises(ValueError, "raise ValueError('hello')")
rep.pyevent__internalerror(excinfo.getrepr())
rep.pytest_internalerror(excinfo.getrepr())
linecomp.assert_contains_lines([
"INTERNALERROR> *raise ValueError*"
])

View File

@ -12,8 +12,8 @@ class PytestPlugins(object):
self.MultiCall = self.pyplugins.MultiCall
self._plugins = {}
def _getapi(self):
return py._com.PluginAPI(apiclass=api.PluginHooks,
self.api = py._com.PluginAPI(
apiclass=api.PluginHooks,
plugins=self.pyplugins)
def register(self, plugin):
@ -86,7 +86,7 @@ class PytestPlugins(object):
if excinfo is None:
excinfo = py.code.ExceptionInfo()
excrepr = excinfo.getrepr(funcargs=True, showlocals=True)
return self.notify("internalerror", excrepr=excrepr)
return self.api.pytest_internalerror(excrepr=excrepr)
def do_addoption(self, parser):
methods = self.pyplugins.listattr("pytest_addoption", reverse=True)

View File

@ -176,7 +176,7 @@ class TestPytestPluginInteractions:
class A:
def pytest_configure(self, config):
l.append(self)
def pyevent__hello(self, obj):
def xyz(self, obj):
events.append(obj)
config.bus.register(A())
@ -187,7 +187,7 @@ class TestPytestPluginInteractions:
assert len(l) == 2
assert l[0] != l[1]
config.bus.notify("hello", 42)
config.bus.call_each("xyz", obj=42)
assert len(events) == 2
assert events == [42,42]