Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Vepricov committed Nov 21, 2024
1 parent 34eb1a8 commit db7d063
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/badge_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# this script was generated by ChatGPT with minor fixes
import xml.etree.ElementTree as ET

def get_coverage():
tree = ET.parse('coverage.xml')
root = tree.getroot()
line_rate = float(root.get('line-rate', 0)) * 100
return round(line_rate, 2)

def generate_badge(coverage):
color = "red"
if coverage >= 90:
color = "lightgreen"
elif coverage >= 75:
color = "yellowgreen"
elif coverage >= 50:
color = "olive"
badge = f"""
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="20">
<rect width="100" height="20" fill="{color}" />
<text x="50%" y="14" fill="#fff" font-family="Arial" font-size="11" text-anchor="middle">
Coverage: {coverage}%
</text>
</svg>
"""
with open('coverage-badge.svg', 'w') as badge_file:
badge_file.write(badge)

if __name__ == "__main__":
coverage = get_coverage()
generate_badge(coverage)

0 comments on commit db7d063

Please sign in to comment.