Skip to content

Commit f1f189d

Browse files
authored
clean up manifest/addtests (#933)
* clean up manifest/addtests * fix githook * attempt to force failure on bad linting * use correct linter * test lint again * test lint again * now test lint passes * don't require future tests for chooser * mark zip type unstable
1 parent 6e815da commit f1f189d

File tree

13 files changed

+83
-230
lines changed

13 files changed

+83
-230
lines changed

addtests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23

34
from manifests import testkey
45

@@ -9,4 +10,7 @@
910

1011
if __name__ == "__main__":
1112
manifest = testkey.TestKey(TEST_KEY)
12-
manifest.addtests()
13+
if len(sys.argv) > 1 and sys.argv[1] == "-q":
14+
manifest.addtests(interactive=False)
15+
else:
16+
manifest.addtests()

choose_ci_set.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def dedupe(run_list: list) -> list:
220220
# Dedupe just in case
221221
if SLASH == "\\":
222222
run_list = [entry.replace("/", SLASH) for entry in run_list]
223+
run_list = [entry for entry in run_list if os.path.exists(entry)]
223224
run_list = manifest.filter_filenames_by_pass(run_list)
224225
run_list = dedupe(run_list)
225226
run_list = [entry for entry in run_list if os.path.exists(entry.split("::")[0])]

make_manifest.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

manifests/incident.yaml

Lines changed: 0 additions & 158 deletions
This file was deleted.

manifests/key.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ address_bar_and_search:
2727
test_addressbar_bookmarks_when_history_disabled:
2828
result: pass
2929
splits:
30-
- functional1
30+
- functional1
3131
test_addressbar_search_engine_keywords:
3232
result: pass
3333
splits:
@@ -363,10 +363,7 @@ downloads:
363363
splits:
364364
- smoke
365365
test_add_zip_type:
366-
result:
367-
linux: unstable
368-
mac: unstable
369-
win: unstable
366+
result: unstable
370367
splits:
371368
- smoke
372369
- ci-extended

manifests/testkey.py

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import os
22
import platform
3+
import re
4+
import sys
35
from copy import deepcopy
46

57
import yaml
68

79
NUM_FUNCTIONAL_SPLITS = 1
810
MAX_DEPTH = 5
11+
SUITE_TUPLE_RE = re.compile(r'\s+return \("S(\d+)", ?".*"\)')
912

1013

1114
def sysname():
@@ -196,20 +199,54 @@ def gather_split(self, split_name, pass_only=True):
196199

197200
return test_filenames
198201

199-
def addtests(self):
202+
def get_valid_suites_in_split(self, split, suite_numbers=False):
203+
filenames = self.gather_split(split)
204+
suite_dirs = []
205+
for filename in filenames:
206+
suite_dir = filename.split(os.path.sep)[1]
207+
if suite_dir not in suite_dirs:
208+
suite_dirs.append(suite_dir)
209+
210+
if not suite_numbers:
211+
return suite_dirs
212+
else:
213+
suite_nums = []
214+
for suite_dir in suite_dirs:
215+
with open(os.path.join("tests", suite_dir, "conftest.py")) as fh:
216+
lines = fh.readlines()
217+
suite_flag = False
218+
for line in lines:
219+
if suite_flag:
220+
m = SUITE_TUPLE_RE.search(line)
221+
if m and len(m.groups()) > 0:
222+
suite_num = m.group(1)
223+
if suite_num not in suite_nums:
224+
suite_nums.append(suite_num)
225+
break
226+
return suite_nums
227+
228+
def addtests(self, interactive=True):
200229
newkey = deepcopy(self.manifest)
201230
for root, _, files in os.walk(self.test_root):
202231
for f in files:
203232
suite = root.split(os.path.sep)[1]
233+
if not (f.startswith("test_") and f.endswith(".py")):
234+
continue
204235
testfile = f.replace(".py", "")
205236
if suite not in newkey:
237+
if not interactive:
238+
sys.exit(
239+
"Please run `python addtests.py` from your command prompt."
240+
)
206241
if ask_question(f"Found suite {suite}. Add it to key? "):
207242
newkey[suite] = {}
208243

209244
resplit = False
210245
if testfile not in newkey[suite]:
211-
if not testfile.startswith("test_"):
212-
continue
246+
if not interactive:
247+
sys.exit(
248+
"Please run `python addtests.py` from your command prompt."
249+
)
213250
if ask_question(f"Found test {suite}/{testfile}. Add it to key? "):
214251
newkey[suite][testfile] = {"result": "pass"}
215252

@@ -229,17 +266,17 @@ def addtests(self):
229266
resplit = True
230267

231268
if resplit:
232-
split = ask_open_question(
233-
"What split is this test assigned to? (One only) "
234-
)
235-
newkey[suite][testfile]["splits"] = [split]
236-
237269
if ask_question(
238270
"Should this test run in a Scheduled Functional split? "
239271
"(Say no if unsure.) "
240272
):
241-
newkey[suite][testfile]["splits"].append("functional1")
273+
newkey[suite][testfile]["splits"] = ["functional1"]
242274
self.rebalance_functionals()
275+
else:
276+
split = ask_open_question(
277+
"What split is this test assigned to? (One only) "
278+
)
279+
newkey[suite][testfile]["splits"] = [split]
243280

244281
print(
245282
f"Test will be added to {split} in {self.manifest_file}. "

modules/testrail_integration.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66

77
from choose_l10n_ci_set import select_l10n_mappings
8+
from manifests.testkey import TestKey
89
from modules import taskcluster as tc
910
from modules import testrail as tr
1011
from modules.testrail import TestRail
@@ -17,6 +18,7 @@
1718
"[{channel} {major}] {plan}Automated testing {major}.{minor}b{beta}-build{build}"
1819
)
1920
PLAN_NAME_RE = re.compile(r"\[(\w+) (\d+)\]")
21+
TEST_KEY_LOCATION = os.path.join("manifests", "key.yaml")
2022
CONFIG_GROUP_ID = 95
2123
TESTRAIL_FX_DESK_PRJ = 17
2224
TC_EXECUTION_TEMPLATE = "https://firefox-ci-tc.services.mozilla.com/tasks/%TASK_ID%/runs/%RUN_ID%/logs/live/public/logs/live.log"
@@ -267,24 +269,30 @@ def reportable(platform_to_test=None):
267269
# Only report when there is a new beta without a reported plan or if the selected split is not completely reported.
268270
return covered_mappings < expected_mappings
269271
else:
270-
covered_suites = 0
272+
covered_suites = []
271273
for entry in plan_entries:
272274
for run_ in entry.get("runs"):
273275
if run_.get("config") and platform in run_.get("config"):
274-
covered_suites += 1
276+
covered_suites.append(str(run_.get("suite_id")))
275277

276-
num_suites = 0
277-
for test_dir_name in os.listdir("tests"):
278-
test_dir = os.path.join("tests", test_dir_name)
279-
if os.path.isdir(test_dir) and not os.path.exists(
280-
os.path.join(test_dir, "skip_reporting")
281-
):
282-
num_suites += 1
283-
284-
logging.warning(
285-
f"Potentially matching run found for {platform}, may be reportable. ({covered_suites} out of {num_suites} suites already reported.)"
278+
if not os.environ.get("STARFOX_SPLIT"):
279+
sys.exit("No split selected")
280+
manifest = TestKey()
281+
expected_suites = manifest.get_valid_suites_in_split(
282+
os.environ["STARFOX_SPLIT"]
286283
)
287-
return covered_suites + 1 < num_suites
284+
285+
uncovered_suites = set(expected_suites) - set(covered_suites)
286+
if len(uncovered_suites):
287+
suite_names = [
288+
s.get("name")
289+
for s in tr_session.get_suites(TESTRAIL_FX_DESK_PRJ)
290+
if str(s.get("id")) in uncovered_suites
291+
]
292+
print("Coverage not found for the following suites:")
293+
print("\t-" + "\n\t-".join(suite_names))
294+
295+
return not uncovered_suites
288296

289297

290298
def testrail_init() -> TestRail:

0 commit comments

Comments
 (0)