forked from nryoung/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
executable file
·59 lines (44 loc) · 1.16 KB
/
run_tests.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import subprocess
import sys
import pytest
FLAKE8_ARGS = ['algorithms', 'tests']
sys.path.append(os.path.dirname(__file__))
def exit_on_failure(ret, message=None):
if ret:
sys.exit(ret)
def flake8_main(args):
print('Running flake8 code linting')
ret = subprocess.call(['flake8'] + args)
print('flake8 failed' if ret else 'flake8 passed')
return ret
if __name__ == '__main__':
pytest_args = sys.argv[1:]
run_tests = True
run_flake8 = True
# Logic to run flake8 only
try:
sys.argv.remove('--lintonly')
except ValueError:
run_tests = True
else:
run_tests = False
run_flake8 = True
# Logic to run pytest with coverage turned on
try:
pytest_args.remove('--coverage')
except ValueError:
pass
else:
pytest_args = [
'--cov-report',
'xml',
'--cov',
'algorithms'] + pytest_args
if run_tests:
exit_on_failure(pytest.main(pytest_args))
if run_flake8:
exit_on_failure(flake8_main(FLAKE8_ARGS))