Skip to content

Commit

Permalink
Bug 1681096 - python3 - pylint --py3k - W1619: from __future__ import…
Browse files Browse the repository at this point in the history
… division r=marionette-reviewers,perftest-reviewers,gbrown

Differential Revision: https://phabricator.services.mozilla.com/D98938
  • Loading branch information
Bob Clary committed Dec 11, 2020
1 parent 0f5d571 commit 3a131c2
Show file tree
Hide file tree
Showing 42 changed files with 117 additions and 41 deletions.
5 changes: 4 additions & 1 deletion testing/awsy/awsy/process_perf_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import, print_function
from __future__ import absolute_import, division, print_function

import os
import sys
Expand Down Expand Up @@ -54,10 +54,12 @@

def median(values):
sorted_ = sorted(values)
# pylint --py3k W1619
med = int(len(sorted_) / 2)

if len(sorted_) % 2:
return sorted_[med]
# pylint --py3k W1619
return (sorted_[med - 1] + sorted_[med]) / 2


Expand Down Expand Up @@ -173,6 +175,7 @@ def create_suite(

# Add the geometric mean. For more details on the calculation see:
# https://en.wikipedia.org/wiki/Geometric_mean#Relationship_with_arithmetic_mean_of_logarithms
# pylint --py3k W1619
suite["value"] = math.exp(total / len(checkpoints))

return suite
Expand Down
4 changes: 3 additions & 1 deletion testing/condprofile/condprof/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""

from __future__ import absolute_import
from __future__ import absolute_import, division

import sys
import time
Expand Down Expand Up @@ -92,6 +92,7 @@ def show(self, progress, count=None):
self.last_progress = progress
if (time.time() - self.etadelta) > ETA_INTERVAL:
self.etadelta = time.time()
# pylint --py3k W1619
self.ittimes = self.ittimes[-ETA_SMA_WINDOW:] + [
-(self.start - time.time()) / (progress + 1)
]
Expand All @@ -101,6 +102,7 @@ def show(self, progress, count=None):
* (self.expected_size - progress)
)
self.etadisp = self.format_time(self.eta)
# pylint --py3k W1619
x = int(self.width * progress / self.expected_size)
if not self.hide:
if (progress % self.every) == 0 or ( # True every "every" updates
Expand Down
4 changes: 2 additions & 2 deletions testing/condprofile/condprof/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#
# This module needs to stay Python 2 and 3 compatible
#
from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, division, print_function

import platform
import time
Expand Down Expand Up @@ -245,6 +244,7 @@ def download_file(url, target=None):
f.flush()
else:
iter = req.iter_content(chunk_size=1024)
# pylint --py3k W1619
size = total_length / 1024 + 1
for chunk in progress.bar(iter, expected_size=size):
if chunk:
Expand Down
4 changes: 2 additions & 2 deletions testing/gtest/bench.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

from __future__ import print_function

from __future__ import division, print_function
import sys
import subprocess
import json
Expand All @@ -13,6 +12,7 @@
data = json.loads(line[len("PERFHERDER_DATA:") :].decode("utf8"))
for suite in data["suites"]:
for subtest in suite["subtests"]:
# pylint --py3k W1619
print(
"%4d.%03d ± %6s ms %s.%s"
% (
Expand Down
6 changes: 5 additions & 1 deletion testing/jsshell/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import, print_function
from __future__ import absolute_import, division, print_function

import json
import os
Expand Down Expand Up @@ -137,6 +137,7 @@ def collect_results(self):
for bench, scores in self.scores.items():
for score, values in scores.items():
test_name = "{}-{}".format(self.name, score)
# pylint --py3k W1619
mean = sum(values) / len(values)
self.suite["subtests"].append({"name": test_name, "value": mean})
bench_total += int(sum(values))
Expand Down Expand Up @@ -193,6 +194,7 @@ def process_line(self, line):
def collect_results(self):
for bench, scores in self.scores.items():
for score, values in scores.items():
# pylint --py3k W1619
mean = sum(values) / len(values)
test_name = "{}-{}".format(bench, score)
self.suite["subtests"].append({"name": test_name, "value": mean})
Expand Down Expand Up @@ -296,6 +298,7 @@ def collect_results(self):
for bench, scores in self.scores.items():
for score_name, values in scores.items():
test_name = "{}-{}".format(self.name, score_name)
# pylint --py3k W1619
mean = sum(values) / len(values)
self.suite["subtests"].append(
{
Expand Down Expand Up @@ -348,6 +351,7 @@ def collect_results(self):
for bench, scores in self.scores.items():
for score_name, values in scores.items():
test_name = "{}-{}".format(self.name, score_name)
# pylint --py3k W1619
mean = sum(values) / len(values)
self.suite["subtests"].append({"name": test_name, "value": mean})
if score_name == "score":
Expand Down
4 changes: 3 additions & 1 deletion testing/marionette/client/marionette_driver/gestures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import
from __future__ import absolute_import, division

from .legacy_actions import MultiActions, Actions

Expand Down Expand Up @@ -70,6 +70,7 @@ def pinch(marionette_session, element, x1, y1, x2, y2, x3, y3, x4, y4, duration=
time_increment = 10
if time_increment >= duration:
time_increment = duration
# pylint --py3k W1619
move_x1 = time_increment * 1.0 / duration * (x3 - x1)
move_y1 = time_increment * 1.0 / duration * (y3 - y1)
move_x2 = time_increment * 1.0 / duration * (x4 - x2)
Expand All @@ -81,6 +82,7 @@ def pinch(marionette_session, element, x1, y1, x2, y2, x3, y3, x4, y4, duration=
action2.press(element, x2, y2)
while time < duration:
time += time_increment
# pylint --py3k W1619
action1.move_by_offset(move_x1, move_y1).wait(time_increment / 1000)
action2.move_by_offset(move_x2, move_y2).wait(time_increment / 1000)
action1.release()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import
from __future__ import absolute_import, division

from . import errors
from .marionette import MouseButton
Expand Down Expand Up @@ -218,12 +218,14 @@ def flick(self, element, x1, y1, x2, y2, duration=200):
time_increment = 10
if time_increment >= duration:
time_increment = duration
# pylint --py3k W1619
move_x = time_increment * 1.0 / duration * (x2 - x1)
move_y = time_increment * 1.0 / duration * (y2 - y1)
self.action_chain.append(["press", element, x1, y1])
while elapsed < duration:
elapsed += time_increment
self.action_chain.append(["moveByOffset", move_x, move_y])
# pylint --py3k W1619
self.action_chain.append(["wait", time_increment / 1000])
self.action_chain.append(["release"])
return self
Expand Down
3 changes: 2 additions & 1 deletion testing/marionette/client/marionette_driver/marionette.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import
from __future__ import absolute_import, division

import base64
import datetime
Expand Down Expand Up @@ -1195,6 +1195,7 @@ def start_session(self, capabilities=None, timeout=None):

timeout = self.session.get("moz:shutdownTimeout")
if timeout is not None:
# pylint --py3k W1619
self.shutdown_timeout = timeout / 1000 + 10

return self.session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import
from __future__ import absolute_import, division

from six.moves.urllib.parse import quote

Expand Down Expand Up @@ -45,6 +45,7 @@ def click_position(self):
)

def get_element_center_point(self, elem):
# pylint --py3k W1619
return {
"x": elem.rect["x"] + elem.rect["width"] / 2,
"y": elem.rect["y"] + elem.rect["height"] / 2,
Expand Down
3 changes: 2 additions & 1 deletion testing/mochitest/bisection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function
from __future__ import division, print_function

import math
import mozinfo
Expand Down Expand Up @@ -139,6 +139,7 @@ def next_chunk_binary(self, options, status):
self.contents["start"] = 0
self.contents["end"] = totalTests - 2

# pylint --py3k W1619
mid = (self.contents["start"] + self.contents["end"]) / 2
if "result" in self.contents:
if self.contents["result"] == "PASS":
Expand Down
3 changes: 3 additions & 0 deletions testing/mochitest/leaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# The content of this file comes orginally from automationutils.py
# and *should* be revised.

from __future__ import division

import re
from operator import itemgetter

Expand Down Expand Up @@ -153,6 +155,7 @@ def process(self):
# Note: to figure out how many hidden windows were created, we divide
# this number by 2, because 1 hidden window creation implies in
# 1 outer window + 1 inner window.
# pylint --py3k W1619
self.logger.info(
"TEST-INFO | %s | This test created %d hidden window(s)"
% (test["fileName"], test["hiddenWindowsCount"] / 2)
Expand Down
4 changes: 4 additions & 0 deletions testing/mochitest/pywebsocket3/mod_pywebsocket/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
http://tools.ietf.org/html/rfc6455
"""

from __future__ import division

from collections import deque
import logging
import os
Expand Down Expand Up @@ -272,6 +274,7 @@ def parse_frame(receive_bytes,
raw_payload_bytes = receive_bytes(payload_length)

if logger.isEnabledFor(common.LOGLEVEL_FINE):
# pylint --py3k W1619
logger.log(
common.LOGLEVEL_FINE, 'Done receiving payload data at %s MB/s',
payload_length / (time.time() - receive_start) / 1000 / 1000)
Expand All @@ -283,6 +286,7 @@ def parse_frame(receive_bytes,
unmasked_bytes = masker.mask(raw_payload_bytes)

if logger.isEnabledFor(common.LOGLEVEL_FINE):
# pylint --py3k W1619
logger.log(common.LOGLEVEL_FINE,
'Done unmasking payload data at %s MB/s',
payload_length / (time.time() - unmask_start) / 1000 / 1000)
Expand Down
3 changes: 2 additions & 1 deletion testing/mochitest/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Runs the Mochitest test harness.
"""

from __future__ import print_function, with_statement
from __future__ import division, print_function, with_statement
import os
import sys

Expand Down Expand Up @@ -357,6 +357,7 @@ def dump_buffered(self, limit=False):

last_timestamp = None
for buf in dumped_messages:
# pylint --py3k W1619
timestamp = datetime.fromtimestamp(buf["time"] / 1000).strftime("%H:%M:%S")
if timestamp != last_timestamp:
self.logger.info("Buffered messages logged at {}".format(timestamp))
Expand Down
4 changes: 3 additions & 1 deletion testing/mozbase/manifestparser/manifestparser/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
possible to define custom filters if the built-in ones are not enough.
"""

from __future__ import absolute_import
from __future__ import absolute_import, division

import itertools
import os
Expand Down Expand Up @@ -362,6 +362,7 @@ def get_chunked_manifests(self, manifests):

# Compute the average to use as a default for manifests that don't exist.
times = [r[0] for r in runtimes]
# pylint --py3k W1619
avg = round(sum(times) / len(times), 2) if times else 0
missing = sorted([m for m in manifests if m not in self.runtimes])
log(
Expand Down Expand Up @@ -392,6 +393,7 @@ def __call__(self, tests, values):
manifests = set(self.get_manifest(t) for t in tests)
chunks = self.get_chunked_manifests(manifests)
runtime, this_manifests = chunks[self.this_chunk - 1]
# pylint --py3k W1619
log(
"Cumulative test runtime is around {} minutes (average is {} minutes)".format(
round(runtime / 60),
Expand Down
3 changes: 2 additions & 1 deletion testing/mozbase/mozdevice/mozdevice/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import, print_function
from __future__ import absolute_import, division, print_function

import io
import os
Expand Down Expand Up @@ -3401,6 +3401,7 @@ def get_battery_percentage(self, timeout=None):
elif parameter == "scale":
scale = float(value)
if parameter is not None and scale is not None:
# pylint --py3k W1619
percentage = 100.0 * level / scale
break
return percentage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import
from __future__ import absolute_import, division

import hashlib
import os
Expand Down Expand Up @@ -312,6 +312,7 @@ def _get_containing_library(self, address, libs):
left = 0
right = len(libs) - 1
while left <= right:
# pylint --py3k W1619
mid = (left + right) / 2
if address >= libs[mid]["end"]:
left = mid + 1
Expand Down
3 changes: 2 additions & 1 deletion testing/mozbase/mozlog/mozlog/formatters/tbplformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import
from __future__ import absolute_import, division

import functools
from collections import deque
Expand Down Expand Up @@ -307,6 +307,7 @@ def test_end(self, data):

def suite_end(self, data):
start_time = self.suite_start_time
# pylint --py3k W1619
time = int((data["time"] - start_time) / 1000)

return "SUITE-END | took %is\n" % time
Expand Down
3 changes: 2 additions & 1 deletion testing/mozbase/mozlog/mozlog/formatters/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


from __future__ import absolute_import
from __future__ import absolute_import, division

from . import base

Expand Down Expand Up @@ -78,6 +78,7 @@ def output_errors(self):
return "\n".join("ERROR %(test)s\n%(message)s" % data for data in self.errors)

def output_summary(self):
# pylint --py3k W1619
return "Ran %i tests in %.1fs" % (
self.tests_run,
(self.end_time - self.start_time) / 1000,
Expand Down
Loading

0 comments on commit 3a131c2

Please sign in to comment.