Bug 1825116 - Reformat some python files with black and avoid 'bare except' ruff warnings

fenix/117.0
Geoff Brown 10 months ago committed by mergify[bot]
parent e8b0f5879f
commit 735db97731

@ -9,7 +9,7 @@ logging.getLogger(__name__).addHandler(logging.NullHandler())
class GradlewBuild(object):
binary = './gradlew'
binary = "./gradlew"
logger = logging.getLogger()
adbrun = ADBrun()
@ -20,17 +20,19 @@ class GradlewBuild(object):
self.adbrun.launch()
# Change path accordingly to go to root folder to run gradlew
os.chdir('../../../../../../../..')
cmd = './gradlew ' + 'app:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=org.mozilla.fenix.syncintegration.SyncIntegrationTest#{}'.format(identifier)
os.chdir("../../../../../../../..")
cmd = (
"./gradlew "
+ "app:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=org.mozilla.fenix.syncintegration.SyncIntegrationTest#{}".format(
identifier
)
)
self.logger.info('Running cmd: {}'.format(cmd))
self.logger.info("Running cmd: {}".format(cmd))
out = ""
try:
out = subprocess.check_output(
cmd,
shell=True,
stderr=subprocess.STDOUT)
out = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
out = e.output
raise
@ -39,5 +41,5 @@ class GradlewBuild(object):
testsPath = "app/src/androidTest/java/org/mozilla/fenix/syncintegration/"
os.chdir(testsPath)
with open(self.log, 'w') as f:
with open(self.log, "w") as f:
f.write(str(out))

@ -13,39 +13,42 @@ class TPS(object):
def __init__(self, firefox, firefox_log, tps_log, profile):
self.firefox = firefox
self.firefox_log = open(firefox_log, 'w')
self.firefox_log = open(firefox_log, "w")
self.tps_log = tps_log
self.profile = profile
def _log(self, line):
self.firefox_log.write(line + '\n')
def run(self, test, phase='phase1', ignore_unused_engines=True):
self.profile.set_preferences({
'testing.tps.testFile': os.path.abspath(test),
'testing.tps.testPhase': phase,
'testing.tps.ignoreUnusedEngines': ignore_unused_engines,
})
args = ['-marionette']
process_args = {'processOutputLine': [self._log]}
self.logger.info('Running: {} {}'.format(self.firefox, ' '.join(args)))
self.logger.info('Using profile at: {}'.format(self.profile.profile))
self.firefox_log.write(line + "\n")
def run(self, test, phase="phase1", ignore_unused_engines=True):
self.profile.set_preferences(
{
"testing.tps.testFile": os.path.abspath(test),
"testing.tps.testPhase": phase,
"testing.tps.ignoreUnusedEngines": ignore_unused_engines,
}
)
args = ["-marionette"]
process_args = {"processOutputLine": [self._log]}
self.logger.info("Running: {} {}".format(self.firefox, " ".join(args)))
self.logger.info("Using profile at: {}".format(self.profile.profile))
runner = FirefoxRunner(
binary=self.firefox,
cmdargs=args,
profile=self.profile,
process_args=process_args)
process_args=process_args,
)
runner.start(timeout=TIMEOUT)
runner.wait(timeout=TIMEOUT)
self.firefox_log.close()
with open(self.tps_log) as f:
for line in f.readlines():
if 'CROSSWEAVE ERROR: ' in line:
raise TPSError(line.partition('CROSSWEAVE ERROR: ')[-1])
if "CROSSWEAVE ERROR: " in line:
raise TPSError(line.partition("CROSSWEAVE ERROR: ")[-1])
with open(self.tps_log) as f:
assert 'test phase {}: PASS'.format(phase) in f.read()
assert "test phase {}: PASS".format(phase) in f.read()
class TPSError(Exception):

