unittest BUG? 
Author Message
 unittest BUG?

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'.

class _WritelnDecorator:
    """Used to decorate file-like objects with a handy 'writeln' method"""
    def __init__(self,stream):
        self.stream = stream
        if _isJPython:
            import java.lang.System
            self.linesep = java.lang.System.getProperty("line.separator")
        else:
            self.linesep = os.linesep

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

    def writeln(self, *args):
        if args: apply(self.write, args)
        self.write(self.linesep)

--
Robin Becker



Wed, 05 Nov 2003 02:27:59 GMT  
 unittest BUG?
| 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'.  What are you using
to view the output?  cmd.exe?  bash(cygwin)?  vim?  less?

Note that if you use '\n' instead of '\r\n' Notepad will display a
black box instead of a newline character.  The lines will not wrap
properly (Notepad is broken).

Here are some examples from a Win2k box:

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.

Quote:
>>> import os
>>> repr( os.linesep )
"'\\015\\012'"

Jython 2.0 on java1.3.0 (JIT: null)
Type "copyright", "credits" or "license" for more information.

Quote:
>>> import os
>>> repr( os.linesep )
"'\\r\\n'"

Python 2.1 (#1, Apr 17 2001, 09:45:01)
[GCC 2.95.3-2 (cygwin special)] on cygwin_nt-4.01
Type "copyright", "credits" or "license" for more information.

Quote:
>>> import os
>>> repr( os.linesep )
"'\\n'"

I think the solution for you would either be to change the way you
view the files so you don't see the carriage returns or modify
os.linesep so that it is Unix-style and not windows-style.

HTH,
-D



Wed, 05 Nov 2003 02:56:07 GMT  
 unittest BUG?

Quote:

> | 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:

Quote:
> | 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



Wed, 05 Nov 2003 04:54:53 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. BUGS, BUGS, BUGS, BUGS, C4 BUGS

2. unittest: how to specify which suites to run with unittest.main()?

3. Need help Translating Python unittest to Ruby Test::Unit

4. The various UnitTest frameworks.

5. Windows python 2.2.1 IDLE glitch - unittest output display nothing

6. problems redirecting unittest output to sys.stdout

7. print unittest errors immediately

8. Code Coverage support for unittest?

9. Tkinter and unittest

10. unittest / pdb tricks?

11. A modest suggestion for unittest.py

12. Standard module unittest, where has unittestgui gone?

 

 
Powered by phpBB® Forum Software