summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-04-03 02:21:39 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-04-03 02:21:39 (GMT)
commit9b4ee12e899a99cc82ef52925d03029ce66bf2c6 (patch)
tree09c3cf1a90d100429db5c23e19f55669d13fbcb5 /Lib
parent1c7c11ef613f64405523972b0db4be2cdc53d8e5 (diff)
downloadcpython-9b4ee12e899a99cc82ef52925d03029ce66bf2c6.zip
cpython-9b4ee12e899a99cc82ef52925d03029ce66bf2c6.tar.gz
cpython-9b4ee12e899a99cc82ef52925d03029ce66bf2c6.tar.bz2
Cross platform unittest.TestResult newline handling when buffering stdout / stderr.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/unittest/result.py21
-rw-r--r--Lib/unittest/test/test_result.py9
2 files changed, 15 insertions, 15 deletions
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py
index 5cab30e..b9045f4 100644
--- a/Lib/unittest/result.py
+++ b/Lib/unittest/result.py
@@ -19,9 +19,8 @@ def failfast(method):
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 @@ class TestResult(object):
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 @@ class TestResult(object):
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)
diff --git a/Lib/unittest/test/test_result.py b/Lib/unittest/test/test_result.py
index c02b8ef..7a1f65a 100644
--- a/Lib/unittest/test/test_result.py
+++ b/Lib/unittest/test/test_result.py
@@ -1,3 +1,4 @@
+import os
import sys
import textwrap
from cStringIO import StringIO, OutputType
@@ -413,8 +414,8 @@ class TestOutputBuffering(unittest.TestCase):
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 @@ class TestOutputBuffering(unittest.TestCase):
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)