forked from adamchainz/django-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.py
executable file
·100 lines (77 loc) · 2.13 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import subprocess
import pytest
from flake8.main import main as flake8_main
from lib2to3.main import main as lib2to3_main
def main():
try:
sys.argv.remove('--nolint')
except ValueError:
run_lint = True
else:
run_lint = False
try:
sys.argv.remove('--lintonly')
except ValueError:
run_tests = True
else:
run_tests = False
if run_tests:
exit_on_failure(tests_main())
if run_lint:
exit_on_failure(run_flake8())
exit_on_failure(run_2to3())
exit_on_failure(run_isort())
# Broken on 2.7.9 due to http://bugs.python.org/issue23063
if sys.version_info[:3] != (2, 7, 9):
exit_on_failure(run_setup_py_check())
def tests_main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
sys.path.insert(0, "tests")
return pytest.main()
def run_flake8():
print('Running flake8 code linting')
try:
original_argv = sys.argv
sys.argv = ['flake8', 'django_mysql', 'tests']
did_fail = False
flake8_main()
except SystemExit:
did_fail = True
finally:
sys.argv = original_argv
print('flake8 failed' if did_fail else 'flake8 passed')
return did_fail
def run_2to3():
print('Running 2to3 checks')
ret = lib2to3_main('lib2to3.fixes', [
'-f', 'idioms',
'-f', 'isinstance',
'-f', 'set_literal',
'-f', 'tuple_params',
'-j', '4',
'django_mysql', 'tests'
])
print('2to3 failed' if ret else '2to3 passed')
return ret
def run_isort():
print('Running isort check')
return subprocess.call([
'isort', '--recursive', '--check-only', '--diff',
'django_mysql', 'tests'
])
def run_setup_py_check():
print('Running setup.py check')
return subprocess.call([
'python', 'setup.py', 'check',
'-s', '--restructuredtext', '--metadata'
])
def exit_on_failure(ret, message=None):
if ret:
sys.exit(ret)
if __name__ == '__main__':
main()