This repository has been archived by the owner on Feb 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
manage.py
executable file
·87 lines (66 loc) · 2.04 KB
/
manage.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
#!/usr/bin/env python3
import click
APP_FOLDER = 'exercises'
@click.group()
def cli(): # NOQA
pass
@cli.command()
@click.option('--only', '-o', multiple=True)
@click.option('--coverage', 'with_coverage', is_flag=True)
@click.option('--no-html', is_flag=True)
@click.option('--no-report', is_flag=True)
@click.option('--verbose', '-v', is_flag=True)
def test(with_coverage, no_html, no_report, verbose, only):
"""Run the tests."""
if with_coverage:
# Initialize coverage.py.
import coverage
COV = coverage.coverage(branch=True,
source=[APP_FOLDER])
COV.start()
# Decide what arguments to use.
args = []
if only:
for name in only:
args.append('tests/test_{}.py'.format(name))
else:
args.append('tests')
if verbose:
args.append('-v')
# Invoke pytest
import pytest
exit_code = pytest.main(args)
if with_coverage:
# Sum up the results of the code coverage analysis.
COV.stop()
COV.save()
if not no_html:
# Generate HTML report and move to tmp directory.
import os
basedir = os.path.abspath(os.path.dirname(__file__))
covdir = os.path.join(basedir, 'tmp/coverage')
COV.html_report(directory=covdir)
if not no_report:
# Show the report and clean up.
click.echo('\nCoverage Summary\n{}'.format('=' * 70))
COV.report()
COV.erase()
raise SystemExit(exit_code)
@cli.command()
@click.option('--all', is_flag=True)
@click.option('--stats', is_flag=True)
def lint(all, stats):
"""Run the linter."""
import os
if all:
click.echo('Running linter (including skeleton code).')
args = ['flake8', '.']
else:
click.echo('Running Linter...')
args = ['flake8', APP_FOLDER]
if stats:
args.extend(['--statistics', '-qq'])
exit_code = os.system(' '.join(args))
raise SystemExit(exit_code)
if __name__ == "__main__":
cli()