@ -56,12 +56,18 @@ def main():
print("| --- | --- | --- | --- |\n")
for matrix, matrix_result in matrix_ids.items():
for axis in matrix_result["axes"]:
print(f"| {matrix_result['matrixId']} | {matrix_result['outcome']}"
f"| [Firebase Test Lab]({matrix_result['webLink']}) | {axis['details']}\n")
print(
f"| {matrix_result['matrixId']} | {matrix_result['outcome']}"
f"| [Firebase Test Lab]({matrix_result['webLink']}) | {axis['details']}\n"
)
print("---\n")
print("# References & Documentation\n")
print("* [Automated UI Testing Documentation](https://github.com/mozilla-mobile/shared-docs/blob/main/android/ui-testing.md)\n")
print("* Mobile Test Engineering on [Mana](https://mana.mozilla.org/wiki/display/MTE/Mobile+Test+Engineering) | [Slack](https://mozilla.slack.com/archives/C02KDDS9QM9) | [Alerts](https://mozilla.slack.com/archives/C0134KJ4JHL)\n")
print(
"* [Automated UI Testing Documentation](https://github.com/mozilla-mobile/shared-docs/blob/main/android/ui-testing.md)\n"
)
print(
"* Mobile Test Engineering on [Mana](https://mana.mozilla.org/wiki/display/MTE/Mobile+Test+Engineering) | [Slack](https://mozilla.slack.com/archives/C02KDDS9QM9) | [Alerts](https://mozilla.slack.com/archives/C0134KJ4JHL)\n"
)
if __name__ == "__main__":

@ -65,8 +65,14 @@ def response(last_key, content, expire_version, writer, renewal):
total_count += 1
# name of the telemtry
dictionary_url = GLEAN_DICTIONARY_PREFIX + last_key.lstrip(".").replace(".", "_")
result = {"#": total_count, "name": last_key.lstrip("."), "glean dictionary": dictionary_url}
dictionary_url = GLEAN_DICTIONARY_PREFIX + last_key.lstrip(".").replace(
".", "_"
)
result = {
"#": total_count,
"name": last_key.lstrip("."),
"glean dictionary": dictionary_url,
}
result.update(content)
# add columns for product to fille out, these should always be added at the end
@ -108,7 +114,7 @@ def response(last_key, content, expire_version, writer, renewal):
with open(METRICS_FILENAME, "r") as f:
try:
arg1 = sys.argv[1]
except:
except Exception:
print("usage is to include argument of the form `100`")
quit()

@ -14,7 +14,7 @@ import sys
try:
version = sys.argv[1]
except:
except Exception:
print("usage is to include arguments of the form <version>")
quit()

