-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
76 lines (59 loc) · 1.9 KB
/
tasks.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
"""
Definition of all invoke CLI commands for this project.
"""
from invoke import task
project_name = "scargo"
@task
def install(c):
"""
Install all requirements and setup poetry environment.
"""
c.run("poetry install")
c.run("poetry run pre-commit install")
@task
def check(c, fix=True):
"""
Runs all static checks; black and pylint. If 'fix == False', black will
only check the files and not modify them. Use '--no-fix' to disable
auto-fixing.
"""
check_command = ""
if not fix:
check_command = " --check "
print("Black")
c.run(f"black {check_command} {project_name}/")
c.run(f"black {check_command} examples/")
print("Style checks")
c.run(f"pylint {project_name}/ --output-format=colorized")
c.run(f"pylint examples/ --output-format=colorized")
@task
def test(c, coverage=False, html_report=False, keyword=None):
"""
Run tests using pytest.
Parameters
----------
coverage : bool
Enable printing out test coverage of code.
html_report : bool
Generate detailed interactive test coverage report. To view the report, navigate to the htmlcov/ directory, open
the index.html in a browser and view the interactive coverage report.
keyword : str, optional
Subselects tests given the provided substring/keyword. Works exactly like the `pytest` `-k` flag.
Example usage:
inv test
inv test -k TestUtils
inv test --coverage --html-report
inv test --coverage --html-report -k TestUtils
"""
if keyword is None:
keyword_filter = ""
else:
keyword_filter = f"-k {keyword}"
test_command = f"pytest -vvv {keyword_filter} . --color=yes"
if coverage:
test_command = f"coverage run -m {test_command}"
c.run(test_command)
if coverage:
c.run("coverage report -m")
if html_report:
c.run("coverage html")