[svn r57548] * introduce py.process.ForkedFunc object (previously lived at

py.io and before that py.test)
* avoid deprecated py/misc/terminal_helper.py
* starting changelog for 1.0

--HG--
branch : trunk
This commit is contained in:
hpk 2008-08-21 14:12:20 +02:00
parent 3702ca2c71
commit d7f4dd3794
6 changed files with 28 additions and 18 deletions

View File

@ -1,4 +1,14 @@
$Id: CHANGELOG 57540 2008-08-21 10:18:58Z hpk $ $Id: CHANGELOG 57548 2008-08-21 12:12:20Z hpk $
Changes between 0.9.2 and 1.0 (UNRELEASED)
=============================================
* revised internal py.test architecture
* new py.process.ForkedFunc object allowing to
fork execution of a function to a sub process
and getting a result back.
XXX lots of things missing here XXX
Changes between 0.9.1 and 0.9.2 Changes between 0.9.1 and 0.9.2
=============================== ===============================

View File

@ -26,8 +26,8 @@ version = "1.0.0a1"
initpkg(__name__, initpkg(__name__,
description = "pylib and py.test: agile development and test support library", description = "pylib and py.test: agile development and test support library",
revision = int('$LastChangedRevision: 57540 $'.split(':')[1][:-1]), revision = int('$LastChangedRevision: 57548 $'.split(':')[1][:-1]),
lastchangedate = '$LastChangedDate: 2008-08-21 12:18:58 +0200 (Thu, 21 Aug 2008) $', lastchangedate = '$LastChangedDate: 2008-08-21 14:12:20 +0200 (Thu, 21 Aug 2008) $',
version = version, version = version,
url = "http://pylib.org", url = "http://pylib.org",
download_url = "http://codespeak.net/py/0.9.2/download.html", download_url = "http://codespeak.net/py/0.9.2/download.html",
@ -95,6 +95,7 @@ initpkg(__name__,
'process.__doc__' : ('./process/__init__.py', '__doc__'), 'process.__doc__' : ('./process/__init__.py', '__doc__'),
'process.cmdexec' : ('./process/cmdexec.py', 'cmdexec'), 'process.cmdexec' : ('./process/cmdexec.py', 'cmdexec'),
'process.ForkedFunc' : ('./process/forkedfunc.py', 'ForkedFunc'),
# path implementation # path implementation
'path.__doc__' : ('./path/__init__.py', '__doc__'), 'path.__doc__' : ('./path/__init__.py', '__doc__'),
@ -148,7 +149,6 @@ initpkg(__name__,
'io.StdCapture' : ('./io/stdcapture.py', 'StdCapture'), 'io.StdCapture' : ('./io/stdcapture.py', 'StdCapture'),
'io.StdCaptureFD' : ('./io/stdcapture.py', 'StdCaptureFD'), 'io.StdCaptureFD' : ('./io/stdcapture.py', 'StdCaptureFD'),
'io.TerminalWriter' : ('./io/terminalwriter.py', 'TerminalWriter'), 'io.TerminalWriter' : ('./io/terminalwriter.py', 'TerminalWriter'),
'io.ForkedFunc' : ('./io/forkedfunc.py', 'ForkedFunc'),
# error module, defining all errno's as Classes # error module, defining all errno's as Classes
'error' : ('./misc/error.py', 'error'), 'error' : ('./misc/error.py', 'error'),

View File

@ -9,7 +9,7 @@ prepended."""
import sys, os import sys, os
import py import py
from py.__.misc.terminal_helper import ansi_print, terminal_width from py.__.io.terminalwriter
import re import re
curdir = py.path.local() curdir = py.path.local()

View File

@ -6,20 +6,20 @@ def setup_module(mod):
mod.tmpdir = py.test.ensuretemp(mod.__file__) mod.tmpdir = py.test.ensuretemp(mod.__file__)
def test_waitfinish_removes_tempdir(): def test_waitfinish_removes_tempdir():
ff = py.io.ForkedFunc(boxf1) ff = py.process.ForkedFunc(boxf1)
assert ff.tempdir.check() assert ff.tempdir.check()
ff.waitfinish() ff.waitfinish()
assert not ff.tempdir.check() assert not ff.tempdir.check()
def test_tempdir_gets_gc_collected(): def test_tempdir_gets_gc_collected():
ff = py.io.ForkedFunc(boxf1) ff = py.process.ForkedFunc(boxf1)
assert ff.tempdir.check() assert ff.tempdir.check()
ff.__del__() ff.__del__()
assert not ff.tempdir.check() assert not ff.tempdir.check()
os.waitpid(ff.pid, 0) os.waitpid(ff.pid, 0)
def test_basic_forkedfunc(): def test_basic_forkedfunc():
result = py.io.ForkedFunc(boxf1).waitfinish() result = py.process.ForkedFunc(boxf1).waitfinish()
assert result.out == "some out\n" assert result.out == "some out\n"
assert result.err == "some err\n" assert result.err == "some err\n"
assert result.exitstatus == 0 assert result.exitstatus == 0
@ -29,7 +29,7 @@ def test_basic_forkedfunc():
def test_exitstatus(): def test_exitstatus():
def func(): def func():
os._exit(4) os._exit(4)
result = py.io.ForkedFunc(func).waitfinish() result = py.process.ForkedFunc(func).waitfinish()
assert result.exitstatus == 4 assert result.exitstatus == 4
assert result.signal == 0 assert result.signal == 0
assert not result.out assert not result.out
@ -38,7 +38,7 @@ def test_exitstatus():
def test_execption_in_func(): def test_execption_in_func():
def fun(): def fun():
raise ValueError(42) raise ValueError(42)
ff = py.io.ForkedFunc(fun) ff = py.process.ForkedFunc(fun)
result = ff.waitfinish() result = ff.waitfinish()
assert result.exitstatus == ff.EXITSTATUS_EXCEPTION assert result.exitstatus == ff.EXITSTATUS_EXCEPTION
assert result.err.find("ValueError: 42") != -1 assert result.err.find("ValueError: 42") != -1
@ -46,7 +46,7 @@ def test_execption_in_func():
assert not result.retval assert not result.retval
def test_forkedfunc_on_fds(): def test_forkedfunc_on_fds():
result = py.io.ForkedFunc(boxf2).waitfinish() result = py.process.ForkedFunc(boxf2).waitfinish()
assert result.out == "someout" assert result.out == "someout"
assert result.err == "someerr" assert result.err == "someerr"
assert result.exitstatus == 0 assert result.exitstatus == 0
@ -54,14 +54,14 @@ def test_forkedfunc_on_fds():
assert result.retval == 2 assert result.retval == 2
def test_forkedfunc_signal(): def test_forkedfunc_signal():
result = py.io.ForkedFunc(boxseg).waitfinish() result = py.process.ForkedFunc(boxseg).waitfinish()
assert result.retval is None assert result.retval is None
if py.std.sys.version_info < (2,4): if py.std.sys.version_info < (2,4):
py.test.skip("signal detection does not work with python prior 2.4") py.test.skip("signal detection does not work with python prior 2.4")
assert result.signal == 11 assert result.signal == 11
def test_forkedfunc_huge_data(): def test_forkedfunc_huge_data():
result = py.io.ForkedFunc(boxhuge).waitfinish() result = py.process.ForkedFunc(boxhuge).waitfinish()
assert result.out assert result.out
assert result.exitstatus == 0 assert result.exitstatus == 0
assert result.signal == 0 assert result.signal == 0
@ -70,7 +70,7 @@ def test_forkedfunc_huge_data():
def test_box_seq(): def test_box_seq():
# we run many boxes with huge data, just one after another # we run many boxes with huge data, just one after another
for i in xrange(50): for i in xrange(50):
result = py.io.ForkedFunc(boxhuge).waitfinish() result = py.process.ForkedFunc(boxhuge).waitfinish()
assert result.out assert result.out
assert result.exitstatus == 0 assert result.exitstatus == 0
assert result.signal == 0 assert result.signal == 0
@ -78,12 +78,12 @@ def test_box_seq():
def test_box_in_a_box(): def test_box_in_a_box():
def boxfun(): def boxfun():
result = py.io.ForkedFunc(boxf2).waitfinish() result = py.process.ForkedFunc(boxf2).waitfinish()
print result.out print result.out
print >>sys.stderr, result.err print >>sys.stderr, result.err
return result.retval return result.retval
result = py.io.ForkedFunc(boxfun).waitfinish() result = py.process.ForkedFunc(boxfun).waitfinish()
assert result.out == "someout\n" assert result.out == "someout\n"
assert result.err == "someerr\n" assert result.err == "someerr\n"
assert result.exitstatus == 0 assert result.exitstatus == 0
@ -99,7 +99,7 @@ def test_kill_func_forked():
def box_fun(): def box_fun():
time.sleep(10) # we don't want to last forever here time.sleep(10) # we don't want to last forever here
ff = py.io.ForkedFunc(box_fun) ff = py.process.ForkedFunc(box_fun)
os.kill(ff.pid, 15) os.kill(ff.pid, 15)
result = ff.waitfinish() result = ff.waitfinish()
if py.std.sys.version_info < (2,4): if py.std.sys.version_info < (2,4):

View File

@ -127,7 +127,7 @@ def forked_run_report(item, pdb=None):
os._exit(EXITSTATUS_TESTEXIT) os._exit(EXITSTATUS_TESTEXIT)
return ipickle.dumps(testrep) return ipickle.dumps(testrep)
ff = py.io.ForkedFunc(runforked) ff = py.process.ForkedFunc(runforked)
result = ff.waitfinish() result = ff.waitfinish()
if result.retval is not None: if result.retval is not None:
return ipickle.loads(result.retval) return ipickle.loads(result.retval)