@ -14,32 +14,53 @@ import os
import tempfile
from subprocess import run
PATH_PREFIX = '/data/local/tmp'
PATH_PREFIX = "/data/local/tmp"
PROD_FENIX = 'fenix'
PROD_GVE = 'geckoview_example'
PROD_FENIX = "fenix"
PROD_GVE = "geckoview_example"
PRODUCTS = [PROD_FENIX, PROD_GVE]
GV_CONFIG = b'''env:
GV_CONFIG = b"""env:
MOZ_PROFILER_STARTUP: 1
MOZ_PROFILER_STARTUP_INTERVAL: 5
MOZ_PROFILER_STARTUP_FEATURES: js,stackwalk,leaf,screenshots,ipcmessages,java,cpu
MOZ_PROFILER_STARTUP_FILTERS: GeckoMain,Compositor,Renderer,IPDL Background
'''
"""
def parse_args():
p = argparse.ArgumentParser(
description=("Easily enable start up profiling using the Firefox Profiler. Finish capturing the profile in "
"about:debugging on desktop. See "
"https://profiler.firefox.com/docs/#/./guide-remote-profiling?id=startup-profiling for "
"details."))
p.add_argument('command', choices=['activate', 'deactivate'], help=("whether to activate or deactive start up "
"profiling for the given release channel"))
p.add_argument('release_channel', choices=['nightly', 'beta', 'release', 'debug'], help=("the release channel to "
"change the startup profiling state of the command on"))
p.add_argument('-p', '--product', choices=PRODUCTS, default=PROD_FENIX, help="which product to work on")
description=(
"Easily enable start up profiling using the Firefox Profiler. Finish capturing the profile in "
"about:debugging on desktop. See "
"https://profiler.firefox.com/docs/#/./guide-remote-profiling?id=startup-profiling for "
"details."
)
)
p.add_argument(
"command",
choices=["activate", "deactivate"],
help=(
"whether to activate or deactive start up "
"profiling for the given release channel"
),
)
p.add_argument(
"release_channel",
choices=["nightly", "beta", "release", "debug"],
help=(
"the release channel to "
"change the startup profiling state of the command on"
),
)
p.add_argument(
"-p",
"--product",
choices=PRODUCTS,
default=PROD_FENIX,
help="which product to work on",
)
return p.parse_args()
@ -51,48 +72,52 @@ def push(id, filename):
with config.file as f:
f.write(GV_CONFIG)
print('Pushing {} to device.'.format(filename))
run(['adb', 'push', config.name, os.path.join(PATH_PREFIX, filename)])
run(['adb', 'shell', 'am', 'set-debug-app', '--persistent', id])
print('\nStartup profiling enabled on all future start ups, possibly even after reinstall.')
print('Call script with `deactivate` to disable it.')
print('DISABLE \'Remote debugging via USB\' IN THE APP SETTINGS BEFORE STARTING THE APP & RE-ENABLE TO CAPTURE THE PROFILE.',
'This avoids the additional overhead added when \'Remote debugging via USB\' is enabled during start up.',
sep=os.linesep)
print("Pushing {} to device.".format(filename))
run(["adb", "push", config.name, os.path.join(PATH_PREFIX, filename)])
run(["adb", "shell", "am", "set-debug-app", "--persistent", id])
print(
"\nStartup profiling enabled on all future start ups, possibly even after reinstall."
)
print("Call script with `deactivate` to disable it.")
print(
"DISABLE 'Remote debugging via USB' IN THE APP SETTINGS BEFORE STARTING THE APP & RE-ENABLE TO CAPTURE THE PROFILE.",
"This avoids the additional overhead added when 'Remote debugging via USB' is enabled during start up.",
sep=os.linesep,
)
finally:
os.remove(config.name)
def remove(filename):
print('Removing {} from device.'.format(filename))
run(['adb', 'shell', 'rm', PATH_PREFIX + '/' + filename])
run(['adb', 'shell', 'am', 'clear-debug-app'])
print("Removing {} from device.".format(filename))
run(["adb", "shell", "rm", PATH_PREFIX + "/" + filename])
run(["adb", "shell", "am", "clear-debug-app"])
def convert_channel_to_id(product, channel):
if product == PROD_FENIX:
mapping = {
'release': 'org.mozilla.firefox',
'beta': 'org.mozilla.firefox_beta',
'nightly': 'org.mozilla.fenix',
'debug': 'org.mozilla.fenix.debug'
"release": "org.mozilla.firefox",
"beta": "org.mozilla.firefox_beta",
"nightly": "org.mozilla.fenix",
"debug": "org.mozilla.fenix.debug",
}
return mapping[channel]
elif product == PROD_GVE:
return 'org.mozilla.geckoview_example'
return "org.mozilla.geckoview_example"
def main():
args = parse_args()
id = convert_channel_to_id(args.product, args.release_channel)
filename = id + '-geckoview-config.yaml'
filename = id + "-geckoview-config.yaml"
if args.command == 'activate':
if args.command == "activate":
push(id, filename)
elif args.command == 'deactivate':
elif args.command == "deactivate":
remove(filename)
if __name__ == '__main__':
if __name__ == "__main__":
main()

Loading…
Cancel
Save