From 09a52ed47bb26498c97a579ce1147861df696d84 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Thu, 28 Mar 2013 17:13:53 -0600 Subject: 2to3: Apply `imports` fixer. The `imports` fixer deals with the standard packages that have been renamed, removed, or methods that have moved. cPickle -- removed, use pickle commands -- removed, getoutput, getstatusoutput moved to subprocess urlparse -- removed, urlparse moved to urllib.parse cStringIO -- removed, use StringIO or io.StringIO copy_reg -- renamed copyreg _winreg -- renamed winreg ConfigParser -- renamed configparser __builtin__ -- renamed builtins In the case of `cPickle`, it is imported as `pickle` when python < 3 and performance may be a consideration, but otherwise plain old `pickle` is used. Dealing with `StringIO` is a bit tricky. There is an `io.StringIO` function in the `io` module, available since Python 2.6, but it expects unicode whereas `StringIO.StringIO` expects ascii. The Python 3 equivalent is then `io.BytesIO`. What I have done here is used BytesIO for anything that is emulating a file for testing purposes. That is more explicit than using a redefined StringIO as was done before we dropped support for Python 2.4 and 2.5. Closes #3180. --- numpy/distutils/tests/test_exec_command.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'numpy/distutils/tests') diff --git a/numpy/distutils/tests/test_exec_command.py b/numpy/distutils/tests/test_exec_command.py index 11f262369..3e85fcd3e 100644 --- a/numpy/distutils/tests/test_exec_command.py +++ b/numpy/distutils/tests/test_exec_command.py @@ -2,11 +2,16 @@ from __future__ import division, absolute_import import os import sys -import StringIO from tempfile import TemporaryFile from numpy.distutils import exec_command +# In python 3 stdout, stderr are text (unicode compliant) devices, so to +# emulate them import StringIO from the io module. +if sys.version_info[0] >= 3: + from io import StringIO +else: + from StringIO import StringIO class redirect_stdout(object): """Context manager to redirect stdout for exec_command test.""" @@ -62,26 +67,26 @@ def test_exec_command_stdout(): # both that the special case works and that the generic code works. # Test posix version: - with redirect_stdout(StringIO.StringIO()): + with redirect_stdout(StringIO()): with redirect_stderr(TemporaryFile()): exec_command.exec_command("cd '.'") if os.name == 'posix': # Test general (non-posix) version: with emulate_nonposix(): - with redirect_stdout(StringIO.StringIO()): + with redirect_stdout(StringIO()): with redirect_stderr(TemporaryFile()): exec_command.exec_command("cd '.'") def test_exec_command_stderr(): # Test posix version: with redirect_stdout(TemporaryFile(mode='w+')): - with redirect_stderr(StringIO.StringIO()): + with redirect_stderr(StringIO()): exec_command.exec_command("cd '.'") if os.name == 'posix': # Test general (non-posix) version: with emulate_nonposix(): with redirect_stdout(TemporaryFile()): - with redirect_stderr(StringIO.StringIO()): + with redirect_stderr(StringIO()): exec_command.exec_command("cd '.'") -- cgit v1.2.1