summaryrefslogtreecommitdiffstats
path: root/test/option
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2010-04-27 06:04:44 (GMT)
committerSteven Knight <knight@baldmt.com>2010-04-27 06:04:44 (GMT)
commit6b99d830007ea3e9c7b8f56b9eb953856c474af1 (patch)
tree33852f223a1324a4f381d98d5d821c75522fcf15 /test/option
parent28b036c0f803c2a156de7e155daa0f8635e95d89 (diff)
downloadSCons-6b99d830007ea3e9c7b8f56b9eb953856c474af1.zip
SCons-6b99d830007ea3e9c7b8f56b9eb953856c474af1.tar.gz
SCons-6b99d830007ea3e9c7b8f56b9eb953856c474af1.tar.bz2
Python 2.6 forward compatibility with 3.x: use a subclass of io.StringIO
to enforce that all strings passed to the .write() method are unicode.
Diffstat (limited to 'test/option')
-rw-r--r--test/option/profile.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/test/option/profile.py b/test/option/profile.py
index fef4b7a..519af73 100644
--- a/test/option/profile.py
+++ b/test/option/profile.py
@@ -39,6 +39,19 @@ except ImportError:
# No 'cStringIO' assume new 3.x structure
from io import StringIO
+try:
+ import io
+except (ImportError, AttributeError):
+ # Pre-2.6 Python has no "io" module.
+ import StringIO
+ StringIOClass = StringIO.StringIO
+else:
+ # TODO(2.6): The 2.6 io.StringIO.write() method requires unicode strings.
+ # This subclass can be removed when we drop support for Python 2.6.
+ class StringIOClass(io.StringIO):
+ def write(self, s):
+ super(io.StringIO, self).write(unicode(s))
+
import TestSCons
test = TestSCons.TestSCons()
@@ -61,7 +74,7 @@ test.must_contain_all_lines(test.stdout(), ['usage: scons [OPTION]'])
try:
save_stdout = sys.stdout
- sys.stdout = StringIO()
+ sys.stdout = StringIOClass()
stats = pstats.Stats(scons_prof)
stats.sort_stats('time')
@@ -82,7 +95,7 @@ test.run(arguments = "--profile %s" % scons_prof)
try:
save_stdout = sys.stdout
- sys.stdout = StringIO()
+ sys.stdout = StringIOClass()
stats = pstats.Stats(scons_prof)
stats.sort_stats('time')