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:
|
2016-01-27 18:27:30 +00:00
|
|
|
print("\n{}Tests Failed. {}Please check messages above and then re-run the command.".format(Fore.RED, Fore.YELLOW))
|
2016-01-17 20:06:11 +00:00
|
|
|
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"],
|
2016-01-26 07:54:34 +00:00
|
|
|
omit=["*/wsgi.py", "*/settings.py", "*/migrations/*.py", "*/__init__*", "*/tests.py"]
|
2016-01-10 16:12:58 +00:00
|
|
|
)
|
|
|
|
cov.start()
|
2015-11-23 14:33:03 +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-27 18:27:30 +00:00
|
|
|
print("{}Tests Complete. {}Collecting Coverage...".format(Fore.GREEN, Fore.YELLOW))
|
2016-01-10 16:12:58 +00:00
|
|
|
cov.save()
|
|
|
|
cov.html_report()
|
|
|
|
covered = cov.report()
|
2016-01-27 18:27:30 +00:00
|
|
|
if covered < PERCENTAGE:
|
|
|
|
print("{}ERROR: Your coverage needs to be higher. Current coverage: {}%. Required: {}%.".format(Fore.RED, covered, PERCENTAGE))
|
2016-01-17 20:06:11 +00:00
|
|
|
EXIT_CODE = 1
|
|
|
|
|
|
|
|
check_if_exit_code()
|
2016-01-27 18:27:30 +00:00
|
|
|
print("{}Coverage Complete. {}Linting...".format(Fore.GREEN, Fore.YELLOW))
|
2016-01-10 16:12:58 +00:00
|
|
|
|
2016-01-10 16:23:34 +00:00
|
|
|
|
2016-04-09 13:14:58 +01:00
|
|
|
FLAKE8_IGNORE = '--ignore=E128,E501,E401,E402'
|
2016-01-10 16:12:58 +00:00
|
|
|
try:
|
2016-01-26 18:25:20 +00:00
|
|
|
subprocess.check_output([os.path.join(bin_dir, 'flake8'), 'project', FLAKE8_IGNORE, '--exclude=migrations,settings,wsgi.py,__init__.py'])
|
2016-01-10 16:12:58 +00:00
|
|
|
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:
|
2016-01-27 18:27:30 +00:00
|
|
|
print(Fore.RED, e.output.decode())
|
2016-01-17 20:06:11 +00:00
|
|
|
EXIT_CODE = 1
|
2016-01-10 16:12:58 +00:00
|
|
|
|
2016-01-27 18:27:30 +00:00
|
|
|
check_if_exit_code()
|
|
|
|
print("{}All Python tests passed! {}Testing Static Files...".format(Fore.GREEN, Fore.YELLOW))
|
2016-01-10 16:12:58 +00:00
|
|
|
|
|
|
|
|
2016-01-17 20:06:11 +00:00
|
|
|
EXIT_CODE = os.system('npm test')
|
|
|
|
check_if_exit_code()
|
2016-01-27 18:27:30 +00:00
|
|
|
|
2016-04-24 21:28:03 +01:00
|
|
|
print("{}All static tests passed! {}Running spell check...".format(Fore.GREEN, Fore.YELLOW))
|
|
|
|
|
|
|
|
EXIT_CODE = os.system('')
|
|
|
|
check_if_exit_code()
|
|
|
|
|
2016-01-27 18:27:30 +00:00
|
|
|
print("{}All Tests Passed!".format(Fore.GREEN))
|