Skip to content

Commit

Permalink
[tools] Disallow unused variables (#11097)
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and gsnedders committed May 22, 2018
1 parent 84f0691 commit 7f994bd
Show file tree
Hide file tree
Showing 19 changed files with 18 additions and 35 deletions.
2 changes: 1 addition & 1 deletion tools/lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def check_git_ignore(repo_root, paths):
if filter_string[0] != '!':
errors += [("IGNORED PATH", "%s matches an ignore filter in .gitignore - "
"please add a .gitignore exception" % path, path, None)]
except subprocess.CalledProcessError as e:
except subprocess.CalledProcessError:
# Nonzero return code means that no match exists.
pass
return errors
Expand Down
6 changes: 3 additions & 3 deletions tools/lint/tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def test_all_filesystem_paths():
(os.path.join('.', 'dir_a'),
[],
['file_c', 'file_d'])]
) as m:
):
got = list(lint_mod.all_filesystem_paths('.'))
assert got == ['file_a',
'file_b',
Expand Down Expand Up @@ -438,7 +438,7 @@ def test_main_no_args():
try:
sys.argv = ['./lint']
with _mock_lint('lint', return_value=True) as m:
with _mock_lint('changed_files', return_value=['foo', 'bar']) as m2:
with _mock_lint('changed_files', return_value=['foo', 'bar']):
lint_mod.main(**vars(create_parser().parse_args()))
m.assert_called_once_with(repo_root, ['foo', 'bar'], "normal")
finally:
Expand All @@ -450,7 +450,7 @@ def test_main_all():
try:
sys.argv = ['./lint', '--all']
with _mock_lint('lint', return_value=True) as m:
with _mock_lint('all_filesystem_paths', return_value=['foo', 'bar']) as m2:
with _mock_lint('all_filesystem_paths', return_value=['foo', 'bar']):
lint_mod.main(**vars(create_parser().parse_args()))
m.assert_called_once_with(repo_root, ['foo', 'bar'], "normal")
finally:
Expand Down
2 changes: 1 addition & 1 deletion tools/serve/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def check_subdomains(config):

try:
urllib2.urlopen("http://%s:%d/" % (domain, port))
except Exception as e:
except Exception:
logger.critical("Failed probing domain %s. "
"You may need to edit /etc/hosts or similar, see README.md." % domain)
sys.exit(1)
Expand Down
3 changes: 1 addition & 2 deletions tools/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ select = E,W,F,N
# F401: module imported but unused
# F403: ‘from module import *’ used; unable to detect undefined names
# F405: name may be undefined, or defined from star imports: module
# F841: local variable name is assigned to but never used
# N801: class names should use CapWords convention
# N802: function name should be lowercase
ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,F841,N801,N802
ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,N801,N802
max-line-length = 141
exclude = .tox,html5lib,third_party/py,third_party/pytest,third_party/funcsigs,third_party/attrs,third_party/pluggy/,pywebsocket,six,_venv,webencodings,wptserve/docs,wptserve/tests/functional/docroot/,wpt,wptrunner
2 changes: 1 addition & 1 deletion tools/webdriver/webdriver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _get(self, key=None):

def _set(self, key, secs):
body = {key: secs * 1000}
timeouts = self.session.send_session_command("POST", "timeouts", body)
self.session.send_session_command("POST", "timeouts", body)
return None

@property
Expand Down
2 changes: 1 addition & 1 deletion tools/wpt/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def install(self, dest=None):

try:
mozinstall.install(filename, dest)
except mozinstall.mozinstall.InstallError as e:
except mozinstall.mozinstall.InstallError:
if platform == "mac" and os.path.exists(os.path.join(dest, "Firefox Nightly.app")):
# mozinstall will fail if nightly is already installed in the venv because
# mac installation uses shutil.copy_tree
Expand Down
3 changes: 1 addition & 2 deletions tools/wpt/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ select = E,W,F,N
# F401: module imported but unused
# F403: ‘from module import *’ used; unable to detect undefined names
# F405: name may be undefined, or defined from star imports: module
# F841: local variable name is assigned to but never used
# N801: class names should use CapWords convention
# N802: function name should be lowercase
ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,F841,N801,N802
ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,N801,N802
max-line-length = 141
2 changes: 1 addition & 1 deletion tools/wpt/wpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def parse_args(argv, commands):
parser.add_argument("--debug", action="store_true", help="Run the debugger in case of an exception")
subparsers = parser.add_subparsers(dest="command")
for command, props in iteritems(commands):
sub_parser = subparsers.add_parser(command, help=props["help"], add_help=False)
subparsers.add_parser(command, help=props["help"], add_help=False)

args, extra = parser.parse_known_args(argv)

Expand Down
2 changes: 1 addition & 1 deletion tools/wptrunner/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def read_config():
# This only allows one product per whatever for now
for product in parser.sections():
if product != "general":
dest = rv["products"][product] = {}
rv["products"][product] = {}
for key, value in parser.items(product):
rv["products"][product][key] = value

Expand Down
3 changes: 1 addition & 2 deletions tools/wptrunner/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ select = E,W,F,N
# F401: module imported but unused
# F403: ‘from module import *’ used; unable to detect undefined names
# F405: name may be undefined, or defined from star imports: module
# F841: local variable name is assigned to but never used
# N801: class names should use CapWords convention
# N802: function name should be lowercase
ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,F841,N801,N802
ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,N801,N802
max-line-length = 141
5 changes: 2 additions & 3 deletions tools/wptrunner/wptrunner/executors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ def logger(self):
return self.executor.logger

def get_hash(self, test, viewport_size, dpi):
timeout = test.timeout * self.timeout_multiplier
key = (test.url, viewport_size, dpi)

if key not in self.screenshot_cache:
Expand Down Expand Up @@ -391,7 +390,7 @@ def run(self):
executor = threading.Thread(target=self._run)
executor.start()

flag = self.result_flag.wait(self.timeout)
self.result_flag.wait(self.timeout)
if self.result[1] is None:
self.result = False, ("EXTERNAL-TIMEOUT", None)

Expand Down Expand Up @@ -533,7 +532,7 @@ def process_action(self, url, payload):
raise ValueError("Unknown action %s" % action)
try:
action_handler(payload)
except Exception as e:
except Exception:
self.logger.warning("Action %s failed" % action)
self.logger.warning(traceback.format_exc())
self._send_message("complete", "failure")
Expand Down
5 changes: 1 addition & 4 deletions tools/wptrunner/wptrunner/executors/executormarionette.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def run(self):
else:
wait_timeout = None

flag = self.result_flag.wait(wait_timeout)
self.result_flag.wait(wait_timeout)

if self.result == (None, None):
self.logger.debug("Timed out waiting for a result")
Expand Down Expand Up @@ -675,9 +675,6 @@ def setup(self, screenshot="unexpected"):
self.executor.protocol.marionette._send_message("reftest:setup", data)

def run_test(self, test):
viewport_size = test.viewport_size
dpi = test.dpi

references = self.get_references(test)
rv = self.executor.protocol.marionette._send_message("reftest:run",
{"test": self.executor.test_url(test),
Expand Down
1 change: 0 additions & 1 deletion tools/wptrunner/wptrunner/executors/executorservodriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def __init__(self, executor, browser, capabilities, **kwargs):

def connect(self):
"""Connect to browser via WebDriver."""
url = "http://%s:%d" % (self.host, self.port)
self.session = webdriver.Session(self.host, self.port,
extension=webdriver.servo.ServoCommandExtensions)
self.session.start()
Expand Down
2 changes: 0 additions & 2 deletions tools/wptrunner/wptrunner/manifestexpected.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ def value(ini_value):

try:
node_prefs = node.get("prefs")
if type(node_prefs) in (str, unicode):
prefs = {value(node_prefs)}
rv = dict(value(item) for item in node_prefs)
except KeyError:
rv = {}
Expand Down
2 changes: 0 additions & 2 deletions tools/wptrunner/wptrunner/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ def unexpected_changes(manifests, change_data, files_changed):
else:
return []

rv = []

return [fn for _, fn, _ in root_manifest if fn in files_changed and change_data.get(fn) != "M"]

# For each testrun
Expand Down
3 changes: 0 additions & 3 deletions tools/wptrunner/wptrunner/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ def products_enabled(config):
return names

def product_module(config, product):
here = os.path.join(os.path.split(__file__)[0])
product_dir = os.path.join(here, "browsers")

if product not in products_enabled(config):
raise ValueError("Unknown product %s" % product)

Expand Down
2 changes: 1 addition & 1 deletion tools/wptrunner/wptrunner/tests/test_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_server_start_config(product):
False,
None,
env_options,
env_extras) as test_environment:
env_extras):
start.assert_called_once()
args = start.call_args
config = args[0][0]
Expand Down
2 changes: 0 additions & 2 deletions tools/wptrunner/wptrunner/wptrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ def list_disabled(test_paths, product, **kwargs):
def list_tests(test_paths, product, **kwargs):
env.do_delayed_imports(logger, test_paths)

rv = []

ssl_env = env.ssl_env(logger, **kwargs)

run_info_extras = products.load_product(kwargs["config"], product)[-1](**kwargs)
Expand Down
4 changes: 2 additions & 2 deletions tools/wptserve/tests/functional/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class TestFileHandler(TestUsingServer):
def test_not_handled(self):
with self.assertRaises(HTTPError) as cm:
resp = self.request("/not_existing")
self.request("/not_existing")

self.assertEqual(cm.exception.code, 404)

Expand All @@ -36,7 +36,7 @@ def handler(request, response):
route = ("GET", "/test/raises", handler)
self.server.router.register(*route)
with self.assertRaises(HTTPError) as cm:
resp = self.request("/test/raises")
self.request("/test/raises")

self.assertEqual(cm.exception.code, 500)

Expand Down

0 comments on commit 7f994bd

Please sign in to comment.