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