|
import sys |
|
import os |
|
|
|
SUMMARY_XML_FILENAME = "Summary.xml" |
|
|
|
|
|
def check_coverage(root_dir, min_percentage): |
|
|
|
|
|
|
|
|
|
summary_xml = None |
|
for dirpath, _, filenames in os.walk(root_dir): |
|
if SUMMARY_XML_FILENAME in filenames: |
|
summary_xml = os.path.join(dirpath, SUMMARY_XML_FILENAME) |
|
break |
|
if not summary_xml: |
|
print(f"Couldn't find {SUMMARY_XML_FILENAME} in root directory") |
|
sys.exit(1) |
|
|
|
with open(summary_xml) as f: |
|
|
|
|
|
lines = f.readlines() |
|
for line in lines: |
|
if "Linecoverage" in line: |
|
pct = line.replace("<Linecoverage>", "").replace("</Linecoverage>", "") |
|
pct = float(pct) |
|
if pct < min_percentage: |
|
print( |
|
f"Coverage {pct} is below the min percentage of {min_percentage}." |
|
) |
|
sys.exit(1) |
|
else: |
|
print( |
|
f"Coverage {pct} is above the min percentage of {min_percentage}." |
|
) |
|
sys.exit(0) |
|
|
|
|
|
print("Couldn't find Linecoverage in summary file") |
|
sys.exit(1) |
|
|
|
|
|
def main(): |
|
root_dir = sys.argv[1] |
|
min_percent = float(sys.argv[2]) |
|
if min_percent > 0: |
|
|
|
check_coverage(root_dir, min_percent) |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |
|
|