-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtasks.py
75 lines (55 loc) · 1.52 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
import subprocess
import webbrowser
import shutil
from pathlib import Path
from invoke import task
from sys import executable
import os
def print_red(s):
print("\033[91m {}\033[00m".format(s), end="")
def print_green(s):
print("\033[92m {}\033[00m".format(s), end="")
@task
def clean_test(context):
"""
Cleans the test store
"""
shutil.rmtree(Path(".pytest_cache"), ignore_errors=True)
@task
def fix_lint(context):
"""
Fixes all linting and import sort errors. Skips init.py files for import sorts
"""
subprocess.run(["black", "explingo"])
subprocess.run(["black", "tests"])
subprocess.run(["isort", "--atomic", "explingo", "tests"])
@task
def lint(context):
"""
Runs the linting and import sort process on all library files and tests and prints errors.
Skips init.py files for import sorts
"""
subprocess.run(["flake8", "explingo", "tests"], check=True)
subprocess.run(["isort", "explingo", "tests"], check=True)
@task
def test(context):
"""
Runs all test commands.
"""
failures_in = []
try:
test_unit(context)
except subprocess.CalledProcessError:
failures_in.append("Unit tests")
if len(failures_in) == 0:
print_green("\nAll tests successful :)")
else:
print_red("\n:( Failures in: ")
for i in failures_in:
print_red(i + ", ")
@task
def test_unit(context):
"""
Runs all unit tests and outputs results and coverage
"""
subprocess.run(["pytest"], check=True)