summaryrefslogtreecommitdiffstats
path: root/test/option/profile.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/option/profile.py')
-rw-r--r--test/option/profile.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/test/option/profile.py b/test/option/profile.py
index 16032fb..fef4b7a 100644
--- a/test/option/profile.py
+++ b/test/option/profile.py
@@ -23,8 +23,21 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import StringIO
import sys
+try:
+ # In Python 2.5 and before, there was no 'io' module. The 'io' module
+ # in 2.6 provides a StringIO, but it only works with Unicode strings,
+ # while virtually all the strings we use are normal eight-bit strings,
+ # including all the strings generated by the 'profile' module. This
+ # is a horrible hack that just papers over the problem without fixing
+ # it, but I don't see any other way to do it. We'll keep using the old
+ # StringIO module until it no longer exists, and hope that if it's not
+ # there, it means that we've converted to Python 3.x where all strings
+ # are Unicode.
+ exec('from cStringIO import StringIO')
+except ImportError:
+ # No 'cStringIO' assume new 3.x structure
+ from io import StringIO
import TestSCons
@@ -48,7 +61,7 @@ test.must_contain_all_lines(test.stdout(), ['usage: scons [OPTION]'])
try:
save_stdout = sys.stdout
- sys.stdout = StringIO.StringIO()
+ sys.stdout = StringIO()
stats = pstats.Stats(scons_prof)
stats.sort_stats('time')
@@ -69,7 +82,7 @@ test.run(arguments = "--profile %s" % scons_prof)
try:
save_stdout = sys.stdout
- sys.stdout = StringIO.StringIO()
+ sys.stdout = StringIO()
stats = pstats.Stats(scons_prof)
stats.sort_stats('time')