Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Bug 1280571 - Add testing/mochitest to the flake8 linter, r=ahal
Browse files Browse the repository at this point in the history
This also adds E402 (no imports at top of file) to the global ignore list. The
other error codes added were previously ignored by default, but now that we
have started a custom ignore list, need to be listed explicitly.

MozReview-Commit-ID: RtMuVEX6i5

--HG--
extra : rebase_source : 939bc9354f5891c680513d7e9068d0438e169132
  • Loading branch information
psdh committed Sep 21, 2016
1 parent e53026e commit 58b6130
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .flake8
@@ -1,3 +1,5 @@
[flake8]
# See http://pep8.readthedocs.io/en/latest/intro.html#configuration
ignore = E121, E123, E126, E133, E226, E241, E242, E704, W503, E402
max-line-length = 99
filename = *.py, +.lint
32 changes: 21 additions & 11 deletions testing/mochitest/bisection.py
Expand Up @@ -15,7 +15,8 @@ def __init__(self, harness):
self.max_failures = 3

def setup(self, tests):
"This method is used to initialize various variables that are required for test bisection"
"""This method is used to initialize various variables that are required
for test bisection"""
status = 0
self.contents.clear()
# We need totalTests key in contents for sanity check
Expand All @@ -25,7 +26,8 @@ def setup(self, tests):
return status

def reset(self, expectedError, result):
"This method is used to initialize self.expectedError and self.result for each loop in runtests."
"""This method is used to initialize self.expectedError and self.result
for each loop in runtests."""
self.expectedError = expectedError
self.result = result

Expand All @@ -40,23 +42,27 @@ def get_tests_for_bisection(self, options, tests):
return bisectlist

def pre_test(self, options, tests, status):
"This method is used to call other methods for setting up variables and getting the list of tests for bisection."
"""This method is used to call other methods for setting up variables and
getting the list of tests for bisection."""
if options.bisectChunk == "default":
return tests
# The second condition in 'if' is required to verify that the failing
# test is the last one.
elif 'loop' not in self.contents or not self.contents['tests'][-1].endswith(options.bisectChunk):
elif ('loop' not in self.contents or not self.contents['tests'][-1].endswith(
options.bisectChunk)):
tests = self.get_tests_for_bisection(options, tests)
status = self.setup(tests)

return self.next_chunk_binary(options, status)

def post_test(self, options, expectedError, result):
"This method is used to call other methods to summarize results and check whether a sanity check is done or not."
"""This method is used to call other methods to summarize results and check whether a
sanity check is done or not."""
self.reset(expectedError, result)
status = self.summarize_chunk(options)
# Check whether sanity check has to be done. Also it is necessary to check whether options.bisectChunk is present
# in self.expectedError as we do not want to run if it is "default".
# Check whether sanity check has to be done. Also it is necessary to check whether
# options.bisectChunk is present in self.expectedError as we do not want to run
# if it is "default".
if status == -1 and options.bisectChunk in self.expectedError:
# In case we have a debug build, we don't want to run a sanity
# check, will take too much time.
Expand Down Expand Up @@ -213,7 +219,8 @@ def summarize_chunk(self, options):
# is the failing test itself therefore the bleedthrough
# test is the first test
self.summary.append(
"TEST-UNEXPECTED-FAIL | %s | Bleedthrough detected, this test is the root cause for many of the above failures" %
"TEST-UNEXPECTED-FAIL | %s | Bleedthrough detected, this test is the "
"root cause for many of the above failures" %
self.contents['testsToRun'][0])
status = -1
else:
Expand All @@ -236,7 +243,8 @@ def check_for_intermittent(self, options):
return 0
else:
if self.failcount > 0:
# -1 is being returned as the test is intermittent, so no need to bisect further.
# -1 is being returned as the test is intermittent, so no need to bisect
# further.
return -1
# If the test does not fail even once, then proceed to next chunk for bisection.
# loop is set to 2 to proceed on bisection.
Expand All @@ -254,12 +262,14 @@ def check_for_intermittent(self, options):
# limit set, it is a perma-fail.
if self.failcount < self.max_failures:
if self.repeat == 0:
# -1 is being returned as the test is intermittent, so no need to bisect further.
# -1 is being returned as the test is intermittent, so no need to bisect
# further.
return -1
return 0
else:
self.summary.append(
"TEST-UNEXPECTED-FAIL | %s | Bleedthrough detected, this test is the root cause for many of the above failures" %
"TEST-UNEXPECTED-FAIL | %s | Bleedthrough detected, this test is the "
"root cause for many of the above failures" %
self.contents['testsToRun'][0])
return -1

