Bug 1825116 - fix python formatting issues in firefox-android scripts. r=bhearsum,amejiamarmol,geckoview-reviewers,releng-reviewers

Generated by
`./mach lint -l black --fix taskcluster/android_taskgraph/ taskcluster/scripts/lint/ taskcluster/scripts/write-dummy-secret.py mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/conftest.py mobile/android/fenix/automation/taskcluster/androidTest/parse-ui-test-fromfile.py mobile/android/focus-android/automation/taskcluster/androidTest/parse-ui-test*`

Differential Revision: https://phabricator.services.mozilla.com/D201457
This commit is contained in:
Julien Cristau 2023-09-07 13:38:12 +02:00
Родитель 9a7f9a7446
Коммит 5c031db2bc
17 изменённых файлов: 151 добавлений и 70 удалений

Просмотреть файл

@ -10,10 +10,14 @@ from junitparser import Attr, Failure, JUnitXml, TestSuite
def parse_args(cmdln_args):
parser = argparse.ArgumentParser(description="Parse and print UI test JUnit results")
parser = argparse.ArgumentParser(
description="Parse and print UI test JUnit results"
)
parser.add_argument(
"--results", type=Path,
help="Directory containing task artifact results", required=True
"--results",
type=Path,
help="Directory containing task artifact results",
required=True,
)
return parser.parse_args(args=cmdln_args)
@ -24,25 +28,35 @@ class test_suite(TestSuite):
def parse_print_failure_results(results):
table = BeautifulTable(maxwidth=256)
table.columns.header = (['UI Test', 'Outcome', 'Details'])
table.columns.header = ["UI Test", "Outcome", "Details"]
table.columns.alignment = BeautifulTable.ALIGN_LEFT
table.set_style(BeautifulTable.STYLE_GRID)
for suite in results:
cur_suite = test_suite.fromelem(suite)
if cur_suite.flakes != '0':
if cur_suite.flakes != "0":
for case in suite:
for entry in case.result:
if case.result:
table.rows.append(
["%s#%s" % (case.classname, case.name), "Flaky", entry.text.replace('\t', ' ')])
[
"%s#%s" % (case.classname, case.name),
"Flaky",
entry.text.replace("\t", " "),
]
)
break
else:
for case in suite:
for entry in case.result:
if isinstance(entry, Failure):
table.rows.append(
["%s#%s" % (case.classname, case.name), "Failure", entry.text.replace('\t', ' ')])
[
"%s#%s" % (case.classname, case.name),
"Failure",
entry.text.replace("\t", " "),
]
)
break
print(table)
@ -50,11 +64,11 @@ def parse_print_failure_results(results):
def load_results_file(filename):
ret = None
try:
f = open(filename, 'r')
f = open(filename, "r")
try:
ret = JUnitXml.fromfile(f)
except xml.etree.ElementTree.ParseError as e:
print(f'Error parsing {filename} file: {e}')
print(f"Error parsing {filename} file: {e}")
finally:
f.close()
except IOError as e:
@ -66,10 +80,10 @@ def load_results_file(filename):
def main():
args = parse_args(sys.argv[1:])
junitxml = load_results_file(args.results.joinpath('FullJUnitReport.xml'))
junitxml = load_results_file(args.results.joinpath("FullJUnitReport.xml"))
if junitxml:
parse_print_failure_results(junitxml)
if __name__ == '__main__':
if __name__ == "__main__":
main()

Просмотреть файл

