[py-svn] r34555 - in py/dist/py/test/rsession: . testing
fijal at codespeak.net
fijal at codespeak.net
Mon Nov 13 13:20:16 CET 2006
Author: fijal
Date: Mon Nov 13 13:20:13 2006
New Revision: 34555
Modified:
py/dist/py/test/rsession/box.py
py/dist/py/test/rsession/master.py
py/dist/py/test/rsession/rsession.py
py/dist/py/test/rsession/slave.py
py/dist/py/test/rsession/testing/test_boxing.py
py/dist/py/test/rsession/testing/test_master.py
py/dist/py/test/rsession/testing/test_rsession.py
py/dist/py/test/rsession/testing/test_slave.py
Log:
A lot of refactoring of SessionOptions. Now nice level should work.
Modified: py/dist/py/test/rsession/box.py
==============================================================================
--- py/dist/py/test/rsession/box.py (original)
+++ py/dist/py/test/rsession/box.py Mon Nov 13 13:20:13 2006
@@ -8,7 +8,7 @@
import sys
import marshal
-NICE_LEVEL = 0 # XXX make it a conftest option
+#NICE_LEVEL = 0 # XXX make it a conftest option
PYTESTSTDOUT = "pyteststdout"
PYTESTSTDERR = "pyteststderr"
@@ -55,12 +55,14 @@
self.PYTESTRETVAL = tempdir.join('retval')
self.PYTESTSTDOUT = tempdir.join('stdout')
self.PYTESTSTDERR = tempdir.join('stderr')
+
+ nice_level = py.test.remote.nice_level
pid = os.fork()
if pid:
self.parent()
else:
try:
- outcome = self.children()
+ outcome = self.children(nice_level)
except:
excinfo = py.code.ExceptionInfo()
print "Internal box error"
@@ -73,7 +75,7 @@
os._exit(0)
return pid
- def children(self):
+ def children(self, nice_level):
# right now we need to call a function, but first we need to
# map all IO that might happen
# make sure sys.stdout points to file descriptor one
@@ -88,8 +90,9 @@
os.dup2(fdstderr, 2)
retvalf = self.PYTESTRETVAL.open("w")
try:
- if NICE_LEVEL:
- os.nice(NICE_LEVEL)
+ from py.__.test.rsession.rsession import remote_options
+ if nice_level:
+ os.nice(nice_level)
retval = self.fun(*self.args, **self.kwargs)
retvalf.write(marshal.dumps(retval))
finally:
Modified: py/dist/py/test/rsession/master.py
==============================================================================
--- py/dist/py/test/rsession/master.py (original)
+++ py/dist/py/test/rsession/master.py Mon Nov 13 13:20:13 2006
@@ -43,7 +43,7 @@
break
waiter()
-def setup_slave(gateway, pkgpath, options={}):
+def setup_slave(gateway, pkgpath, options):
from py.__.test.rsession import slave
import os
ch = gateway.remote_exec(str(py.code.Source(slave.setup, "setup()")))
Modified: py/dist/py/test/rsession/rsession.py
==============================================================================
--- py/dist/py/test/rsession/rsession.py (original)
+++ py/dist/py/test/rsession/rsession.py Mon Nov 13 13:20:13 2006
@@ -30,12 +30,13 @@
self.d[item] = val
# XXX: Must be initialised somehow
-remote_options = RemoteOptions({'we_are_remote':False, 'exitfirst':False})
-
+remote_options = RemoteOptions({'we_are_remote':False})
+
class SessionOptions:
defaults = {
'max_tasks_per_node' : 15,
- 'runner_policy' : 'plain_runner'
+ 'runner_policy' : 'plain_runner',
+ 'nice_level' : 0,
}
config = None
@@ -51,6 +52,20 @@
def bind_config(self, config):
self.config = config
+ # copy to remote all options
+ for item, val in config.option.__dict__.items():
+ remote_options[item] = val
+ # as well as some options from us
+ try:
+ ses_opt = self.config.getinitialvalue('SessionOptions').__dict__
+ except ValueError:
+ ses_opt = self.defaults
+ for key in self.defaults:
+ try:
+ val = getattr(ses_opt, key)
+ except AttributeError:
+ val = self.defaults[key]
+ remote_options[key] = val
def __repr__(self):
return "<SessionOptions %s>" % self.config
@@ -173,11 +188,9 @@
except:
remotepython = None
- rem_options = RemoteOptions({})
- rem_options['nomagic'] = self.config.option.nomagic
- rem_options['exitfirst'] = self.config.option.exitfirst
+ session_options.bind_config(self.config)
nodes = init_hosts(reporter, sshhosts, directories, pkgdir,
- rsync_roots, remotepython, remote_options=rem_options.d,
+ rsync_roots, remotepython, remote_options=remote_options.d,
optimise_localhost=self.optimise_localhost)
reporter(report.RsyncFinished())
@@ -189,7 +202,6 @@
yield y
itemgenerator = itemgen()
- session_options.bind_config(self.config)
dispatch_loop(nodes, itemgenerator, checkfun)
teardown_hosts(reporter, [node.channel for node in nodes], nodes,
exitfirst=self.config.option.exitfirst)
Modified: py/dist/py/test/rsession/slave.py
==============================================================================
--- py/dist/py/test/rsession/slave.py (original)
+++ py/dist/py/test/rsession/slave.py Mon Nov 13 13:20:13 2006
@@ -64,9 +64,6 @@
nextitem = receive()
def setup():
- default_options = {'nomagic':False} # XXX should come from somewhere else
- # but I don't want to mess with conftest at this point
-
import os, sys
pkgdir = channel.receive() # path is ready
options = channel.receive() # options stuff, should be dictionary
@@ -76,9 +73,6 @@
sys.path.insert(0, basedir)
import py
options['we_are_remote'] = True
- for opt, val in default_options.items():
- if opt not in options:
- options[opt] = val
from py.__.test.rsession.rsession import RemoteOptions
py.test.remote = RemoteOptions(options)
# XXX the following assumes that py lib is there, a bit
Modified: py/dist/py/test/rsession/testing/test_boxing.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_boxing.py (original)
+++ py/dist/py/test/rsession/testing/test_boxing.py Mon Nov 13 13:20:13 2006
@@ -11,6 +11,10 @@
from py.__.test.rsession.testing import example2
from py.__.test.rsession.conftest import option
+def setup_module(mod):
+ from py.__.test.rsession.rsession import remote_options
+ remote_options['nice_level'] = 0
+
def test_basic_boxing():
# XXX: because we do not have option transfer
## if not hasattr(option, 'nocapture') or not option.nocapture:
Modified: py/dist/py/test/rsession/testing/test_master.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_master.py (original)
+++ py/dist/py/test/rsession/testing/test_master.py Mon Nov 13 13:20:13 2006
@@ -13,8 +13,13 @@
from py.__.test.rsession.outcome import ReprOutcome, Outcome
from py.__.test.rsession.testing.test_slave import funcpass_spec, funcfail_spec
from py.__.test.rsession import report
+from py.__.test.rsession.rsession import session_options, remote_options
def setup_module(mod):
+ # bind an empty config
+ config, args = py.test.Config.parse([])
+ session_options.bind_config(config)
+ #assert not remote_options.exitfirst
mod.pkgdir = py.path.local(py.__file__).dirpath()
class DummyChannel(object):
@@ -70,7 +75,7 @@
def test_slave_setup():
gw = py.execnet.PopenGateway()
- channel = setup_slave(gw, pkgdir)
+ channel = setup_slave(gw, pkgdir, remote_options.d)
channel.send(funcpass_spec)
output = ReprOutcome(channel.receive())
assert output.passed
@@ -90,7 +95,7 @@
def open_gw():
gw = py.execnet.PopenGateway()
- channel = setup_slave(gw, pkgdir)
+ channel = setup_slave(gw, pkgdir, remote_options.d)
mn = MasterNode(channel, simple_report)
return mn
Modified: py/dist/py/test/rsession/testing/test_rsession.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_rsession.py (original)
+++ py/dist/py/test/rsession/testing/test_rsession.py Mon Nov 13 13:20:13 2006
@@ -4,7 +4,8 @@
import py
from py.__.test.rsession import report
-from py.__.test.rsession.rsession import RSession, parse_directories
+from py.__.test.rsession.rsession import RSession, parse_directories,\
+ session_options, remote_options
from py.__.test.rsession.hostmanage import init_hosts, teardown_hosts
from py.__.test.rsession.testing.test_slave import funcfail_spec,\
funcpass_spec, funcskip_spec, funcprint_spec, funcprintfail_spec, \
@@ -185,8 +186,10 @@
setup_events = []
teardown_events = []
+ config, args = py.test.Config.parse([])
+ session_options.bind_config(config)
nodes = init_hosts(setup_events.append, hosts, 'pytesttest', pkgdir,
- rsync_roots=["py"], optimise_localhost=False, remote_options={'exitfirst':False})
+ rsync_roots=["py"], optimise_localhost=False, remote_options=remote_options.d)
teardown_hosts(teardown_events.append,
[node.channel for node in nodes], nodes)
@@ -209,8 +212,10 @@
hosts = ['localhost']
allevents = []
+ config, args = py.test.Config.parse([])
+ session_options.bind_config(config)
nodes = init_hosts(allevents.append, hosts, 'pytesttest', pkgdir,
- rsync_roots=["py"], optimise_localhost=False, remote_options={'exitfirst':False})
+ rsync_roots=["py"], optimise_localhost=False, remote_options=remote_options.d)
from py.__.test.rsession.testing.test_executor \
import ItemTestPassing, ItemTestFailing, ItemTestSkipping
@@ -248,8 +253,12 @@
"""
allevents = []
hosts = ['localhost']
+ config, args = py.test.Config.parse([])
+ session_options.bind_config(config)
+ d = remote_options.d.copy()
+ d['custom'] = 'custom'
nodes = init_hosts(allevents.append, hosts, 'pytesttest', pkgdir,
- rsync_roots=["py"], remote_options={'custom':'custom', 'exitfirst':False},
+ rsync_roots=["py"], remote_options=d,
optimise_localhost=False)
rootcol = py.test.collect.Directory(pkgdir.dirpath())
Modified: py/dist/py/test/rsession/testing/test_slave.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_slave.py (original)
+++ py/dist/py/test/rsession/testing/test_slave.py Mon Nov 13 13:20:13 2006
@@ -11,7 +11,10 @@
py.test.skip("rsession is unsupported on Windows.")
def setup_module(module):
+ from py.__.test.rsession.rsession import session_options
module.rootdir = py.path.local(py.__file__).dirpath().dirpath()
+ config, args = py.test.Config.parse([])
+ session_options.bind_config(config)
# ----------------------------------------------------------------------
# inlined testing functions used below
@@ -109,8 +112,7 @@
slave_main(q.pop, res.append, str(rootdir))
assert len(res) == 2
res_repr = [ReprOutcome(r) for r in res]
- assert (not res_repr[0].passed and res_repr[1].passed) or \
- (not res_repr[1].passed and res_repr[0].passed)
+ assert not res_repr[0].passed and res_repr[1].passed
def test_slave_run_different_stuff():
node = gettestnode()
@@ -127,7 +129,8 @@
if self.count == 0:
retval = str(tmp)
elif self.count == 1:
- retval = {}
+ from py.__.test.rsession.rsession import remote_options
+ retval = remote_options.d
else:
raise NotImplementedError("mora data")
self.count += 1
@@ -152,7 +155,8 @@
if self.count == 0:
retval = str(x.dirpath())
elif self.count == 1:
- retval = {}
+ from py.__.test.rsession.rsession import remote_options
+ retval = remote_options.d
else:
raise NotImplementedError("mora data")
self.count += 1
More information about the pytest-commit
mailing list