forked from manosim/django-rest-framework-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.py
58 lines (43 loc) · 1.52 KB
/
runtests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
import os
import sys
import subprocess
import django
from coverage import coverage
from django.conf import settings
from django.test.utils import get_runner
FLAKE8_ARGS = ['demo/project/', 'rest_framework_docs', 'tests/', '--ignore=E501']
def exit_on_failure(command, message=None):
if command:
sys.exit(command)
def flake8_main(args):
print('Running: flake8', FLAKE8_ARGS)
command = subprocess.call(['flake8'] + args)
print("" if command else "Success. flake8 passed.")
return command
def run_tests_eslint():
print('Running: eslint')
command = subprocess.call(['cd rest_framework_docs/static/ && npm test'], shell=True)
print("" if command else "Success. eslint passed.")
return command
def run_tests_coverage():
if __name__ == "__main__":
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner()
# Setup Coverage
cov = coverage(source=["rest_framework_docs"], omit=["rest_framework_docs/__init__.py"])
cov.start()
failures = test_runner.run_tests(["tests"])
if bool(failures):
cov.erase()
sys.exit("Tests Failed. Coverage Cancelled.")
# If success show coverage results
cov.stop()
cov.save()
cov.report()
cov.html_report(directory='covhtml')
exit_on_failure(flake8_main(FLAKE8_ARGS))
exit_on_failure(run_tests_eslint())
exit_on_failure(run_tests_coverage())