From f129a36099c255913c3f8dc95e3e0df4eca0b473 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 9 Jan 2016 22:56:48 +0000 Subject: [PATCH] Added custom coverage script --- runtests | 6 ++++-- scripts/check-coverage.py | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100755 scripts/check-coverage.py diff --git a/runtests b/runtests index 67eb52f..77498b2 100755 --- a/runtests +++ b/runtests @@ -4,8 +4,10 @@ set -e export PATH=env/bin:${PATH} -coverage run --source=project --omit='*/wsgi.py,*/settings.py,*/migrations/*.py,*__init__*' manage.py test $@ -flake8 project --ignore=E128,E501,E401 --exclude="migrations,settings,*/wsgi.py" +./scripts/check-coverage.py + +flake8 project scripts --ignore=E128,E501,E401 --exclude="migrations,settings,*/wsgi.py" + coverage html coverage report diff --git a/scripts/check-coverage.py b/scripts/check-coverage.py new file mode 100755 index 0000000..b799408 --- /dev/null +++ b/scripts/check-coverage.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +import coverage +import subprocess + +RED = "\033[31m" +GREEN = "\033[32m" +YELLOW = "\033[33m" +NORMAL = "\033[0m" +PERCENTAGE = 95 + +cov = coverage.Coverage( + source=["project"], + omit=["*/wsgi.py", "*/settings.py", "*/migrations/*.py", "*/__init__*"] +) + +cov.start() +print(YELLOW + "Running Tests..." + NORMAL) +subprocess.check_output(["manage.py", "test"]) +cov.stop() + +print(YELLOW + "Collecting Coverage..." + NORMAL) +covered = cov.report() +if covered <= PERCENTAGE: + print(RED + "ERROR: Your coverage needs to be higher. Current coverage: {}%. Required: {}%.".format(covered, PERCENTAGE) + NORMAL) + exit(1) + +print(GREEN + "Coverage Complete." + NORMAL)