From 47abc68d21d973035dbb18a370ffbd4ce901c875 Mon Sep 17 00:00:00 2001 From: Zim Kalinowski Date: Mon, 13 Apr 2020 08:25:47 +0200 Subject: [PATCH] Test coverage calculation script (#10804) * statistics script * calculating coverage * finalized coverage script --- .../devtools_testutils/mgmt_test_stats.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tools/azure-sdk-tools/devtools_testutils/mgmt_test_stats.py diff --git a/tools/azure-sdk-tools/devtools_testutils/mgmt_test_stats.py b/tools/azure-sdk-tools/devtools_testutils/mgmt_test_stats.py new file mode 100644 index 000000000000..13de933c7a77 --- /dev/null +++ b/tools/azure-sdk-tools/devtools_testutils/mgmt_test_stats.py @@ -0,0 +1,50 @@ +from os import listdir, walk +import re +from os.path import join, exists + +print("| Package | Coverage |") +print("|----------------------------------------|------------|") + +pattern = ".\/sdk\/[a-z]+\/azure-mgmt-[a-z-]+$" +dirs = [x[0] for x in walk(".") if re.match(pattern, x[0])] +dirs.sort(key=lambda x: x.split("/").pop()) +total = 0 +manual = 0 +auto = 0 +none = 0 +for d in dirs: + total += 1 + coverage = "-" + test_dir = join(d, "tests") + if exists(test_dir): + test_files = [f for f in listdir(test_dir) if re.match("^test_[a-z_]+.py$", f)] + has_manual = False + has_auto = False + for t in test_files: + coverage = "MANUAL" + if t.startswith("test_cli_"): + coverage = "AUTO" + with open(join(test_dir, t)) as f: + content = f.readlines() + coverage = [x for x in content if x.startswith("# Coverage % :")] + coverage = 0 if not coverage else float(coverage[0].split(":").pop()) + has_auto = True + else: + has_manual = True + manual += 1 if has_manual else 0 + auto += 1 if has_auto else 0 + else: + none += 1 + + print("| {:38} | {:10} |".format(d.split("/").pop(), coverage if coverage in ["-" , "AUTO", "MANUAL"] else "{:4.2f}".format(coverage))) + +print("| {:38} | {:10} |".format("", "")) +print("| {:38} | {:10} |".format("**TOTAL**", "**{}**".format(total))) +print("| {:38} | {:10} |".format("**MANUAL**", "**{}**".format(manual))) +print("| {:38} | {:10} |".format("**MANUAL %**", "**{:4.2f}**".format(100 * manual / total))) +print("| {:38} | {:10} |".format("**AUTO**", "**{}**".format(auto))) +print("| {:38} | {:10} |".format("**AUTO %**", "**{:4.2f}**".format(100 * auto / total))) +print("| {:38} | {:10} |".format("**NONE**", "**{}**".format(none))) +print("| {:38} | {:10} |".format("**NONE %**", "**{:4.2f}**".format(100 * none / total))) + +