pre-upload: switch to io.StringIO
Since Python 3 dropped StringIO, switch over to io.StringIO.
BUG=chromium:1003955
TEST=unittests pass
Change-Id: If7074d4dd89e31c7e48b79e8a6b34ed3adb65c98
Reviewed-on: https://chromium-review.googlesource.com/1803858
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Will Bradley <wbbradley@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index c1c49ad..04d13c8 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -16,12 +16,12 @@
import datetime
import fnmatch
import functools
+import io
import json
import os
import re
import sys
import stat
-import StringIO
from six.moves import configparser
@@ -1569,7 +1569,7 @@
# commit diff, rather than whatever's on disk.
# TODO(vapier): Once we migrate this to Python 3 only, cut it over.
contents = _get_file_content(f, commit)
- parser.readfp(StringIO.StringIO(contents))
+ parser.readfp(io.StringIO(contents))
except configparser.Error as e:
msg = ('Unable to parse COMMIT-QUEUE.ini file at %s due to %s.' %
(f, e))
diff --git a/pre-upload_unittest.py b/pre-upload_unittest.py
index da27cba..9608cc3 100755
--- a/pre-upload_unittest.py
+++ b/pre-upload_unittest.py
@@ -424,13 +424,13 @@
def testIgnoreIrrelevantFile(self):
self.file_mock.return_value = ['unrelated_file.ini']
- self.content_mock.return_value = '^$malformed gibberish^^&'
+ self.content_mock.return_value = u'^$malformed gibberish^^&'
self.assertEqual(pre_upload._check_cq_ini_well_formed('PROJECT', 'COMMIT'),
None)
def testWellformedFile(self):
self.file_mock.return_value = ['COMMIT-QUEUE.ini']
- self.content_mock.return_value = """#
+ self.content_mock.return_value = u"""#
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -450,7 +450,7 @@
def testMalformedFile(self):
self.file_mock.return_value = ['COMMIT-QUEUE.ini']
- self.content_mock.return_value = '^$malformed gibberish^^&'
+ self.content_mock.return_value = u'^$malformed gibberish^^&'
m = pre_upload._check_cq_ini_well_formed('PROJECT', 'COMMIT')
self.assertTrue(isinstance(m, pre_upload.HookFailure))