From 0ca844e294d930184ce4859fff5d558b0e754c44 Mon Sep 17 00:00:00 2001 From: Raphael Kubo da Costa Date: Mon, 14 Oct 2019 17:56:39 +0000 Subject: [PATCH] upload_to_google_storage_unittest.py: Make StringIO usage Python 3-compatible There is no StringIO module in Python 3, it is now in the io module. Add some code to make it work with both versions. Bug: 1009819 Change-Id: I7be020735916f6181beaa3a2beb7e1902c38ad31 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1859996 Auto-Submit: Raphael Kubo da Costa Commit-Queue: Edward Lesmes Reviewed-by: Edward Lesmes --- tests/upload_to_google_storage_unittest.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/upload_to_google_storage_unittest.py b/tests/upload_to_google_storage_unittest.py index 4b6a5c916..6b14ee7b6 100755 --- a/tests/upload_to_google_storage_unittest.py +++ b/tests/upload_to_google_storage_unittest.py @@ -14,7 +14,6 @@ except ImportError: # For Py3 compatibility import queue import shutil -import StringIO import sys import tarfile import tempfile @@ -26,6 +25,13 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import upload_to_google_storage from download_from_google_storage_unittest import GsutilMock from download_from_google_storage_unittest import ChangedWorkingDirectory +from third_party import six + +if six.PY2: + from cStringIO import StringIO +else: + from io import StringIO + # ../third_party/gsutil/gsutil GSUTIL_DEFAULT_PATH = os.path.join( @@ -176,7 +182,7 @@ class UploadTests(unittest.TestCase): def test_get_targets_multiple_stdin(self): inputs = ['a', 'b', 'c', 'd', 'e'] - sys.stdin = StringIO.StringIO(os.linesep.join(inputs)) + sys.stdin = StringIO(os.linesep.join(inputs)) result = upload_to_google_storage.get_targets( ['-'], self.parser, @@ -185,7 +191,7 @@ class UploadTests(unittest.TestCase): def test_get_targets_multiple_stdin_null(self): inputs = ['a', 'b', 'c', 'd', 'e'] - sys.stdin = StringIO.StringIO('\0'.join(inputs)) + sys.stdin = StringIO('\0'.join(inputs)) result = upload_to_google_storage.get_targets( ['-'], self.parser,