[py-svn] r37772 - in py/trunk/py/io: . test
hpk at codespeak.net
hpk at codespeak.net
Thu Feb 1 22:52:44 CET 2007
Author: hpk
Date: Thu Feb 1 22:52:42 2007
New Revision: 37772
Modified:
py/trunk/py/io/stdcapture.py
py/trunk/py/io/test/test_capture.py
Log:
have both capturings have the same done/reset semantics
(should also fix a buildcmodule related problem, e.g. for
greenlets)
Modified: py/trunk/py/io/stdcapture.py
==============================================================================
--- py/trunk/py/io/stdcapture.py (original)
+++ py/trunk/py/io/stdcapture.py Thu Feb 1 22:52:42 2007
@@ -22,6 +22,16 @@
return res, out, err
call = classmethod(call)
+ def reset(self):
+ """ reset sys.stdout and sys.stderr
+
+ returns a tuple of file objects (out, err) for the captured
+ data
+ """
+ outfile, errfile = self.done()
+ return outfile.read(), errfile.read()
+
+
class StdCaptureFD(Capture):
""" capture Stdout and Stderr both on filedescriptor
and sys.stdout/stderr level.
@@ -40,18 +50,14 @@
if patchsys:
self.err.setasfile('stderr')
- def reset(self):
- """ reset sys.stdout and sys.stderr
-
- returns a tuple of file objects (out, err) for the captured
- data
- """
+ def done(self):
+ """ return (outfile, errfile) and stop capturing. """
outfile = errfile = emptyfile
if hasattr(self, 'out'):
outfile = self.out.done()
if hasattr(self, 'err'):
errfile = self.err.done()
- return outfile.read(), errfile.read()
+ return outfile, errfile
class StdCapture(Capture):
""" capture sys.stdout/sys.stderr (but not system level fd 1 and 2).
@@ -76,11 +82,12 @@
sys.stdin = self.newin = DontReadFromInput()
def reset(self):
- """ return captured output and restore sys.stdout/err."""
+ """ return captured output as strings and restore sys.stdout/err."""
x, y = self.done()
return x.read(), y.read()
def done(self):
+ """ return (outfile, errfile) and stop capturing. """
o,e = sys.stdout, sys.stderr
outfile = errfile = emptyfile
if self._out:
Modified: py/trunk/py/io/test/test_capture.py
==============================================================================
--- py/trunk/py/io/test/test_capture.py (original)
+++ py/trunk/py/io/test/test_capture.py Thu Feb 1 22:52:42 2007
@@ -61,7 +61,15 @@
def getcapture(self, **kw):
return py.io.StdCapture(**kw)
- def test_capturing_simple(self):
+ def test_capturing_done_simple(self):
+ cap = self.getcapture()
+ print "hello world"
+ print >>sys.stderr, "hello error"
+ outfile, errfile = cap.done()
+ assert outfile.read() == "hello world\n"
+ assert errfile.read() == "hello error\n"
+
+ def test_capturing_reset_simple(self):
cap = self.getcapture()
print "hello world"
print >>sys.stderr, "hello error"
More information about the py-svn
mailing list