[py-svn] r31569 - in py/branch/distributed/py/test/rsession: . testing
hpk at codespeak.net
hpk at codespeak.net
Wed Aug 23 18:47:58 CEST 2006
Author: hpk
Date: Wed Aug 23 18:47:54 2006
New Revision: 31569
Modified:
py/branch/distributed/py/test/rsession/master.py
py/branch/distributed/py/test/rsession/rsession.py
py/branch/distributed/py/test/rsession/slave.py
py/branch/distributed/py/test/rsession/testing/test_master.py
py/branch/distributed/py/test/rsession/testing/test_slave.py
Log:
(fijal, hpk) more unification towards pkgdir and adding tests and assertions about it.
Modified: py/branch/distributed/py/test/rsession/master.py
==============================================================================
--- py/branch/distributed/py/test/rsession/master.py (original)
+++ py/branch/distributed/py/test/rsession/master.py Wed Aug 23 18:47:54 2006
@@ -49,8 +49,8 @@
_rsync.sysexec("-az", "--delete", "--exclude=.svn",
str(source), sshaddress + ":" + str(destpath))
-def setup_slave(gateway, destpath):
+def setup_slave(gateway, pkgpath):
from py.__.test.rsession import slave
ch = gateway.remote_exec(py.code.Source(slave.setup, "setup()"))
- ch.send(str(destpath))
+ ch.send(str(pkgpath))
return ch
Modified: py/branch/distributed/py/test/rsession/rsession.py
==============================================================================
--- py/branch/distributed/py/test/rsession/rsession.py (original)
+++ py/branch/distributed/py/test/rsession/rsession.py Wed Aug 23 18:47:54 2006
@@ -2,6 +2,7 @@
""" Remote session base class
"""
+import os
import py
import thread
import threading
@@ -23,7 +24,7 @@
report.wrapcall(reporter, bin_rsync,
str(pkgdir.dirpath())+"/", host, relpath)
gw = py.execnet.SshGateway(host)
- ch = setup_slave(gw, relpath)
+ ch = setup_slave(gw, os.path.join(relpath, pkgdir.basename))
nodes_lock.acquire()
try:
nodes.append(MasterNode(ch, reporter))
Modified: py/branch/distributed/py/test/rsession/slave.py
==============================================================================
--- py/branch/distributed/py/test/rsession/slave.py (original)
+++ py/branch/distributed/py/test/rsession/slave.py Wed Aug 23 18:47:54 2006
@@ -38,9 +38,15 @@
send(res)
def setup():
- base_path = channel.receive() # path is ready
import os, sys
- base_path = os.path.abspath(base_path)
- sys.path.insert(0, base_path)
+ pkgdir = channel.receive() # path is ready
+ basedir = os.path.dirname(pkgdir)
+ pkgname = os.path.basename(pkgdir)
+ sys.path.insert(0, basedir)
+ import py
+ # XXX the following assumes that py lib is there, a bit
+ # much of an assumtion
+ mod = __import__(pkgname)
+ assert py.path.local(mod.__file__).dirpath() == py.path.local(pkgdir)
from py.__.test.rsession.slave import slave_main
- slave_main(channel.receive, channel.send, base_path)
+ slave_main(channel.receive, channel.send, basedir)
Modified: py/branch/distributed/py/test/rsession/testing/test_master.py
==============================================================================
--- py/branch/distributed/py/test/rsession/testing/test_master.py (original)
+++ py/branch/distributed/py/test/rsession/testing/test_master.py Wed Aug 23 18:47:54 2006
@@ -61,7 +61,7 @@
def test_slave_setup():
gw = py.execnet.PopenGateway()
- channel = setup_slave(gw, pkgdir.dirpath())
+ channel = setup_slave(gw, pkgdir)
channel.send(funcpass_spec)
output = ReprOutcome(channel.receive())
assert output.passed
@@ -81,7 +81,7 @@
def open_gw():
gw = py.execnet.PopenGateway()
- channel = setup_slave(gw, pkgdir.dirpath())
+ channel = setup_slave(gw, pkgdir)
mn = MasterNode(channel, simple_report)
return mn
Modified: py/branch/distributed/py/test/rsession/testing/test_slave.py
==============================================================================
--- py/branch/distributed/py/test/rsession/testing/test_slave.py (original)
+++ py/branch/distributed/py/test/rsession/testing/test_slave.py Wed Aug 23 18:47:54 2006
@@ -89,3 +89,43 @@
def test_slave_run_different_stuff():
node = gettestnode()
node.run("py documentation log.txt".split())
+
+def test_slave_setup_fails_on_import_error():
+ from py.__.test.rsession.slave import setup
+ tmp = py.test.ensuretemp("slavesetup")
+ class C:
+ def receive(self):
+ return str(tmp)
+ try:
+ exec py.code.Source(setup, "setup()").compile() in {
+ 'channel': C()}
+ except ImportError:
+ pass # expected
+ else:
+ py.test.fail("missing exception")
+
+def test_slave_setup_fails_on_missing_pkg():
+ from py.__.test.rsession.slave import setup
+ tmp = py.test.ensuretemp("slavesetup2")
+ x = tmp.ensure("sometestpackage", "__init__.py")
+ class C:
+ def receive(self):
+ return str(x.dirpath())
+ try:
+ exec py.code.Source(setup, "setup()").compile() in {'channel': C()}
+ except AttributeError: # channel.send
+ pass
+ else:
+ py.test.fail("missing exception")
+
+ # now create a parallel structure
+ tmp = py.test.ensuretemp("slavesetup3")
+ x = tmp.ensure("sometestpackage", "__init__.py")
+ try:
+ exec py.code.Source(setup, "setup()").compile() in {
+ 'channel': C()}
+ except AssertionError:
+ pass # expected
+ else:
+ py.test.fail("missing exception")
+
More information about the pytest-commit
mailing list