2007-01-24 22:24:01 +08:00
|
|
|
from __future__ import generators
|
|
|
|
import py
|
2007-01-28 21:25:03 +08:00
|
|
|
from py.__.test.session import Session
|
2007-02-03 20:14:46 +08:00
|
|
|
from py.__.test.terminal.out import getout
|
|
|
|
from py.__.test.outcome import Failed, Passed, Skipped
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
def checkpyfilechange(rootdir, statcache={}):
|
|
|
|
""" wait until project files are changed. """
|
|
|
|
def fil(p):
|
|
|
|
return p.ext in ('.py', '.c', '.h')
|
|
|
|
#fil = lambda x: x.check(fnmatch='*.py')
|
|
|
|
def rec(p):
|
|
|
|
return p.check(dotfile=0)
|
|
|
|
changed = False
|
|
|
|
for path in rootdir.visit(fil, rec):
|
|
|
|
oldstat = statcache.get(path, None)
|
|
|
|
try:
|
|
|
|
statcache[path] = curstat = path.stat()
|
|
|
|
except py.error.ENOENT:
|
|
|
|
if oldstat:
|
|
|
|
del statcache[path]
|
|
|
|
print "# WARN: race condition on", path
|
|
|
|
else:
|
|
|
|
if oldstat:
|
|
|
|
if oldstat.mtime != curstat.mtime or \
|
|
|
|
oldstat.size != curstat.size:
|
|
|
|
changed = True
|
|
|
|
print "# MODIFIED", path
|
|
|
|
else:
|
|
|
|
changed = True
|
|
|
|
return changed
|
|
|
|
|
|
|
|
def getfailureitems(failures):
|
|
|
|
l = []
|
|
|
|
for rootpath, names in failures:
|
|
|
|
root = py.path.local(rootpath)
|
|
|
|
if root.check(dir=1):
|
|
|
|
current = py.test.collect.Directory(root).Directory(root)
|
|
|
|
elif root.check(file=1):
|
|
|
|
current = py.test.collect.Module(root).Module(root)
|
|
|
|
# root is fspath of names[0] -> pop names[0]
|
|
|
|
# slicing works with empty lists
|
|
|
|
names = names[1:]
|
|
|
|
while names:
|
|
|
|
name = names.pop(0)
|
|
|
|
try:
|
|
|
|
current = current.join(name)
|
|
|
|
except NameError:
|
|
|
|
print "WARNING: could not find %s on %r" %(name, current)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
l.append(current)
|
|
|
|
return l
|
|
|
|
|
2007-01-28 21:25:03 +08:00
|
|
|
class RemoteTerminalSession(Session):
|
2007-01-25 00:46:46 +08:00
|
|
|
def __init__(self, config, file=None):
|
2007-01-28 21:25:03 +08:00
|
|
|
super(RemoteTerminalSession, self).__init__(config=config)
|
2007-01-25 00:46:46 +08:00
|
|
|
self._setexecutable()
|
|
|
|
if file is None:
|
|
|
|
file = py.std.sys.stdout
|
|
|
|
self._file = file
|
|
|
|
self.out = getout(file)
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-01-25 00:46:46 +08:00
|
|
|
def _setexecutable(self):
|
|
|
|
name = self.config.option.executable
|
|
|
|
if name is None:
|
|
|
|
executable = py.std.sys.executable
|
|
|
|
else:
|
|
|
|
executable = py.path.local.sysfind(name)
|
|
|
|
assert executable is not None, executable
|
|
|
|
self.executable = executable
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-01-25 00:46:46 +08:00
|
|
|
def main(self):
|
|
|
|
rootdir = self.config.topdir
|
|
|
|
wasfailing = False
|
|
|
|
failures = []
|
|
|
|
while 1:
|
|
|
|
if self.config.option.looponfailing and (failures or not wasfailing):
|
|
|
|
while not checkpyfilechange(rootdir):
|
2007-02-01 06:20:33 +08:00
|
|
|
py.std.time.sleep(4.4)
|
2007-01-25 00:46:46 +08:00
|
|
|
wasfailing = len(failures)
|
|
|
|
failures = self.run_remote_session(failures)
|
|
|
|
if not self.config.option.looponfailing:
|
|
|
|
break
|
|
|
|
print "#" * 60
|
|
|
|
print "# looponfailing: mode: %d failures args" % len(failures)
|
|
|
|
for root, names in failures:
|
|
|
|
name = "/".join(names) # XXX
|
|
|
|
print "Failure at: %r" % (name,)
|
|
|
|
print "# watching py files below %s" % rootdir
|
|
|
|
print "# ", "^" * len(str(rootdir))
|
|
|
|
return failures
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-01-28 02:41:39 +08:00
|
|
|
def _initslavegateway(self):
|
2007-01-25 00:46:46 +08:00
|
|
|
print "* opening PopenGateway: ", self.executable
|
2007-01-28 02:41:39 +08:00
|
|
|
topdir = self.config.topdir
|
|
|
|
return py.execnet.PopenGateway(self.executable), topdir
|
|
|
|
|
|
|
|
def run_remote_session(self, failures):
|
|
|
|
gw, topdir = self._initslavegateway()
|
2007-01-25 00:46:46 +08:00
|
|
|
channel = gw.remote_exec("""
|
|
|
|
from py.__.test.terminal.remote import slaverun_TerminalSession
|
|
|
|
slaverun_TerminalSession(channel)
|
|
|
|
""", stdout=self.out, stderr=self.out)
|
|
|
|
try:
|
2007-01-28 16:49:28 +08:00
|
|
|
print "MASTER: initiated slave terminal session ->"
|
2007-02-12 20:18:23 +08:00
|
|
|
repr = self.config._makerepr(conftestnames=[])
|
2007-01-28 16:49:28 +08:00
|
|
|
channel.send((str(topdir), repr, failures))
|
|
|
|
print "MASTER: send start info, topdir=%s" % (topdir,)
|
|
|
|
try:
|
|
|
|
return channel.receive()
|
|
|
|
except channel.RemoteError, e:
|
|
|
|
print "*" * 70
|
|
|
|
print "ERROR while waiting for proper slave startup"
|
|
|
|
print "*" * 70
|
|
|
|
print e
|
|
|
|
return []
|
|
|
|
finally:
|
|
|
|
gw.exit()
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-01-25 00:46:46 +08:00
|
|
|
def slaverun_TerminalSession(channel):
|
|
|
|
""" we run this on the other side. """
|
2007-01-28 02:41:39 +08:00
|
|
|
print "SLAVE: initializing ..."
|
2007-01-25 00:46:46 +08:00
|
|
|
topdir, repr, failures = channel.receive()
|
2007-01-28 02:41:39 +08:00
|
|
|
print "SLAVE: received configuration, using topdir:", topdir
|
2007-01-25 00:46:46 +08:00
|
|
|
config = py.test.config
|
2007-02-12 20:21:16 +08:00
|
|
|
config._initdirect(topdir, repr, failures)
|
2007-01-28 02:41:39 +08:00
|
|
|
config.option.session = None
|
2007-01-25 00:46:46 +08:00
|
|
|
config.option.looponfailing = False
|
|
|
|
config.option.usepdb = False
|
|
|
|
config.option.executable = None
|
2007-01-28 19:00:17 +08:00
|
|
|
if failures:
|
|
|
|
config.option.verbose = True
|
2007-01-25 00:46:46 +08:00
|
|
|
|
|
|
|
session = config.initsession()
|
|
|
|
session.shouldclose = channel.isclosed
|
|
|
|
print "SLAVE: starting session.main()"
|
|
|
|
session.main()
|
2007-02-03 20:14:46 +08:00
|
|
|
failures = session.getitemoutcomepairs(Failed)
|
2007-01-25 00:46:46 +08:00
|
|
|
failures = [config.get_collector_trail(item) for item,_ in failures]
|
|
|
|
channel.send(failures)
|