load all yml files while assigning tests

This commit is contained in:
Fu Hanxi 2020-04-29 10:49:10 +08:00 committed by bot
parent 7709d4ccfd
commit c131a18059

View file

@ -1,7 +1,7 @@
""" """
Command line tool to assign unit tests to CI test jobs. Command line tool to assign unit tests to CI test jobs.
""" """
import os
import re import re
import argparse import argparse
@ -145,15 +145,33 @@ class UnitTestAssignTest(CIAssignTest.AssignTest):
The unit test cases is stored in a yaml file which is created in job build-idf-test. The unit test cases is stored in a yaml file which is created in job build-idf-test.
""" """
try: def find_by_suffix(suffix, path):
with open(test_case_path, "r") as f: res = []
raw_data = yaml.load(f, Loader=Loader) for root, _, files in os.walk(path):
test_cases = raw_data["test cases"] for file in files:
for case in test_cases: if file.endswith(suffix):
case["tags"] = set(case["tags"]) res.append(os.path.join(root, file))
except IOError: return res
def get_test_cases_from_yml(yml_file):
try:
with open(yml_file) as fr:
raw_data = yaml.load(fr, Loader=Loader)
test_cases = raw_data['test cases']
except (IOError, KeyError):
return []
else:
return test_cases
test_cases = []
if os.path.isdir(test_case_path):
for yml_file in find_by_suffix('.yml', test_case_path):
test_cases.extend(get_test_cases_from_yml(yml_file))
elif os.path.isfile(test_case_path):
test_cases.extend(get_test_cases_from_yml(test_case_path))
else:
print("Test case path is invalid. Should only happen when use @bot to skip unit test.") print("Test case path is invalid. Should only happen when use @bot to skip unit test.")
test_cases = []
# filter keys are lower case. Do map lower case keys with original keys. # filter keys are lower case. Do map lower case keys with original keys.
try: try:
key_mapping = {x.lower(): x for x in test_cases[0].keys()} key_mapping = {x.lower(): x for x in test_cases[0].keys()}