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 subprocess
import os
logging.getLogger(__name__).addHandler(logging.NullHandler())
class ADBrun(object):
binary = 'adbrun'
binary = "adbrun"
logger = logging.getLogger()
def launch(self):
# 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
os.system("sh launchSimScript.sh")

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

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

@ -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.
"""
import os
import csv
import yaml
import json
import os
import sys
import yaml
from yaml.loader import FullLoader
METRICS_FILENAME = "../app/metrics.yaml"
@ -24,7 +24,7 @@ write_header = True
# The number of soon to expired telemetry detected
total_count = 0
USAGE="""usage: ./{script_name} future_fenix_version_number"""
USAGE = """usage: ./{script_name} future_fenix_version_number"""
# list of values that we care about
_KEY_FILTER = [
@ -38,6 +38,7 @@ _KEY_FILTER = [
"expires",
]
def response(last_key, content, expire_version, writer, renewal):
global write_header
global total_count
@ -45,13 +46,15 @@ def response(last_key, content, expire_version, writer, renewal):
if (key == "$schema") or (key == "no_lint"):
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
if (key == "type"):
if key == "type":
remove_keys = []
for key in content.keys():
if (key not in _KEY_FILTER):
if key not in _KEY_FILTER:
remove_keys.append(key)
for key in remove_keys:
@ -60,16 +63,16 @@ def response(last_key, content, expire_version, writer, renewal):
total_count += 1
# name of the telemtry
result = {"#": total_count, "name" : last_key.lstrip('.')}
result = {"#": total_count, "name": last_key.lstrip(".")}
result.update(content)
# add columns for product to fille out, these should always be added at the end
result.update({"keep(Y/N)" : ""})
result.update({"new expiry version" : ""})
result.update({"reason to extend" : ""})
result.update({"keep(Y/N)": ""})
result.update({"new expiry version": ""})
result.update({"reason to extend": ""})
# output data-renewal request template
if (write_header):
if write_header:
header = result.keys()
writer.writerow(header)
write_header = False
@ -80,8 +83,10 @@ def response(last_key, content, expire_version, writer, renewal):
writer.writerow(result.values())
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("`" + last_key.lstrip(".") + "`:\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("\n")
renewal.write("2) When will this collection now expire?\n")
@ -96,11 +101,12 @@ def response(last_key, content, expire_version, writer, renewal):
if type(value) is dict:
response(last_key + "." + key, value, expire_version, writer, renewal)
with open(METRICS_FILENAME, 'r') as f:
with open(METRICS_FILENAME, "r") as f:
try:
arg1 = sys.argv[1]
except:
print ("usage is to include argument of the form `100`")
print("usage is to include argument of the form `100`")
quit()
# parse metrics.yaml to json
@ -127,9 +133,9 @@ with open(METRICS_FILENAME, 'r') as f:
print("remove old metrics yaml file")
os.remove(NEW_METRICS_FILENAME)
data_file = open(csv_filename, 'w')
data_file = open(csv_filename, "w")
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)
renewal_file.close()
@ -140,26 +146,33 @@ with open(METRICS_FILENAME, 'r') as f:
verify_count = 0
f.seek(0, 0)
data = f.readlines()
with open(NEW_METRICS_FILENAME, 'w') as f2:
with open(NEW_METRICS_FILENAME, "w") as f2:
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: ")
version = int(line.lstrip(' ')[start_pos:])
if (version <= current_version):
version = int(line.lstrip(" ")[start_pos:])
if version <= current_version:
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:
f2.writelines(line)
else:
f2.writelines(line)
f2.close()
print ("\n==============================")
if (total_count != verify_count):
print("\n==============================")
if total_count != verify_count:
print("!!! Count check failed !!!")
else:
print("Count check passed")
print ("==============================")
print("==============================")
os.remove(METRICS_FILENAME)
os.rename(NEW_METRICS_FILENAME, METRICS_FILENAME)

@ -15,18 +15,18 @@ import sys
try:
version = sys.argv[1]
except:
print ("usage is to include arguments of the form <version>")
print("usage is to include arguments of the form <version>")
quit()
expiry_filename = version + "_expiry_list.csv"
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 = ""
total_count = 0
updated_version = int(version) + 13
for row in csv_reader:
if row["keep(Y/N)"] == 'n':
if row["keep(Y/N)"] == "n":
continue
total_count += 1
output_string += f'` {row["name"]}`\n'
@ -35,7 +35,7 @@ for row in csv_reader:
output_string += "\n"
output_string += "2) When will this collection now expire?\n"
if len(row["new expiry version"]) == 0:
output_string += f' - {updated_version}\n'
output_string += f" - {updated_version}\n"
else:
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 += "### Renew for 1 year\n"
header += f'Total: {total_count}\n'
header += f"Total: {total_count}\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.close()

@ -2,50 +2,67 @@
# 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/.
import argparse
import os
import subprocess
import webbrowser
import os
import argparse
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)
"""
ff_browser = 'firefox'
target_directory = '{cwd}/app/build/'.format(cwd=os.getcwd())
output_path = '/storage/emulated/0/benchmark/'
output_file = 'org.mozilla.fenix-benchmarkData.json'
ff_browser = "firefox"
target_directory = "{cwd}/app/build/".format(cwd=os.getcwd())
output_path = "/storage/emulated/0/benchmark/"
output_file = "org.mozilla.fenix-benchmarkData.json"
file_url = "file:///"
def parse_args():
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument("class_to_test",
help="Path to the class to test. Format it as 'org.mozilla.fenix.[path_to_benchmark_test")
parser.add_argument("--open_file_in_browser",
help="Open the JSON file in the browser once the tests are done.")
parser.add_argument(
"class_to_test",
help="Path to the class to test. Format it as 'org.mozilla.fenix.[path_to_benchmark_test",
)
parser.add_argument(
"--open_file_in_browser",
help="Open the JSON file in the browser once the tests are done.",
)
return parser.parse_args()
def run_benchmark(class_to_test):
args = ['./gradlew', '-Pbenchmark', 'app:connectedCheck']
args = ["./gradlew", "-Pbenchmark", "app:connectedCheck"]
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)
def fetch_benchmark_results():
subprocess.run(
['adb', 'pull', "{path}{file}".format(path=output_path, file=output_file)],
cwd=target_directory, check=True, text=True)
print("The benchmark results can be seen here: {file_path}".format(
file_path=os.path.abspath("./{file}".format(file=file_url))))
["adb", "pull", "{path}{file}".format(path=output_path, file=output_file)],
cwd=target_directory,
check=True,
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():
abs_path = os.path.abspath("{target_directory}{file}".format(target_directory=target_directory,
file=output_file))
webbrowser.get(ff_browser).open_new(file_url+abs_path)
abs_path = os.path.abspath(
"{target_directory}{file}".format(
target_directory=target_directory, file=output_file
)
)
webbrowser.get(ff_browser).open_new(file_url + abs_path)
def main():
@ -56,5 +73,5 @@ def main():
open_in_browser()
if __name__ == '__main__':
if __name__ == "__main__":
main()

@ -11,7 +11,6 @@ from pathlib import Path
import requests
import yaml
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
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

Loading…
Cancel
Save