mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
Revert "Use io.open for opening files"
This reverts commit eb16430cf9.
Reason for revert: blocking upload of CLs, https://crbug.com/1357152#c8
Original change's description:
> Use io.open for opening files
>
> Use io.open which is consistent in py2 and py3.
>
> Bug: 1357152
> Change-Id: I49a3df503026bc6918362a9b5600f57111111111
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3872429
> Reviewed-by: Gavin Mak <gavinmak@google.com>
> Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Bug: 1357152
Change-Id: Iec18fe8fd37f28887507d47d7b35b93ccee72375
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3872487
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Gavin Mak <gavinmak@google.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import os as _os
|
||||
import io as _io
|
||||
|
||||
from warnings import warn
|
||||
_HERE = _os.path.dirname(_os.path.abspath(__file__))
|
||||
@@ -171,9 +170,9 @@ def CheckAuthorizedAuthor(input_api, output_api, bot_allowlist=None):
|
||||
input_api.PresubmitLocalPath(), 'AUTHORS')
|
||||
author_re = input_api.re.compile(r'[^#]+\s+\<(.+?)\>\s*$')
|
||||
valid_authors = []
|
||||
with _io.open(authors_path, 'rb', encoding='utf-8') as fp:
|
||||
with open(authors_path, 'rb') as fp:
|
||||
for line in fp:
|
||||
m = author_re.match(line)
|
||||
m = author_re.match(line.decode('utf8'))
|
||||
if m:
|
||||
valid_authors.append(m.group(1).lower())
|
||||
|
||||
@@ -799,7 +798,7 @@ def GetUnitTests(input_api,
|
||||
assert run_on_python3 or run_on_python2, (
|
||||
'At least one of "run_on_python2" or "run_on_python3" must be set.')
|
||||
def has_py3_shebang(test):
|
||||
with _io.open(test, encoding='utf-8') as f:
|
||||
with open(test) as f:
|
||||
maybe_shebang = f.readline()
|
||||
return maybe_shebang.startswith('#!') and 'python3' in maybe_shebang
|
||||
|
||||
@@ -1900,7 +1899,7 @@ def CheckJsonParses(input_api, output_api, file_filter=None):
|
||||
file_filter=file_filter)
|
||||
warnings = []
|
||||
for f in affected_files:
|
||||
with _io.open(f.AbsoluteLocalPath(), encoding='utf-8') as j:
|
||||
with open(f.AbsoluteLocalPath()) as j:
|
||||
try:
|
||||
json.load(j)
|
||||
except ValueError:
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import functools
|
||||
import io
|
||||
import itertools
|
||||
import logging
|
||||
import multiprocessing
|
||||
@@ -27,10 +26,12 @@ if sys.version_info.major == 2:
|
||||
from cStringIO import StringIO
|
||||
import mock
|
||||
import urllib2 as urllib_request
|
||||
BUILTIN_OPEN = '__builtin__.open'
|
||||
else:
|
||||
from io import StringIO
|
||||
from unittest import mock
|
||||
import urllib.request as urllib_request
|
||||
BUILTIN_OPEN = 'builtins.open'
|
||||
|
||||
_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, _ROOT)
|
||||
@@ -2986,9 +2987,9 @@ the current line as well!
|
||||
self.AssertOwnersWorks(approvers=set(['ben@example.com']),
|
||||
is_committing=False)
|
||||
|
||||
@mock.patch('io.open', mock.mock_open())
|
||||
@mock.patch(BUILTIN_OPEN, mock.mock_open())
|
||||
def testCannedRunUnitTests(self):
|
||||
io.open().readline.return_value = ''
|
||||
open().readline.return_value = ''
|
||||
change = presubmit.Change(
|
||||
'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
||||
input_api = self.MockInputApi(change, False)
|
||||
@@ -3032,9 +3033,9 @@ the current line as well!
|
||||
|
||||
self.checkstdout('')
|
||||
|
||||
@mock.patch('io.open', mock.mock_open())
|
||||
@mock.patch(BUILTIN_OPEN, mock.mock_open())
|
||||
def testCannedRunUnitTestsWithTimer(self):
|
||||
io.open().readline.return_value = ''
|
||||
open().readline.return_value = ''
|
||||
change = presubmit.Change(
|
||||
'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
||||
input_api = self.MockInputApi(change, False)
|
||||
@@ -3058,9 +3059,9 @@ the current line as well!
|
||||
|
||||
self.checkstdout('')
|
||||
|
||||
@mock.patch('io.open', mock.mock_open())
|
||||
@mock.patch(BUILTIN_OPEN, mock.mock_open())
|
||||
def testCannedRunUnitTestsWithTimerTimesOut(self):
|
||||
io.open().readline.return_value = ''
|
||||
open().readline.return_value = ''
|
||||
change = presubmit.Change(
|
||||
'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
||||
input_api = self.MockInputApi(change, False)
|
||||
@@ -3092,9 +3093,9 @@ the current line as well!
|
||||
input_api.thread_pool.timeout, mock.ANY)
|
||||
timer_instance.start.assert_called_once_with()
|
||||
|
||||
@mock.patch('io.open', mock.mock_open())
|
||||
@mock.patch(BUILTIN_OPEN, mock.mock_open())
|
||||
def testCannedRunUnitTestsPython3(self):
|
||||
io.open().readline.return_value = '#!/usr/bin/env python3'
|
||||
open().readline.return_value = '#!/usr/bin/env python3'
|
||||
change = presubmit.Change(
|
||||
'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
||||
input_api = self.MockInputApi(change, False)
|
||||
@@ -3148,9 +3149,9 @@ the current line as well!
|
||||
|
||||
self.checkstdout('')
|
||||
|
||||
@mock.patch('io.open', mock.mock_open())
|
||||
@mock.patch(BUILTIN_OPEN, mock.mock_open())
|
||||
def testCannedRunUnitTestsDontRunOnPython2(self):
|
||||
io.open().readline.return_value = '#!/usr/bin/env python3'
|
||||
open().readline.return_value = '#!/usr/bin/env python3'
|
||||
change = presubmit.Change(
|
||||
'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
||||
input_api = self.MockInputApi(change, False)
|
||||
@@ -3192,9 +3193,9 @@ the current line as well!
|
||||
|
||||
self.checkstdout('')
|
||||
|
||||
@mock.patch('io.open', mock.mock_open())
|
||||
@mock.patch(BUILTIN_OPEN, mock.mock_open())
|
||||
def testCannedRunUnitTestsDontRunOnPython3(self):
|
||||
io.open().readline.return_value = '#!/usr/bin/env python3'
|
||||
open().readline.return_value = '#!/usr/bin/env python3'
|
||||
change = presubmit.Change(
|
||||
'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
||||
input_api = self.MockInputApi(change, False)
|
||||
|
||||
Reference in New Issue
Block a user