From 81bfee8128cb7edc6e82fe361de465ef988375b7 Mon Sep 17 00:00:00 2001 From: Marco Cavalli Date: Tue, 13 May 2025 17:52:35 +0200 Subject: [PATCH] fix: improve code readability and formatting in statisticsDocumentationData.py --- doc/statisticsDocumentationData.py | 98 ++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 25 deletions(-) diff --git a/doc/statisticsDocumentationData.py b/doc/statisticsDocumentationData.py index 65e09e8d9..01657aabc 100644 --- a/doc/statisticsDocumentationData.py +++ b/doc/statisticsDocumentationData.py @@ -13,25 +13,40 @@ if __name__ == "__main__": number_of_all_testcases = 0 number_of_successes = 0 ROBOT_FILE_EXTENSION = ".robot" - BASE_URL_OF_FORGE = "https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/blob/master/TP/NGSI-LD/" + BASE_URL_OF_FORGE = ( + "https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/blob/master/TP/NGSI-LD/" + ) fullpath = basedir + "/TP/NGSI-LD" for root, dirs, files in walk(fullpath): + # skip if the root contains DistributedOperations + if "DistributedOperations" in root: + continue + for filename in files: if filename.endswith(ROBOT_FILE_EXTENSION): number_of_all_testcases += 1 - name_of_test_case = filename[:-len(ROBOT_FILE_EXTENSION)] + name_of_test_case = filename[: -len(ROBOT_FILE_EXTENSION)] json_of_test_case = create_json_of_robotfile(name_of_test_case, True) statistics[name_of_test_case] = dict() - strippedpath = root[len(fullpath)+1:] + strippedpath = root[len(fullpath) + 1 :] statistics[name_of_test_case]["path"] = strippedpath - if "error_while_parsing" in json_of_test_case and json_of_test_case["error_while_parsing"]: + if ( + "error_while_parsing" in json_of_test_case + and json_of_test_case["error_while_parsing"] + ): statistics[name_of_test_case]["failed"] = True number_of_failures += 1 # we create a dummy entry in the "sub" test_cases, which has a "permutation_tp_id" equal to the # robotfile. We do not forget to add a trailing slash that will be removed later, and a tail _XX # which will allow matching from the googlesheet? - json_of_test_case["test_cases"] = [{"permutation_tp_id": "/"+json_of_test_case["robotfile"]+"_XX"}] + json_of_test_case["test_cases"] = [ + { + "permutation_tp_id": "/" + + json_of_test_case["robotfile"] + + "_XX" + } + ] else: statistics[name_of_test_case]["failed"] = False number_of_successes += 1 @@ -40,12 +55,19 @@ if __name__ == "__main__": # establish the right configuration if json_of_test_case["robotpath"].startswith("ContextSource"): json_of_test_case["config_id"] = "CF_05" + elif json_of_test_case["robotpath"].startswith( + "DistributedOperations" + ): + json_of_test_case["config_id"] = "CF_06" else: json_of_test_case["config_id"] = "CF_01" # upgrade the version and add the reference in square brackets - json_of_test_case["reference"] = ( - re.sub(r"V1.3.1 \[\]", "version 1.5.1 [1]", json_of_test_case["reference"])) + json_of_test_case["reference"] = re.sub( + r"V1\.[3-6]\.1 \[\]", + "V1.6.1 [1]", + json_of_test_case["reference"], + ) # now for each permutation inside this test case, create the permutation's correct parent_release if "test_cases" in json_of_test_case: @@ -54,13 +76,18 @@ if __name__ == "__main__": # default parent release parent_release = "v1.3.1" for tag in permutation_body["tags"]: - if tag.startswith('since_'): - parts = tag.split('_') + if tag.startswith("since_"): + parts = tag.split("_") # the suffix parent_release = parts[-1] - permutation_body["permutation_parent_release"] = parent_release + permutation_body["permutation_parent_release"] = ( + parent_release + ) else: - print("NO PERMUTATIONS in TESTCASE??? " + json_of_test_case["tp_id"]) + print( + "NO PERMUTATIONS in TESTCASE??? " + + json_of_test_case["tp_id"] + ) exit(1) testcases.append(json_of_test_case) @@ -70,14 +97,16 @@ if __name__ == "__main__": print("THE FOLLOWING TESTCASES FAILED PARSING:") for testcasename, testcaseresult in statistics.items(): if testcaseresult["failed"]: - print(testcasename+" "+testcaseresult["path"]) - - print(f"Out of {number_of_all_testcases} testcases, {number_of_failures} of them failed to be correctly parsed.") + print(testcasename + " " + testcaseresult["path"]) + + print( + f"Out of {number_of_all_testcases} testcases, {number_of_failures} of them failed to be correctly parsed." + ) testcases_file = join(basedir, "doc", "results", "testcases.json") - with open(testcases_file, 'w') as fp: + with open(testcases_file, "w") as fp: json.dump(obj=testcases, indent=2, fp=fp) - + # determine the structure/schema of a successfully parsed testcase permutation_template = {} for testcase in testcases: @@ -103,9 +132,13 @@ if __name__ == "__main__": # everything that is a permutation_body inside the "sub" test_cases, # shall rise on its own existenz and be joined with its permutation_metadata for permutation_body in testcase["test_cases"]: - permutation_body_template = {} # new object, not changing permutation_body + permutation_body_template = ( + {} + ) # new object, not changing permutation_body if "permutation_tp_id" in permutation_body: - permutation_body_template["stripped_permutation_tp_id"] = "UNKNOWN" + permutation_body_template["stripped_permutation_tp_id"] = ( + "UNKNOWN" + ) permutation_body_template["robotlink"] = "UNKNOWN" for key, value in permutation_body.items(): if type(key) is str: @@ -122,7 +155,10 @@ if __name__ == "__main__": print("UNKNOWN BODY type") exit(1) # we use the unpacking python operator ** that strips the container dict from both - permutation_template = {**permutation_metadata_template, **permutation_body_template} + permutation_template = { + **permutation_metadata_template, + **permutation_body_template, + } else: print("NO PERMUTATION TP ID") exit(1) @@ -131,7 +167,7 @@ if __name__ == "__main__": exit(1) if permutation_template != {}: break - + print() print("Typical template:") print(permutation_template) @@ -148,8 +184,13 @@ if __name__ == "__main__": permutation_metadata[key] = value # start creating HTML link to robot file in repo - fullurl = (BASE_URL_OF_FORGE + permutation_metadata["robotpath"] + - "/" + permutation_metadata["robotfile"] + ROBOT_FILE_EXTENSION) + fullurl = ( + BASE_URL_OF_FORGE + + permutation_metadata["robotpath"] + + "/" + + permutation_metadata["robotfile"] + + ROBOT_FILE_EXTENSION + ) if "test_cases" in testcase: # everything that is a permutation_body inside the "sub" test_cases, @@ -164,11 +205,18 @@ if __name__ == "__main__": # print("::: "+ptpid) # strip from beginning up to including the last "/" - permutation_body["stripped_permutation_tp_id"] = ptpid[ptpid.rindex("/")+1:] + permutation_body["stripped_permutation_tp_id"] = ptpid[ + ptpid.rindex("/") + 1 : + ] # use the stripped_permutation_tp_id as text of the link permutation_body["robotlink"] = ( - "" + permutation_body["stripped_permutation_tp_id"] + "") + '' + + permutation_body["stripped_permutation_tp_id"] + + "" + ) # So basically we append to the permutations a new dict that is the | union merge of the # items of the template merged with the items of the concatenation of {**permutation_metadata, @@ -195,5 +243,5 @@ if __name__ == "__main__": exit(1) permutations_file = join(basedir, "doc", "results", "permutations.json") - with open(permutations_file, 'w') as fp: + with open(permutations_file, "w") as fp: json.dump(obj=permutations, indent=2, fp=fp) -- GitLab