Skip to content

Commit

Permalink
New nox project able to perform tests, generate docs, publish docs & …
Browse files Browse the repository at this point in the history
…coverage, and release on PyPi.
  • Loading branch information
Sylvain MARIE committed Mar 5, 2021
1 parent ff79536 commit 525f57c
Show file tree
Hide file tree
Showing 4 changed files with 491 additions and 279 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ venv.bak/

# mypy
.mypy_cache/

# genrated
docs/reports
24 changes: 17 additions & 7 deletions ci_tools/generate-junit-badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def get_test_stats(junit_xml='reports/junit/junit.xml' # type: str
return TestStats(success_percentage, success, runned, skipped)


def download_badge(test_stats, # type: TestStats
dest_folder='reports/junit' # type: str
def download_badge(test_stats, # type: TestStats
dest_folder='reports/junit', # type: str
badge_name='junit-badge.svg' # type: str
):
"""
Downloads the badge corresponding to the provided success percentage, from https://img.shields.io.
Expand All @@ -66,7 +67,7 @@ def download_badge(test_stats, # type: TestStats
right_txt = "%s/%s" % (test_stats.success, test_stats.runned)
url = 'https://img.shields.io/badge/%s-%s-%s.svg' % (left_txt, quote_plus(right_txt), color)

dest_file = path.join(dest_folder, 'junit-badge.svg')
dest_file = path.join(dest_folder, badge_name)

print('Generating junit badge from : ' + url)
response = requests.get(url, stream=True)
Expand All @@ -79,11 +80,20 @@ def download_badge(test_stats, # type: TestStats
if __name__ == "__main__":
# Execute only if run as a script.
# Check the arguments
assert len(sys.argv[1:]) == 1, "a single mandatory argument is required: <threshold>"
threshold = float(sys.argv[1])
nbargs = len(sys.argv[1:])
if nbargs < 1:
raise ValueError("a mandatory argument is required: <threshold>, and an optional: <dest_folder>")
else:
threshold = float(sys.argv[1])
if nbargs < 2:
dest_folder = None
elif nbargs < 3:
dest_folder = sys.argv[2]
else:
raise ValueError("too many arguments received: 2 maximum (<threshold>, <dest_folder>)")

# First retrieve the success percentage from the junit xml
test_stats = get_test_stats()
test_stats = get_test_stats(junit_xml='%s/junit.xml' % ('reports/junit' if dest_folder is None else dest_folder))

# Validate against the threshold
print("Success percentage is %s%%. Checking that it is >= %s" % (test_stats.success_percentage, threshold))
Expand All @@ -92,4 +102,4 @@ def download_badge(test_stats, # type: TestStats
"" % (test_stats.success_percentage, threshold))

# Download the badge
download_badge(test_stats)
download_badge(test_stats, dest_folder=dest_folder)
Loading

0 comments on commit 525f57c

Please sign in to comment.