2016-01-10 16:12:58 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import coverage
|
|
|
|
import os, sys
|
|
|
|
import subprocess
|
|
|
|
from colorama import Fore, init
|
2015-10-19 13:04:49 +01:00
|
|
|
|
|
|
|
|
2016-01-10 16:12:58 +00:00
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
|
|
|
|
from django.core.management import execute_from_command_line
|
|
|
|
init(autoreset=True)
|
2015-10-19 13:04:49 +01:00
|
|
|
|
2016-01-09 22:56:48 +00:00
|
|
|
|
2016-01-10 16:23:34 +00:00
|
|
|
bin_dir = os.path.abspath(os.path.join(sys.executable, os.path.pardir))
|
2016-01-10 16:12:58 +00:00
|
|
|
PERCENTAGE = 95
|
2016-01-17 20:06:11 +00:00
|
|
|
EXIT_CODE = 0
|
|
|
|
|
|
|
|
|
|
|
|
def check_if_exit_code():
|
|
|
|
if EXIT_CODE != 0:
|
|
|
|
exit(EXIT_CODE)
|
2016-01-09 22:56:48 +00:00
|
|
|
|
2016-01-10 16:23:34 +00:00
|
|
|
|
2016-01-10 16:12:58 +00:00
|
|
|
cov = coverage.Coverage(
|
|
|
|
source=["project"],
|
|
|
|
omit=["*/wsgi.py", "*/settings.py", "*/migrations/*.py", "*/__init__*"]
|
|
|
|
)
|
|
|
|
cov.start()
|
2015-11-23 14:33:03 +00:00
|
|
|
|
2016-01-10 16:12:58 +00:00
|
|
|
|
2016-01-10 16:23:34 +00:00
|
|
|
print(Fore.YELLOW + "Running Tests...")
|
|
|
|
execute_from_command_line([sys.argv[0], 'test'])
|
2016-01-10 16:12:58 +00:00
|
|
|
cov.stop()
|
2016-01-10 16:23:34 +00:00
|
|
|
|
|
|
|
|
2016-01-10 16:12:58 +00:00
|
|
|
print(Fore.YELLOW + "Collecting Coverage...")
|
|
|
|
cov.save()
|
|
|
|
cov.html_report()
|
2016-01-10 16:23:34 +00:00
|
|
|
|
|
|
|
|
2016-01-10 16:12:58 +00:00
|
|
|
covered = cov.report()
|
|
|
|
if covered <= PERCENTAGE:
|
|
|
|
print(Fore.RED + "ERROR: Your coverage needs to be higher. Current coverage: {}%. Required: {}%.".format(covered, PERCENTAGE))
|
2016-01-17 20:06:11 +00:00
|
|
|
EXIT_CODE = 1
|
|
|
|
|
|
|
|
check_if_exit_code()
|
2016-01-10 16:12:58 +00:00
|
|
|
print(Fore.GREEN + "Coverage Complete.")
|
|
|
|
|
2016-01-10 16:23:34 +00:00
|
|
|
|
2016-01-10 16:12:58 +00:00
|
|
|
FLAKE8_IGNORE = '--ignore=E128,E501,E401'
|
|
|
|
try:
|
|
|
|
subprocess.check_output([os.path.join(bin_dir, 'flake8'), 'project', FLAKE8_IGNORE, '--exclude=migrations,settings,wsgi.py'])
|
|
|
|
subprocess.check_output([os.path.join(bin_dir, 'flake8'), 'scripts', FLAKE8_IGNORE])
|
|
|
|
subprocess.check_output([os.path.join(bin_dir, 'flake8'), sys.argv[0], FLAKE8_IGNORE])
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print(Fore.RED + e.output.decode())
|
2016-01-17 20:06:11 +00:00
|
|
|
EXIT_CODE = 1
|
|
|
|
check_if_exit_code()
|
2016-01-10 16:12:58 +00:00
|
|
|
|
|
|
|
print(Fore.GREEN + "All Python tests passed!")
|
|
|
|
|
|
|
|
|
2016-01-17 20:06:11 +00:00
|
|
|
EXIT_CODE = os.system('npm test')
|
|
|
|
|
|
|
|
check_if_exit_code()
|
2016-01-10 16:12:58 +00:00
|
|
|
print(Fore.GREEN + "All Tests Passed!")
|