summaryrefslogtreecommitdiff
path: root/test/option
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2010-04-27 06:04:44 +0000
committerSteven Knight <knight@baldmt.com>2010-04-27 06:04:44 +0000
commit0477dbbda89ad588a31adc480a7e0a2bda2073bb (patch)
tree33852f223a1324a4f381d98d5d821c75522fcf15 /test/option
parentc66e92f020a391d461b594d6104f61a3abadb940 (diff)
downloadscons-0477dbbda89ad588a31adc480a7e0a2bda2073bb.tar.gz
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 fef4b7a8..519af73c 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')