Expand Down
24 changes: 15 additions & 9 deletions testing/mochitest/leaks.py
Expand Up @@ -54,17 +54,21 @@ def process(self):
for test in self._parseLeakingTests():
for url, count in self._zipLeakedWindows(test["leakedWindows"]):
self.logger.warning(
"TEST-UNEXPECTED-FAIL | %s | leaked %d window(s) until shutdown [url = %s]" % (test["fileName"], count, url))
"TEST-UNEXPECTED-FAIL | %s | leaked %d window(s) until shutdown "
"[url = %s]") % (test["fileName"], count, url)

if test["leakedWindowsString"]:
self.logger.info("TEST-INFO | %s | windows(s) leaked: %s" %
(test["fileName"], test["leakedWindowsString"]))

if test["leakedDocShells"]:
self.logger.warning("TEST-UNEXPECTED-FAIL | %s | leaked %d docShell(s) until shutdown" % (
test["fileName"], len(test["leakedDocShells"])))
self.logger.info("TEST-INFO | %s | docShell(s) leaked: %s" % (test["fileName"],
', '.join(["[pid = %s] [id = %s]" % x for x in test["leakedDocShells"]])))
self.logger.warning("TEST-UNEXPECTED-FAIL | %s | leaked %d docShell(s) until "
"shutdown" %
(test["fileName"], len(test["leakedDocShells"])))
self.logger.info("TEST-INFO | %s | docShell(s) leaked: %s" %
(test["fileName"], ', '.join(["[pid = %s] [id = %s]" %
x for x in test["leakedDocShells"]]
)))

def _logWindow(self, line):
created = line[:2] == "++"
Expand Down Expand Up @@ -229,12 +233,14 @@ def log(self, line):

def process(self):
if self.fatalError:
self.logger.warning(
"TEST-UNEXPECTED-FAIL | LeakSanitizer | LeakSanitizer has encountered a fatal error.")
self.logger.warning("TEST-UNEXPECTED-FAIL | LeakSanitizer | LeakSanitizer "
"has encountered a fatal error.")

if self.foundFrames:
self.logger.info("TEST-INFO | LeakSanitizer | To show the addresses of leaked objects add report_objects=1 to LSAN_OPTIONS")
self.logger.info("TEST-INFO | LeakSanitizer | This can be done in testing/mozbase/mozrunner/mozrunner/utils.py")
self.logger.info("TEST-INFO | LeakSanitizer | To show the "
"addresses of leaked objects add report_objects=1 to LSAN_OPTIONS")
self.logger.info("TEST-INFO | LeakSanitizer | This can be done "
"in testing/mozbase/mozrunner/mozrunner/utils.py")

for f in self.foundFrames:
self.logger.warning(
Expand Down
4 changes: 2 additions & 2 deletions testing/mochitest/mach_commands.py
Expand Up @@ -9,7 +9,6 @@
from itertools import chain
import logging
import os
import shutil
import sys
import warnings

Expand Down Expand Up @@ -350,7 +349,8 @@ def verify_host_bin():
# validate MOZ_HOST_BIN environment variables for Android tests
MOZ_HOST_BIN = os.environ.get('MOZ_HOST_BIN')
if not MOZ_HOST_BIN:
print('environment variable MOZ_HOST_BIN must be set to a directory containing host xpcshell')
print('environment variable MOZ_HOST_BIN must be set to a directory containing host '
'xpcshell')
return 1
elif not os.path.isdir(MOZ_HOST_BIN):
print('$MOZ_HOST_BIN does not specify a directory')
Expand Down
12 changes: 6 additions & 6 deletions testing/mochitest/runrobocop.py
Expand Up @@ -376,9 +376,9 @@ def setupRobotiumConfig(self, browserEnv):
for key, value in browserEnv.items():
try:
value.index(',')
self.log.error(
"setupRobotiumConfig: browserEnv - Found a ',' in our value, unable to process value. key=%s,value=%s" %
(key, value))
self.log.error("setupRobotiumConfig: browserEnv - Found a ',' "
"in our value, unable to process value. key=%s,value=%s" %
(key, value))
self.log.error("browserEnv=%s" % browserEnv)
except ValueError:
envstr += "%s%s=%s" % (delim, key, value)
Expand Down Expand Up @@ -445,9 +445,9 @@ def runSingleTest(self, test):
# This does not launch a test at all. It launches an activity
# that starts Fennec and then waits indefinitely, since cat
# never returns.
browserArgs = ["start",
"-n", "org.mozilla.roboexample.test/org.mozilla.gecko.LaunchFennecWithConfigurationActivity",
"&&", "cat"]
browserArgs = ["start", "-n",
"org.mozilla.roboexample.test/org.mozilla."
"gecko.LaunchFennecWithConfigurationActivity", "&&", "cat"]
self.dm.default_timeout = sys.maxint # Forever.
self.log.info("")
self.log.info("Serving mochi.test Robocop root at http://%s:%s/tests/robocop/" %
Expand Down

0 comments on commit 58b6130

Please sign in to comment.