@ -10,10 +10,14 @@ from junitparser import Attr, Failure, JUnitXml, TestSuite
def parse_args(cmdln_args):
parser = argparse.ArgumentParser(description="Parse and print UI test JUnit results")
parser = argparse.ArgumentParser(
description="Parse and print UI test JUnit results"
)
parser.add_argument(
"--results", type=Path,
help="Directory containing task artifact results", required=True
"--results",
type=Path,
help="Directory containing task artifact results",
required=True,
)
return parser.parse_args(args=cmdln_args)
@ -24,25 +28,35 @@ class test_suite(TestSuite):
def parse_print_failure_results(results):
table = BeautifulTable(maxwidth=256)
table.columns.header = (['UI Test', 'Outcome', 'Details'])
table.columns.header = ["UI Test", "Outcome", "Details"]
table.columns.alignment = BeautifulTable.ALIGN_LEFT
table.set_style(BeautifulTable.STYLE_GRID)
for suite in results:
cur_suite = test_suite.fromelem(suite)
if cur_suite.flakes != '0':
if cur_suite.flakes != "0":
for case in suite:
for entry in case.result:
if case.result:
table.rows.append(
["%s#%s" % (case.classname, case.name), "Flaky", entry.text.replace('\t', ' ')])
[
"%s#%s" % (case.classname, case.name),
"Flaky",
entry.text.replace("\t", " "),
]
)
break
else:
for case in suite:
for entry in case.result:
if isinstance(entry, Failure):
table.rows.append(
["%s#%s" % (case.classname, case.name), "Failure", entry.text.replace('\t', ' ')])
[
"%s#%s" % (case.classname, case.name),
"Failure",
entry.text.replace("\t", " "),
]
)
break
print(table)
@ -50,11 +64,11 @@ def parse_print_failure_results(results):
def load_results_file(filename):
ret = None
try:
f = open(filename, 'r')
f = open(filename, "r")
try:
ret = JUnitXml.fromfile(f)
except xml.etree.ElementTree.ParseError as e:
print(f'Error parsing {filename} file: {e}')
print(f"Error parsing {filename} file: {e}")
finally:
f.close()
except IOError as e:
@ -66,10 +80,10 @@ def load_results_file(filename):
def main():
args = parse_args(sys.argv[1:])
junitxml = load_results_file(args.results.joinpath('FullJUnitReport.xml'))
junitxml = load_results_file(args.results.joinpath("FullJUnitReport.xml"))
if junitxml:
parse_print_failure_results(junitxml)
if __name__ == '__main__':
if __name__ == "__main__":
main()

Просмотреть файл

@ -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 [Confluence](https://mozilla-hub.atlassian.net/wiki/spaces/MTE/overview) | [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 [Confluence](https://mozilla-hub.atlassian.net/wiki/spaces/MTE/overview) | [Slack](https://mozilla.slack.com/archives/C02KDDS9QM9) | [Alerts](https://mozilla.slack.com/archives/C0134KJ4JHL)\n"
)
if __name__ == "__main__":

Просмотреть файл

@ -7,7 +7,9 @@ import os
from importlib import import_module
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
PROJECT_DIR = os.path.realpath(os.path.join(CURRENT_DIR, "..", "..", "mobile", "android"))
PROJECT_DIR = os.path.realpath(
os.path.join(CURRENT_DIR, "..", "..", "mobile", "android")
)
ANDROID_COMPONENTS_DIR = os.path.join(PROJECT_DIR, "android-components")
FOCUS_DIR = os.path.join(PROJECT_DIR, "focus-android")
FENIX_DIR = os.path.join(PROJECT_DIR, "fenix")

Просмотреть файл

