This repository was archived by the owner on Jan 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtasks.py
98 lines (74 loc) · 2.25 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import sys
import webbrowser
from invoke import task
# Name definitions
db_files = ['db.sqlite3', 'db.sqlite3-shm', 'db.sqlite3-wal']
config = 'bot/config_reader.py'
app = 'bot/application.py'
comm = 'bot/communication.py'
linter = 'linter/linter.py'
first_test = 'tests.test_dialogs.TestBotDialogs.test_if_comm_answers_greetings'
config_test = 'tests/test_config_reader.py'
app_test = 'tests/test_application.py'
comm_test = 'tests/test_communication.py'
dialog_test = 'tests/test_dialogs.py'
linter_test = 'tests/test_linter.py'
@task
def rmdb(c):
""" Removes all test databases """
for db_file in db_files:
if os.path.exists(db_file):
os.remove(db_file)
@task(rmdb)
def test(c, vv=False):
""" Runs all tests """
detail = ""
if vv:
detail = '-vv'
c.run(f'green3 {first_test}')
c.run(f'green3 {app_test} {comm_test} {linter_test} {config_test} {detail}')
@task
def style(c):
""" Cheks if your code is well formatted for this project """
c.run('pycodestyle bot/. tests/. --ignore=E402,W504')
@task
def doc(c):
""" Checks if your code is well documented """
c.run('make --directory docs/ html')
webbrowser.open('file://' + os.path.realpath('docs/_build/html/index.html'))
c.run('pydocstyle bot/. tests/.')
@task(rmdb)
def run(c):
""" Run bot.py """
c.run('python ' + app)
@task()
def travis(c):
""" Runs the tests checked by Travis """
style(c)
lint(c)
test(c)
cov(c)
@task
def install(c):
""" Installs the requirements necessary for this project """
c.run('pip3 install -r requirements.txt')
@task
def encrypt(c):
""" Encrypts key for Heroku (for admins only) """
c.run('travis encrypt-file bot/config.ini --add')
@task(rmdb)
def cov(c):
""" Checks how much of the program is covered by tests """
c.run(f'coverage run -m py.test\
{app_test} {comm_test} {linter_test} {config_test}')
c.run(f'coverage report -m {app} {comm} {linter} {config}')
c.run(f'coverage html {app} {comm} {linter} {config}')
@task()
def lint(c):
""" Checks yaml file structure """
c.run('yamllint bot')
@task()
def encrypt(c):
""" Needed only when encrypting bot token to travis """
c.run('travis encrypt-file bot/config.ini --add')