unittest BUG?

Fredrik Lundh fredrik at pythonware.com
Fri May 18 16:54:53 EDT 2001


D-Man wrote:
> | We are using unittest.py $Revision: 1.3 $ and see extra ^Ms on
> | win32. It seems the problem comes from using the os.linesep in the
> | following when the stream is stdout. Is there a sensible
> | way for this kind of class to obtain a sensible line terminator?
> | Clearly the correct linesep for files opened in text mode is '\n'.
>
> On M$ Windo~1 the proper line separator is '\r\n'.

Maybe, but he's using Windows, where the proper line separator
is '\n' if you're writing to a file opened in text mode.

As Robin had already noted, of course:

> | Clearly the correct linesep for files opened in text mode is '\n'.

fwiw, unittest.py 1.2 does the right thing (note the comment):

class _WritelnDecorator:
    """Used to decorate file-like objects with a handy 'writeln' method"""
    def __init__(self,stream):
        self.stream = stream

    def __getattr__(self, attr):
        return getattr(self.stream,attr)

    def writeln(self, *args):
        if args: apply(self.write, args)
        self.write('\n') # text-mode streams translate to \r\n if needed

looks like some Jython hacker broke it...

a quick and stupid workaround might be to run Python using the -u
flag (unbuffered, binary output).

Cheers /F





More information about the Python-list mailing list