load all yml files while assigning tests
"""
Command line tool to assign unit tests to CI test jobs.
"""
-
+import os
import re
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.
"""
+ def find_by_suffix(suffix, path):
+ res = []
+ for root, _, files in os.walk(path):
+ for file in files:
+ if file.endswith(suffix):
+ res.append(os.path.join(root, file))
+ return res
+
+ def get_test_cases_from_yml(yml_file):
try:
- with open(test_case_path, "r") as f:
- raw_data = yaml.load(f, Loader=Loader)
- test_cases = raw_data["test cases"]
- for case in test_cases:
- case["tags"] = set(case["tags"])
- except IOError:
- print("Test case path is invalid. Should only happen when use @bot to skip unit test.")
+ 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.")
+
# filter keys are lower case. Do map lower case keys with original keys.
try:
key_mapping = {x.lower(): x for x in test_cases[0].keys()}
