[Android] Lint pylib/utils.

BUG=168518

Review URL: https://codereview.chromium.org/182033002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255761 0039d316-1c4b-4281-b951-d872f2087c98
parent 67f60d54
......@@ -12,18 +12,16 @@ Assumes system environment ANDROID_NDK_ROOT has been set.
import logging
import os
import shutil
import signal
import subprocess
import sys
import time
import time_profile
# TODO(craigdh): Move these pylib dependencies to pylib/utils/.
from pylib import android_commands
from pylib import cmd_helper
from pylib import constants
from pylib import pexpect
from pylib.utils import time_profile
import errors
import run_command
......@@ -98,7 +96,7 @@ def _KillAllEmulators():
for emu_name in emulators:
cmd_helper.RunCmd(['adb', '-s', emu_name, 'emu', 'kill'])
logging.info('Emulator killing is async; give a few seconds for all to die.')
for i in range(5):
for _ in range(5):
if not android_commands.GetAttachedDevices(hardware=False):
return
time.sleep(1)
......@@ -229,7 +227,8 @@ class Emulator(object):
self.api_level = api_level
self._CreateAVD()
def _DeviceName(self):
@staticmethod
def _DeviceName():
"""Return our device name."""
port = _GetAvailablePort()
return ('emulator-%d' % port, port)
......@@ -349,7 +348,8 @@ class Emulator(object):
stderr=subprocess.STDOUT)
self._InstallKillHandler()
def _AggressiveImageCleanup(self):
@staticmethod
def _AggressiveImageCleanup():
"""Aggressive cleanup of emulator images.
Experimentally it looks like our current emulator use on the bot
......@@ -386,7 +386,7 @@ class Emulator(object):
number_of_waits -= 1
if not number_of_waits:
break
except errors.WaitForResponseTimedOutError as e:
except errors.WaitForResponseTimedOutError:
seconds_waited += self._WAITFORDEVICE_TIMEOUT
adb_cmd = "adb -s %s %s" % (self.device, 'kill-server')
run_command.RunCommand(adb_cmd)
......@@ -411,7 +411,7 @@ class Emulator(object):
self.popen.kill()
self.popen = None
def _ShutdownOnSignal(self, signum, frame):
def _ShutdownOnSignal(self, _signum, _frame):
logging.critical('emulator _ShutdownOnSignal')
for sig in self._SIGNALS:
signal.signal(sig, signal.SIG_DFL)
......
......@@ -62,7 +62,7 @@ def _DiffKnownWarnings(current_warnings_set, known_bugs_file):
def _Rebaseline(current_warnings_set, known_bugs_file):
with file(known_bugs_file, 'w') as known_bugs:
for warning in sorted(current_warnings_set):
print >>known_bugs, warning
print >> known_bugs, warning
return 0
......@@ -142,7 +142,7 @@ def _Run(exclude, known_bugs, classes_to_analyze, auxiliary_classes,
proc = subprocess.Popen(shlex.split(cmd),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
out, _err = proc.communicate()
current_warnings_set = set(_StripLineNumbers(filter(None, out.splitlines())))
if rebaseline:
......@@ -230,7 +230,7 @@ def GetCommonParser():
return parser
def main(argv):
def main():
parser = GetCommonParser()
options, _ = parser.parse_args()
......@@ -238,4 +238,4 @@ def main(argv):
if __name__ == '__main__':
sys.exit(main(sys.argv))
sys.exit(main())
......@@ -3,11 +3,11 @@
# found in the LICENSE file.
"""Uploads the results to the flakiness dashboard server."""
# pylint: disable=E1002,R0201
import logging
import os
import shutil
import subprocess
import sys
import tempfile
import xml
......@@ -26,8 +26,10 @@ sys.path.append(
os.pardir, os.pardir, os.pardir,
'Tools', 'Scripts')))
# pylint: disable=F0401
from webkitpy.common.system import executive, filesystem
from webkitpy.layout_tests.layout_package import json_results_generator
# pylint: enable=F0401
#TODO(craigdh): pylib/utils/ should not depend on pylib/.
from pylib import cmd_helper
......@@ -125,7 +127,7 @@ class ResultsUploader(object):
# TODO(frankf): Use factory properties (see buildbot/bb_device_steps.py)
# This requires passing the actual master name (e.g. 'ChromiumFYI' not
# 'chromium.fyi').
from slave import slave_utils
from slave import slave_utils # pylint: disable=F0401
self._build_name = slave_utils.SlaveBuildName(constants.DIR_SOURCE_ROOT)
self._master_name = slave_utils.GetActiveMaster()
else:
......@@ -188,7 +190,7 @@ class ResultsUploader(object):
results_generator.generate_times_ms_file()
results_generator.upload_json_files(json_files)
except Exception as e:
logging.error("Uploading results to test server failed: %s." % e);
logging.error("Uploading results to test server failed: %s." % e)
finally:
shutil.rmtree(tmp_folder)
......
......@@ -9,8 +9,7 @@ import os
import re
from pylib import constants
import flakiness_dashboard_results_uploader
from pylib.utils import flakiness_dashboard_results_uploader
def _LogToFile(results, test_type, suite_name):
......@@ -47,11 +46,11 @@ def _LogToFlakinessDashboard(results, test_type, test_package,
try:
if flakiness_server == constants.UPSTREAM_FLAKINESS_SERVER:
assert test_package in ['ContentShellTest',
'ChromiumTestShellTest',
'AndroidWebViewTest']
dashboard_test_type = ('%s_instrumentation_tests' %
test_package.lower().rstrip('test'))
assert test_package in ['ContentShellTest',
'ChromiumTestShellTest',
'AndroidWebViewTest']
dashboard_test_type = ('%s_instrumentation_tests' %
test_package.lower().rstrip('test'))
# Downstream server.
else:
dashboard_test_type = 'Chromium_Android_Instrumentation'
......
......@@ -3,14 +3,14 @@
# found in the LICENSE file.
"""Thread and ThreadGroup that reraise exceptions on the main thread."""
# pylint: disable=W0212
import logging
import sys
import threading
import time
import traceback
import watchdog_timer
from pylib.utils import watchdog_timer
class TimeoutError(Exception):
......@@ -38,7 +38,7 @@ def LogThreadStack(thread):
class ReraiserThread(threading.Thread):
"""Thread class that can reraise exceptions."""
def __init__(self, func, args=[], kwargs={}, name=None):
def __init__(self, func, args=None, kwargs=None, name=None):
"""Initialize thread.
Args:
......@@ -48,6 +48,10 @@ class ReraiserThread(threading.Thread):
name: thread name, defaults to Thread-N.
"""
super(ReraiserThread, self).__init__(name=name)
if not args:
args = []
if not kwargs:
kwargs = {}
self.daemon = True
self._func = func
self._args = args
......@@ -72,12 +76,14 @@ class ReraiserThread(threading.Thread):
class ReraiserThreadGroup(object):
"""A group of ReraiserThread objects."""
def __init__(self, threads=[]):
def __init__(self, threads=None):
"""Initialize thread group.
Args:
threads: a list of ReraiserThread objects; defaults to empty.
"""
if not threads:
threads = []
self._threads = threads
def Add(self, thread):
......
......@@ -7,8 +7,8 @@
import threading
import unittest
import reraiser_thread
import watchdog_timer
from pylib.utils import reraiser_thread
from pylib.utils import watchdog_timer
class TestException(Exception):
......
......@@ -3,7 +3,6 @@
# found in the LICENSE file.
import logging
import os
import psutil
import signal
......
......@@ -3,15 +3,15 @@
# found in the LICENSE file.
"""A utility to run functions with timeouts and retries."""
# pylint: disable=W0702
import functools
import threading
import reraiser_thread
import watchdog_timer
from pylib.utils import reraiser_thread
from pylib.utils import watchdog_timer
def Run(func, timeout, retries, args=[], kwargs={}):
def Run(func, timeout, retries, args=None, kwargs=None):
"""Runs the passed function in a separate thread with timeouts and retries.
Args:
......@@ -24,6 +24,11 @@ def Run(func, timeout, retries, args=[], kwargs={}):
Returns:
The return value of func(*args, **kwargs).
"""
if not args:
args = []
if not kwargs:
kwargs = {}
# The return value uses a list because Python variables are references, not
# values. Closures make a copy of the reference, so updating the closure's
# reference wouldn't update where the original reference pointed.
......
......@@ -6,15 +6,15 @@
import unittest
import reraiser_thread
import timeout_retry
from pylib.utils import reraiser_thread
from pylib.utils import timeout_retry
class TestException(Exception):
pass
def _NeverEnding(tries=[0]):
def _NeverEnding(tries):
tries[0] += 1
while True:
pass
......
......@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# pylint: disable=W0702
import os
import signal
import subprocess
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment