Bug 1825116 - Resolve many black, isort, and file-whitespace lint issues

fenix/114.1.0
Geoff Brown 1 year ago committed by mergify[bot]
parent b83d16558d
commit 5692b4b13b

@ -1,16 +1,17 @@
import logging import logging
import subprocess
import os import os
logging.getLogger(__name__).addHandler(logging.NullHandler()) logging.getLogger(__name__).addHandler(logging.NullHandler())
class ADBrun(object): class ADBrun(object):
binary = 'adbrun' binary = "adbrun"
logger = logging.getLogger() logger = logging.getLogger()
def launch(self): def launch(self):
# First close sim if any then launch # First close sim if any then launch
os.system('~/Library/Android/sdk/platform-tools/adb devices | grep emulator | cut -f1 | while read line; do ~/Library/Android/sdk/platform-tools/adb -s $line emu kill; done') os.system(
"~/Library/Android/sdk/platform-tools/adb devices | grep emulator | cut -f1 | while read line; do ~/Library/Android/sdk/platform-tools/adb -s $line emu kill; done"
)
# Then launch sim # Then launch sim
os.system("sh launchSimScript.sh") os.system("sh launchSimScript.sh")

@ -2,89 +2,92 @@ import io
import json import json
import os import os
import time import time
import os.path as path
from mozdownload import DirectScraper, FactoryScraper
from mozprofile import Profile
import mozinstall import mozinstall
import mozversion import mozversion
import pytest import pytest
import requests import requests
from mozdownload import DirectScraper, FactoryScraper
from mozprofile import Profile
from .tps import TPS
from .gradlewbuild import GradlewBuild from .gradlewbuild import GradlewBuild
from .tps import TPS
here = os.path.dirname(__file__) here = os.path.dirname(__file__)
@pytest.fixture(scope='session')
@pytest.fixture(scope="session")
def firefox(pytestconfig, tmpdir_factory): def firefox(pytestconfig, tmpdir_factory):
binary = os.getenv('MOZREGRESSION_BINARY', binary = os.getenv("MOZREGRESSION_BINARY", pytestconfig.getoption("firefox"))
pytestconfig.getoption('firefox'))
if binary is None: if binary is None:
cache_dir = str(pytestconfig.cache.makedir('firefox')) cache_dir = str(pytestconfig.cache.makedir("firefox"))
scraper = FactoryScraper('daily', destination=cache_dir) scraper = FactoryScraper("daily", destination=cache_dir)
build_path = scraper.download() build_path = scraper.download()
install_path = str(tmpdir_factory.mktemp('firefox')) install_path = str(tmpdir_factory.mktemp("firefox"))
install_dir = mozinstall.install(src=build_path, dest=install_path) install_dir = mozinstall.install(src=build_path, dest=install_path)
binary = mozinstall.get_binary(install_dir, 'firefox') binary = mozinstall.get_binary(install_dir, "firefox")
version = mozversion.get_version(binary) version = mozversion.get_version(binary)
if hasattr(pytestconfig, '_metadata'): if hasattr(pytestconfig, "_metadata"):
pytestconfig._metadata.update(version) pytestconfig._metadata.update(version)
return binary return binary
@pytest.fixture @pytest.fixture
def firefox_log(pytestconfig, tmpdir): def firefox_log(pytestconfig, tmpdir):
firefox_log = str(tmpdir.join('firefox.log')) firefox_log = str(tmpdir.join("firefox.log"))
pytestconfig._firefox_log = firefox_log pytestconfig._firefox_log = firefox_log
yield firefox_log yield firefox_log
@pytest.fixture(scope='session') @pytest.fixture(scope="session")
def tps_addon(pytestconfig, tmpdir_factory): def tps_addon(pytestconfig, tmpdir_factory):
path = pytestconfig.getoption('tps') path = pytestconfig.getoption("tps")
if path is not None: if path is not None:
return path return path
task_url = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/' \ task_url = (
'gecko.v2.mozilla-central.latest.firefox.addons.tps' "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/"
task_id = requests.get(task_url).json().get('taskId') "gecko.v2.mozilla-central.latest.firefox.addons.tps"
cache_dir = str(pytestconfig.cache.makedir('tps-{}'.format(task_id))) )
addon_url = 'https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/' \ task_id = requests.get(task_url).json().get("taskId")
'{}/artifacts/public/tps.xpi'.format(task_id) cache_dir = str(pytestconfig.cache.makedir("tps-{}".format(task_id)))
addon_url = (
"https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/"
"{}/artifacts/public/tps.xpi".format(task_id)
)
scraper = DirectScraper(addon_url, destination=cache_dir) scraper = DirectScraper(addon_url, destination=cache_dir)
return scraper.download() return scraper.download()
@pytest.fixture @pytest.fixture
def tps_config(fxa_account, monkeypatch): def tps_config(fxa_account, monkeypatch):
monkeypatch.setenv('FXA_EMAIL', fxa_account.email) monkeypatch.setenv("FXA_EMAIL", fxa_account.email)
monkeypatch.setenv('FXA_PASSWORD', fxa_account.password) monkeypatch.setenv("FXA_PASSWORD", fxa_account.password)
# Go to resources folder # Go to resources folder
os.chdir('../../../../..') os.chdir("../../../../..")
resources = r'resources' resources = r"resources"
resourcesDir = os.path.join(os.getcwd(), resources) resourcesDir = os.path.join(os.getcwd(), resources)
with open (os.path.join(resourcesDir, 'email.txt'), "w") as f: with open(os.path.join(resourcesDir, "email.txt"), "w") as f:
f.write(fxa_account.email) f.write(fxa_account.email)
with open (os.path.join(resourcesDir, 'password.txt'), "w") as f: with open(os.path.join(resourcesDir, "password.txt"), "w") as f:
f.write(fxa_account.password) f.write(fxa_account.password)
# Set the path where tests are # Set the path where tests are
os.chdir('../') os.chdir("../")
currentDir = os.getcwd() currentDir = os.getcwd()
testsDir = currentDir + "/androidTest/java/org/mozilla/fenix/syncintegration" testsDir = currentDir + "/androidTest/java/org/mozilla/fenix/syncintegration"
os.chdir(testsDir) os.chdir(testsDir)
yield {'fx_account': { yield {
'username': fxa_account.email, "fx_account": {"username": fxa_account.email, "password": fxa_account.password}
'password': fxa_account.password}
} }
@pytest.fixture @pytest.fixture
def tps_log(pytestconfig, tmpdir): def tps_log(pytestconfig, tmpdir):
tps_log = str(tmpdir.join('tps.log')) tps_log = str(tmpdir.join("tps.log"))
pytestconfig._tps_log = tps_log pytestconfig._tps_log = tps_log
yield tps_log yield tps_log
@ -92,89 +95,98 @@ def tps_log(pytestconfig, tmpdir):
@pytest.fixture @pytest.fixture
def tps_profile(pytestconfig, tps_addon, tps_config, tps_log, fxa_urls): def tps_profile(pytestconfig, tps_addon, tps_config, tps_log, fxa_urls):
preferences = { preferences = {
'app.update.enabled': False, "app.update.enabled": False,
'browser.dom.window.dump.enabled': True, "browser.dom.window.dump.enabled": True,
'browser.onboarding.enabled': False, "browser.onboarding.enabled": False,
'browser.sessionstore.resume_from_crash': False, "browser.sessionstore.resume_from_crash": False,
'browser.shell.checkDefaultBrowser': False, "browser.shell.checkDefaultBrowser": False,
'browser.startup.homepage_override.mstone': 'ignore', "browser.startup.homepage_override.mstone": "ignore",
'browser.startup.page': 0, "browser.startup.page": 0,
'browser.tabs.warnOnClose': False, "browser.tabs.warnOnClose": False,
'browser.warnOnQuit': False, "browser.warnOnQuit": False,
'datareporting.policy.dataSubmissionEnabled': False, "datareporting.policy.dataSubmissionEnabled": False,
# 'devtools.chrome.enabled': True, # 'devtools.chrome.enabled': True,
# 'devtools.debugger.remote-enabled': True, # 'devtools.debugger.remote-enabled': True,
'engine.bookmarks.repair.enabled': False, "engine.bookmarks.repair.enabled": False,
'extensions.autoDisableScopes': 10, "extensions.autoDisableScopes": 10,
'extensions.experiments.enabled': True, "extensions.experiments.enabled": True,
'extensions.update.enabled': False, "extensions.update.enabled": False,
'extensions.update.notifyUser': False, "extensions.update.notifyUser": False,
# While this line is commented prod is launched instead of stage # While this line is commented prod is launched instead of stage
'identity.fxaccounts.autoconfig.uri': fxa_urls['content'], "identity.fxaccounts.autoconfig.uri": fxa_urls["content"],
'testing.tps.skipPingValidation': True, "testing.tps.skipPingValidation": True,
'services.sync.firstSync': 'notReady', "services.sync.firstSync": "notReady",
'services.sync.lastversion': '1.0', "services.sync.lastversion": "1.0",
'services.sync.log.appender.console': 'Trace', "services.sync.log.appender.console": "Trace",
'services.sync.log.appender.dump': 'Trace', "services.sync.log.appender.dump": "Trace",
'services.sync.log.appender.file.level': 'Trace', "services.sync.log.appender.file.level": "Trace",
'services.sync.log.appender.file.logOnSuccess': True, "services.sync.log.appender.file.logOnSuccess": True,
'services.sync.log.logger': 'Trace', "services.sync.log.logger": "Trace",
'services.sync.log.logger.engine': 'Trace', "services.sync.log.logger.engine": "Trace",
'services.sync.testing.tps': True, "services.sync.testing.tps": True,
'testing.tps.logFile': tps_log, "testing.tps.logFile": tps_log,
'toolkit.startup.max_resumed_crashes': -1, "toolkit.startup.max_resumed_crashes": -1,
'tps.config': json.dumps(tps_config), "tps.config": json.dumps(tps_config),
'tps.seconds_since_epoch': int(time.time()), "tps.seconds_since_epoch": int(time.time()),
'xpinstall.signatures.required': False "xpinstall.signatures.required": False,
} }
profile = Profile(addons=[tps_addon], preferences=preferences) profile = Profile(addons=[tps_addon], preferences=preferences)
pytestconfig._profile = profile.profile pytestconfig._profile = profile.profile
yield profile yield profile
@pytest.fixture @pytest.fixture
def tps(firefox, firefox_log, monkeypatch, pytestconfig, tps_log, tps_profile): def tps(firefox, firefox_log, monkeypatch, pytestconfig, tps_log, tps_profile):
yield TPS(firefox, firefox_log, tps_log, tps_profile) yield TPS(firefox, firefox_log, tps_log, tps_profile)
@pytest.fixture @pytest.fixture
def gradlewbuild_log(pytestconfig, tmpdir): def gradlewbuild_log(pytestconfig, tmpdir):
gradlewbuild_log = str(tmpdir.join('gradlewbuild.log')) gradlewbuild_log = str(tmpdir.join("gradlewbuild.log"))
pytestconfig._gradlewbuild_log = gradlewbuild_log pytestconfig._gradlewbuild_log = gradlewbuild_log
yield gradlewbuild_log yield gradlewbuild_log
@pytest.fixture @pytest.fixture
def gradlewbuild(fxa_account, monkeypatch, gradlewbuild_log): def gradlewbuild(fxa_account, monkeypatch, gradlewbuild_log):
monkeypatch.setenv('FXA_EMAIL', fxa_account.email) monkeypatch.setenv("FXA_EMAIL", fxa_account.email)
monkeypatch.setenv('FXA_PASSWORD', fxa_account.password) monkeypatch.setenv("FXA_PASSWORD", fxa_account.password)
yield GradlewBuild(gradlewbuild_log) yield GradlewBuild(gradlewbuild_log)
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption('--firefox', help='path to firefox binary (defaults to ' parser.addoption(
'downloading latest nightly build)') "--firefox",
parser.addoption('--tps', help='path to tps add-on (defaults to ' help="path to firefox binary (defaults to " "downloading latest nightly build)",
'downloading latest nightly build)') )
parser.addoption(
"--tps",
help="path to tps add-on (defaults to " "downloading latest nightly build)",
)
@pytest.mark.hookwrapper @pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call): def pytest_runtest_makereport(item, call):
outcome = yield outcome = yield
report = outcome.get_result() report = outcome.get_result()
extra = getattr(report, 'extra', []) extra = getattr(report, "extra", [])
pytest_html = item.config.pluginmanager.getplugin('html') pytest_html = item.config.pluginmanager.getplugin("html")
profile = getattr(item.config, '_profile', None) profile = getattr(item.config, "_profile", None)
if profile is not None and os.path.exists(profile): if profile is not None and os.path.exists(profile):
# add sync logs to HTML report # add sync logs to HTML report
for root, _, files in os.walk(os.path.join(profile, 'weave', 'logs')): for root, _, files in os.walk(os.path.join(profile, "weave", "logs")):
for f in files: for f in files:
path = os.path.join(root, f) path = os.path.join(root, f)
if pytest_html is not None: if pytest_html is not None:
with io.open(path, 'r', encoding='utf8') as f: with io.open(path, "r", encoding="utf8") as f:
extra.append(pytest_html.extras.text(f.read(), 'Sync')) extra.append(pytest_html.extras.text(f.read(), "Sync"))
report.sections.append(('Sync', 'Log: {}'.format(path))) report.sections.append(("Sync", "Log: {}".format(path)))
for log in ('Firefox', 'TPS', 'GradlewBuild'): for log in ("Firefox", "TPS", "GradlewBuild"):
attr = '_{}_log'.format(log.lower()) attr = "_{}_log".format(log.lower())
path = getattr(item.config, attr, None) path = getattr(item.config, attr, None)
if path is not None and os.path.exists(path): if path is not None and os.path.exists(path):
if pytest_html is not None: if pytest_html is not None:
with io.open(path, 'r', encoding='utf8') as f: with io.open(path, "r", encoding="utf8") as f:
extra.append(pytest_html.extras.text(f.read(), log)) extra.append(pytest_html.extras.text(f.read(), log))
report.sections.append((log, 'Log: {}'.format(path))) report.sections.append((log, "Log: {}".format(path)))
report.extra = extra report.extra = extra

