Re: [Python-Dev] [Python-checkins] cpython (3.2): Issue #12400: runtest() truncates the StringIO stream before a new test
Le mercredi 29 juin 2011 à 13:05 -0400, Terry Reedy a écrit :
On 6/29/2011 11:30 AM, victor.stinner wrote:
summary: Issue #12400: runtest() truncates the StringIO stream before a new test
files: Lib/test/regrtest.py | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -793,6 +793,7 @@ if runtest.stringio is None: runtest.stringio = io.StringIO() stream = runtest.stringio + stream.truncate(0)
You *MUST* seek to 0 to reset the file position, which I presume is your intention. 'Resize' does not mean what you probably think is does (and what I thought once either ;-).
"truncate(size=None) Resize the stream to the given size in bytes (or the current position if size is not specified). The current stream position isn’t changed."
s=io.StringIO() s.write('abc') 3 s.truncate(0) 0 s.tell() 3 s.write('abc') 3 s.getvalue() '\x00\x00\x00abc'
Oh crap. I read _pyio source code and .truncate(0) was looking for the right method to "reset" a StringIO. I tried .truncate(0) in a terminal, but the zeros ('\x00') are "hidden". sys.stdout.write("\0") doesn't print anything in my Linux terminal. Fixed by commit 450209efe272, thank you. Victor
participants (1)
-
Victor Stinner