[Python-checkins] r79648 - in python/trunk/Lib/unittest: result.py test/test_result.py

michael.foord python-checkins at python.org
Sat Apr 3 04:21:39 CEST 2010


Author: michael.foord
Date: Sat Apr  3 04:21:39 2010
New Revision: 79648

Log:
Cross platform unittest.TestResult newline handling when buffering stdout / stderr.

Modified:
   python/trunk/Lib/unittest/result.py
   python/trunk/Lib/unittest/test/test_result.py

Modified: python/trunk/Lib/unittest/result.py
==============================================================================
--- python/trunk/Lib/unittest/result.py	(original)
+++ python/trunk/Lib/unittest/result.py	Sat Apr  3 04:21:39 2010
@@ -19,9 +19,8 @@
         return method(self, *args, **kw)
     return inner
 
-NEWLINE = os.linesep
-STDOUT_LINE = '%sStdout:%s%%s' % (NEWLINE, NEWLINE)
-STDERR_LINE = '%sStderr:%s%%s' % (NEWLINE, NEWLINE)
+STDOUT_LINE = '\nStdout:\n%s'
+STDERR_LINE = '\nStderr:\n%s'
 
 
 class TestResult(object):
@@ -77,12 +76,12 @@
                 output = sys.stdout.getvalue()
                 error = sys.stderr.getvalue()
                 if output:
-                    if not output.endswith(NEWLINE):
-                        output += NEWLINE
+                    if not output.endswith('\n'):
+                        output += '\n'
                     self._original_stdout.write(STDOUT_LINE % output)
                 if error:
-                    if not error.endswith(NEWLINE):
-                        error += NEWLINE
+                    if not error.endswith('\n'):
+                        error += '\n'
                     self._original_stderr.write(STDERR_LINE % error)
 
             sys.stdout = self._original_stdout
@@ -158,12 +157,12 @@
             output = sys.stdout.getvalue()
             error = sys.stderr.getvalue()
             if output:
-                if not output.endswith(NEWLINE):
-                    output += NEWLINE
+                if not output.endswith('\n'):
+                    output += '\n'
                 msgLines.append(STDOUT_LINE % output)
             if error:
-                if not error.endswith(NEWLINE):
-                    error += NEWLINE
+                if not error.endswith('\n'):
+                    error += '\n'
                 msgLines.append(STDERR_LINE % error)
         return ''.join(msgLines)
 

Modified: python/trunk/Lib/unittest/test/test_result.py
==============================================================================
--- python/trunk/Lib/unittest/test/test_result.py	(original)
+++ python/trunk/Lib/unittest/test/test_result.py	Sat Apr  3 04:21:39 2010
@@ -1,3 +1,4 @@
+import os
 import sys
 import textwrap
 from cStringIO import StringIO, OutputType
@@ -413,8 +414,8 @@
         print 'foo'
         print >> sys.stderr, 'bar'
 
-        self.assertEqual(out_stream.getvalue(), 'foo\n')
-        self.assertEqual(err_stream.getvalue(), 'bar\n')
+        self.assertEqual(out_stream.getvalue(), 'foo%s' % os.linesep)
+        self.assertEqual(err_stream.getvalue(), 'bar%s' % os.linesep)
 
         self.assertEqual(result._original_stdout.getvalue(), '')
         self.assertEqual(result._original_stderr.getvalue(), '')
@@ -467,13 +468,13 @@
             expectedOutMessage = textwrap.dedent("""
                 Stdout:
                 foo
-            """)
+            """).replace('\n', os.linesep)
             expectedErrMessage = ''
             if include_error:
                 expectedErrMessage = textwrap.dedent("""
                 Stderr:
                 bar
-            """)
+            """).replace('\n', os.linesep)
             expectedFullMessage = 'None\n%s%s' % (expectedOutMessage, expectedErrMessage)
 
             self.assertIs(test, self)


More information about the Python-checkins mailing list