@ -197,5 +197,9 @@ def release_promotion_action(parameters, graph_config, input, task_group_id, tas
def read_version_file():
with open(os.path.join(os.path.dirname(__file__), "..", "..", "mobile", "android", "version.txt")) as f:
with open(
os.path.join(
os.path.dirname(__file__), "..", "..", "mobile", "android", "version.txt"
)
) as f:
return f.read().strip()

Просмотреть файл

@ -2,6 +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/.
def does_task_match_release_type(task, release_type):
return (
# TODO: only use a single attribute to compare to `release_type`

Просмотреть файл

@ -33,8 +33,7 @@ def add_signing_indexes(config, task):
subs["artifact_type"] = "components"
subs["artifact_name"] = task["attributes"]["component"]
new_signing_routes = [
template.format(**subs)
for template in SIGNING_ROUTE_TEMPLATES
template.format(**subs) for template in SIGNING_ROUTE_TEMPLATES
]
elif task["attributes"].get("apks"):
@ -42,10 +41,9 @@ def add_signing_indexes(config, task):
new_signing_routes = []
for abi in task["attributes"]["apks"].keys():
subs["artifact_name"] = abi
new_signing_routes.extend([
template.format(**subs)
for template in SIGNING_ROUTE_TEMPLATES
])
new_signing_routes.extend(
[template.format(**subs) for template in SIGNING_ROUTE_TEMPLATES]
)
elif task["attributes"].get("aab"):
# no indexes for AAB signing

Просмотреть файл

@ -25,7 +25,13 @@ def index_exists(index_path, reason=""):
def target_tasks_nightly(full_task_graph, parameters, graph_config):
def filter(task, parameters):
build_type = task.attributes.get("build-type", "")
return build_type in ("nightly", "focus-nightly", "fenix-nightly", "fenix-nightly-firebase", "focus-nightly-firebase")
return build_type in (
"nightly",
"focus-nightly",
"fenix-nightly",
"fenix-nightly-firebase",
"focus-nightly-firebase",
)
index_path = (
f"{graph_config['trust-domain']}.v2.{parameters['project']}.branch."

Просмотреть файл

@ -26,7 +26,7 @@ beetmover_description_schema = Schema(
Optional("dependencies"): task_description_schema["dependencies"],
Optional("bucket-scope"): optionally_keyed_by("level", "build-type", str),
},
extra=ALLOW_EXTRA
extra=ALLOW_EXTRA,
)
transforms = TransformSequence()

Просмотреть файл

@ -17,15 +17,14 @@ def set_treeherder_config(config, tasks):
treeherder = task.setdefault("treeherder", {})
if not treeherder.get("symbol"):
gradle_project = get_gradle_project(task)
treeherder_group = task.get("attributes", {}).get("treeherder-group", gradle_project)
treeherder_group = task.get("attributes", {}).get(
"treeherder-group", gradle_project
)
treeherder["symbol"] = f"{treeherder_group}(egd)"
yield task
@transforms.add
def extend_resources(config, tasks):
deps_per_gradle_project = get_upstream_deps_for_all_gradle_projects()
@ -39,11 +38,13 @@ def extend_resources(config, tasks):
dependencies = deps_per_gradle_project[gradle_project]
gradle_project_and_deps = [gradle_project] + dependencies
resources.extend([
path
for gradle_project in gradle_project_and_deps
for path in _get_build_gradle_paths(gradle_project)
])
resources.extend(
[
path
for gradle_project in gradle_project_and_deps
for path in _get_build_gradle_paths(gradle_project)
]
)
run["resources"] = sorted(list(set(resources)))
@ -68,9 +69,13 @@ def _get_build_gradle_paths(gradle_project):
# Make sure we rebuild the cache when Fenix or Focus dependencies are changed
if gradle_project == "fenix":
file_list.append(f"{project_dir}/plugins/fenixdependencies/src/main/java/FenixDependenciesPlugin.kt")
file_list.append(
f"{project_dir}/plugins/fenixdependencies/src/main/java/FenixDependenciesPlugin.kt"
)
elif gradle_project == "focus":
file_list.append(f"{project_dir}/plugins/focusdependencies/src/main/java/FocusDependenciesPlugin.kt")
file_list.append(
f"{project_dir}/plugins/focusdependencies/src/main/java/FocusDependenciesPlugin.kt"
)
return file_list
@ -95,14 +100,20 @@ def set_command_arguments(config, tasks):
project_dir = _get_gradle_project_dir(gradle_project)
arguments.append(project_dir)
gradle_task_template = "{gradle_task_name}" if gradle_project in ("focus", "fenix") else "{gradle_project}:{gradle_task_name}"
arguments.extend([
gradle_task_template.format(
gradle_project=gradle_project,
gradle_task_name=gradle_task_name,
)
for gradle_task_name in _get_gradle_task_names(gradle_project)
])
gradle_task_template = (
"{gradle_task_name}"
if gradle_project in ("focus", "fenix")
else "{gradle_project}:{gradle_task_name}"
)
arguments.extend(
[
gradle_task_template.format(
gradle_project=gradle_project,
gradle_task_name=gradle_task_name,
)
for gradle_task_name in _get_gradle_task_names(gradle_project)
]
)
yield task
@ -110,10 +121,25 @@ def set_command_arguments(config, tasks):
def _get_gradle_task_names(gradle_project):
gradle_tasks_name = []
if gradle_project == "focus":
gradle_tasks_name.extend(["assembleFocusDebug", "assembleAndroidTest", "testFocusDebugUnitTest", "lint"])
gradle_tasks_name.extend(
[
"assembleFocusDebug",
"assembleAndroidTest",
"testFocusDebugUnitTest",
"lint",
]
)
elif gradle_project == "fenix":
gradle_tasks_name.extend(["assemble", "assembleAndroidTest", "testClasses", "lint"])
gradle_tasks_name.extend(
["assemble", "assembleAndroidTest", "testClasses", "lint"]
)
else:
lint_task_name = "lint" if gradle_project in ("tooling-lint", "samples-browser") else "lintRelease"
gradle_tasks_name.extend(["assemble", "assembleAndroidTest", "test", lint_task_name])
lint_task_name = (
"lint"
if gradle_project in ("tooling-lint", "samples-browser")
else "lintRelease"
)
gradle_tasks_name.extend(
["assemble", "assembleAndroidTest", "test", lint_task_name]
)
return tuple(gradle_tasks_name)

Просмотреть файл

@ -21,7 +21,8 @@ def set_name_and_clear_artifacts(config, tasks):
def resolve_keys(config, tasks):
for task in tasks:
resolve_keyed_by(
task, "treeherder.symbol",
task,
"treeherder.symbol",
item_name=task["name"],
**{
"build-type": task["attributes"]["build-type"],

Просмотреть файл

@ -38,7 +38,6 @@ def resolve_keys(config, tasks):
@transforms.add
def add_startup_test(config, tasks):
# TODO: change kind.yml to have the right dependency upfront
for task in tasks:
if "nightly" not in task["attributes"].get("build-type", ""):
yield task

Просмотреть файл

@ -41,7 +41,7 @@ def resolve_keys(config, tasks):
"build-type": task["attributes"]["build-type"],
"level": config.params["level"],
"tasks-for": config.params["tasks_for"],
}
},
)
yield task

Просмотреть файл

@ -36,7 +36,7 @@ def component_grouping(config, tasks):
return groups.values()
@group_by('build-type')
@group_by("build-type")
def build_type_grouping(config, tasks):
groups = {}
for task in tasks:
@ -45,7 +45,7 @@ def build_type_grouping(config, tasks):
if not task.attributes.get("is_final_chunked_task", True):
continue
build_type = task.attributes.get('build-type')
build_type = task.attributes.get("build-type")
groups.setdefault(build_type, []).append(task)
return groups.values()

Просмотреть файл

@ -23,7 +23,14 @@ logger = logging.getLogger(__name__)
def _buildconfig_files_diff():
cmd = ["hg", "diff", "--rev", "draft() and ancestors(.)", "-I", "**/.buildconfig.yml"]
cmd = [
"hg",
"diff",
"--rev",
"draft() and ancestors(.)",
"-I",
"**/.buildconfig.yml",
]
p = subprocess.run(cmd, capture_output=True, universal_newlines=True)
return p.stdout

Просмотреть файл

@ -46,8 +46,7 @@ def _get_upstream_deps_per_gradle_project(gradle_root, existing_build_config):
current_project_name = None
print(f"Running command: {' '.join(cmd)}")
try:
output = subprocess.check_output(
cmd, universal_newlines=True, cwd=gradle_root)
output = subprocess.check_output(cmd, universal_newlines=True, cwd=gradle_root)
except subprocess.CalledProcessError as cpe:
print(cpe.output)
raise

Просмотреть файл

@ -20,15 +20,19 @@ def write_secret_to_file(path, secret):
print(f"Outputting secret to: {path}")
with open(path, 'w') as f:
with open(path, "w") as f:
f.write(secret)
def main():
parser = argparse.ArgumentParser(description="Store a dummy secret to a file")
parser.add_argument("-c", dest="content", action="store", help="content of the secret")
parser.add_argument("-f", dest="path", action="store", help="file to save secret to")
parser.add_argument(
"-c", dest="content", action="store", help="content of the secret"
)
parser.add_argument(
"-f", dest="path", action="store", help="file to save secret to"
)
result = parser.parse_args()