@ -1,13 +1,13 @@
import os
import sys
def test_sync_account_settings(tps, gradlewbuild): def test_sync_account_settings(tps, gradlewbuild):
gradlewbuild.test('checkAccountSettings') gradlewbuild.test("checkAccountSettings")
def test_sync_history_from_desktop(tps, gradlewbuild): def test_sync_history_from_desktop(tps, gradlewbuild):
tps.run('test_history.js') tps.run("test_history.js")
gradlewbuild.test('checkHistoryFromDesktopTest') gradlewbuild.test("checkHistoryFromDesktopTest")
'''
"""
def test_sync_bookmark_from_desktop(tps, gradlewbuild): def test_sync_bookmark_from_desktop(tps, gradlewbuild):
tps.run('test_bookmark.js') tps.run('test_bookmark.js')
gradlewbuild.test('checkBookmarkFromDesktopTest') gradlewbuild.test('checkBookmarkFromDesktopTest')
@ -23,4 +23,4 @@ def test_sync_bookmark_from_device(tps, gradlewbuild):
def test_sync_history_from_device(tps, gradlewbuild): def test_sync_history_from_device(tps, gradlewbuild):
gradlewbuild.test('checkHistoryFromDeviceTest') gradlewbuild.test('checkHistoryFromDeviceTest')
tps.run('test_history_desktop.js') tps.run('test_history_desktop.js')
''' """

@ -90,4 +90,3 @@ We will experiment with writing new components using MVI unidirectional principl
Because all changes can be represented by a single, merged and serialized Observable or Flowable, we should be able to use this for debugging. All ViewStates, Changes, and Actions/Intents will be easily loggable to observe the causes of state issues. Because all changes can be represented by a single, merged and serialized Observable or Flowable, we should be able to use this for debugging. All ViewStates, Changes, and Actions/Intents will be easily loggable to observe the causes of state issues.
--- ---

@ -8,12 +8,12 @@ A script to help generate telemetry renewal csv and request template.
This script also modifies metrics.yaml to mark soon to expired telemetry entries. This script also modifies metrics.yaml to mark soon to expired telemetry entries.
""" """
import os
import csv import csv
import yaml
import json import json
import os
import sys import sys
import yaml
from yaml.loader import FullLoader from yaml.loader import FullLoader
METRICS_FILENAME = "../app/metrics.yaml" METRICS_FILENAME = "../app/metrics.yaml"
@ -38,6 +38,7 @@ _KEY_FILTER = [
"expires", "expires",
] ]
def response(last_key, content, expire_version, writer, renewal): def response(last_key, content, expire_version, writer, renewal):
global write_header global write_header
global total_count global total_count
@ -45,13 +46,15 @@ def response(last_key, content, expire_version, writer, renewal):
if (key == "$schema") or (key == "no_lint"): if (key == "$schema") or (key == "no_lint"):
continue continue
if ("expires" in value) and ((value["expires"] == "never") or (not value["expires"] <= expire_version)): if ("expires" in value) and (
(value["expires"] == "never") or (not value["expires"] <= expire_version)
):
continue continue
if (key == "type"): if key == "type":
remove_keys = [] remove_keys = []
for key in content.keys(): for key in content.keys():
if (key not in _KEY_FILTER): if key not in _KEY_FILTER:
remove_keys.append(key) remove_keys.append(key)
for key in remove_keys: for key in remove_keys:
@ -60,7 +63,7 @@ def response(last_key, content, expire_version, writer, renewal):
total_count += 1 total_count += 1
# name of the telemtry # name of the telemtry
result = {"#": total_count, "name" : last_key.lstrip('.')} result = {"#": total_count, "name": last_key.lstrip(".")}
result.update(content) result.update(content)
# add columns for product to fille out, these should always be added at the end # add columns for product to fille out, these should always be added at the end
@ -69,7 +72,7 @@ def response(last_key, content, expire_version, writer, renewal):
result.update({"reason to extend": ""}) result.update({"reason to extend": ""})
# output data-renewal request template # output data-renewal request template
if (write_header): if write_header:
header = result.keys() header = result.keys()
writer.writerow(header) writer.writerow(header)
write_header = False write_header = False
@ -80,8 +83,10 @@ def response(last_key, content, expire_version, writer, renewal):
writer.writerow(result.values()) writer.writerow(result.values())
renewal.write("`" + last_key.lstrip('.') + "`:\n") renewal.write("`" + last_key.lstrip(".") + "`:\n")
renewal.write("1) Provide a link to the initial Data Collection Review Request for this collection.\n") renewal.write(
"1) Provide a link to the initial Data Collection Review Request for this collection.\n"
)
renewal.write(" - " + content["data_reviews"][0] + "\n") renewal.write(" - " + content["data_reviews"][0] + "\n")
renewal.write("\n") renewal.write("\n")
renewal.write("2) When will this collection now expire?\n") renewal.write("2) When will this collection now expire?\n")
@ -96,7 +101,8 @@ def response(last_key, content, expire_version, writer, renewal):
if type(value) is dict: if type(value) is dict:
response(last_key + "." + key, value, expire_version, writer, renewal) response(last_key + "." + key, value, expire_version, writer, renewal)
with open(METRICS_FILENAME, 'r') as f:
with open(METRICS_FILENAME, "r") as f:
try: try:
arg1 = sys.argv[1] arg1 = sys.argv[1]
except: except:
@ -127,9 +133,9 @@ with open(METRICS_FILENAME, 'r') as f:
print("remove old metrics yaml file") print("remove old metrics yaml file")
os.remove(NEW_METRICS_FILENAME) os.remove(NEW_METRICS_FILENAME)
data_file = open(csv_filename, 'w') data_file = open(csv_filename, "w")
csv_writer = csv.writer(data_file) csv_writer = csv.writer(data_file)
renewal_file = open(renewal_filename, 'w') renewal_file = open(renewal_filename, "w")
response("", content, current_version, csv_writer, renewal_file) response("", content, current_version, csv_writer, renewal_file)
renewal_file.close() renewal_file.close()
@ -140,14 +146,21 @@ with open(METRICS_FILENAME, 'r') as f:
verify_count = 0 verify_count = 0
f.seek(0, 0) f.seek(0, 0)
data = f.readlines() data = f.readlines()
with open(NEW_METRICS_FILENAME, 'w') as f2: with open(NEW_METRICS_FILENAME, "w") as f2:
for line in data: for line in data:
if (line.lstrip(' ').startswith("expires: ") and not(line.lstrip(' ').startswith("expires: never"))): if line.lstrip(" ").startswith("expires: ") and not (
line.lstrip(" ").startswith("expires: never")
):
start_pos = len("expires: ") start_pos = len("expires: ")
version = int(line.lstrip(' ')[start_pos:]) version = int(line.lstrip(" ")[start_pos:])
if (version <= current_version): if version <= current_version:
verify_count += 1 verify_count += 1
f2.writelines(line.rstrip('\n') + " /* TODO <" + str(verify_count) + "> require renewal */\n") f2.writelines(
line.rstrip("\n")
+ " /* TODO <"
+ str(verify_count)
+ "> require renewal */\n"
)
else: else:
f2.writelines(line) f2.writelines(line)
else: else:
@ -155,7 +168,7 @@ with open(METRICS_FILENAME, 'r') as f:
f2.close() f2.close()
print("\n==============================") print("\n==============================")
if (total_count != verify_count): if total_count != verify_count:
print("!!! Count check failed !!!") print("!!! Count check failed !!!")
else: else:
print("Count check passed") print("Count check passed")

@ -21,12 +21,12 @@ except:
expiry_filename = version + "_expiry_list.csv" expiry_filename = version + "_expiry_list.csv"
filled_renewal_filename = version + "_filled_renewal_request.txt" filled_renewal_filename = version + "_filled_renewal_request.txt"
csv_reader = csv.DictReader(open(expiry_filename, 'r')) csv_reader = csv.DictReader(open(expiry_filename, "r"))
output_string = "" output_string = ""
total_count = 0 total_count = 0
updated_version = int(version) + 13 updated_version = int(version) + 13
for row in csv_reader: for row in csv_reader:
if row["keep(Y/N)"] == 'n': if row["keep(Y/N)"] == "n":
continue continue
total_count += 1 total_count += 1
output_string += f'` {row["name"]}`\n' output_string += f'` {row["name"]}`\n'
@ -35,7 +35,7 @@ for row in csv_reader:
output_string += "\n" output_string += "\n"
output_string += "2) When will this collection now expire?\n" output_string += "2) When will this collection now expire?\n"
if len(row["new expiry version"]) == 0: if len(row["new expiry version"]) == 0:
output_string += f' - {updated_version}\n' output_string += f" - {updated_version}\n"
else: else:
output_string += f' - {row["new expiry version"]}\n' output_string += f' - {row["new expiry version"]}\n'
@ -47,9 +47,9 @@ for row in csv_reader:
header = "# Request for Data Collection Renewal\n" header = "# Request for Data Collection Renewal\n"
header += "### Renew for 1 year\n" header += "### Renew for 1 year\n"
header += f'Total: {total_count}\n' header += f"Total: {total_count}\n"
header += "———\n\n" header += "———\n\n"
with open(filled_renewal_filename, 'w+') as out: with open(filled_renewal_filename, "w+") as out:
out.write(header + output_string) out.write(header + output_string)
out.close() out.close()

@ -2,49 +2,66 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/. # file, You can obtain one at https://mozilla.org/MPL/2.0/.
import argparse
import os
import subprocess import subprocess
import webbrowser import webbrowser
import os
import argparse
DESCRIPTION = """ This script is made to run benchmark tests on Fenix. It'll open DESCRIPTION = """ This script is made to run benchmark tests on Fenix. It'll open
the JSON output file in firefox (or another browser of your choice if you pass the string in) the JSON output file in firefox (or another browser of your choice if you pass the string in)
""" """
ff_browser = 'firefox' ff_browser = "firefox"
target_directory = '{cwd}/app/build/'.format(cwd=os.getcwd()) target_directory = "{cwd}/app/build/".format(cwd=os.getcwd())
output_path = '/storage/emulated/0/benchmark/' output_path = "/storage/emulated/0/benchmark/"
output_file = 'org.mozilla.fenix-benchmarkData.json' output_file = "org.mozilla.fenix-benchmarkData.json"
file_url = "file:///" file_url = "file:///"
def parse_args(): def parse_args():
parser = argparse.ArgumentParser(description=DESCRIPTION) parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument("class_to_test", parser.add_argument(
help="Path to the class to test. Format it as 'org.mozilla.fenix.[path_to_benchmark_test") "class_to_test",
parser.add_argument("--open_file_in_browser", help="Path to the class to test. Format it as 'org.mozilla.fenix.[path_to_benchmark_test",
help="Open the JSON file in the browser once the tests are done.") )
parser.add_argument(
"--open_file_in_browser",
help="Open the JSON file in the browser once the tests are done.",
)
return parser.parse_args() return parser.parse_args()
def run_benchmark(class_to_test): def run_benchmark(class_to_test):
args = ['./gradlew', '-Pbenchmark', 'app:connectedCheck'] args = ["./gradlew", "-Pbenchmark", "app:connectedCheck"]
if class_to_test: if class_to_test:
args.append("-Pandroid.testInstrumentationRunnerArguments.class={clazz}".format(clazz=class_to_test)) args.append(
"-Pandroid.testInstrumentationRunnerArguments.class={clazz}".format(
clazz=class_to_test
)
)
subprocess.run(args, check=True, text=True) subprocess.run(args, check=True, text=True)
def fetch_benchmark_results(): def fetch_benchmark_results():
subprocess.run( subprocess.run(
['adb', 'pull', "{path}{file}".format(path=output_path, file=output_file)], ["adb", "pull", "{path}{file}".format(path=output_path, file=output_file)],
cwd=target_directory, check=True, text=True) cwd=target_directory,
print("The benchmark results can be seen here: {file_path}".format( check=True,
file_path=os.path.abspath("./{file}".format(file=file_url)))) text=True,
)
print(
"The benchmark results can be seen here: {file_path}".format(
file_path=os.path.abspath("./{file}".format(file=file_url))
)
)
def open_in_browser(): def open_in_browser():
abs_path = os.path.abspath("{target_directory}{file}".format(target_directory=target_directory, abs_path = os.path.abspath(
file=output_file)) "{target_directory}{file}".format(
target_directory=target_directory, file=output_file
)
)
webbrowser.get(ff_browser).open_new(file_url + abs_path) webbrowser.get(ff_browser).open_new(file_url + abs_path)
@ -56,5 +73,5 @@ def main():
open_in_browser() open_in_browser()
if __name__ == '__main__': if __name__ == "__main__":
main() main()

@ -11,7 +11,6 @@ from pathlib import Path
import requests import requests
import yaml import yaml
LICENSE_HEADER = """# This Source Code Form is subject to the terms of the Mozilla Public LICENSE_HEADER = """# 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 # 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/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.

Loading…
Cancel
Save