-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.py
88 lines (65 loc) · 2.29 KB
/
commands.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
# -*- coding:utf-8 -*-
from flask.ext.script import Command, Option, prompt_bool
import os
class CreateDB(Command):
"""
Creates database using SQLAlchemy
"""
def run(self):
try:
from database import create_all
create_all()
except ImportError, e:
print "Please, make sure database.create_all exists in order to create a db."
class DropDB(Command):
"""
Drops database using SQLAlchemy
"""
def run(self):
try:
from database import drop_all
drop_all()
except ImportError, e:
print "Please, make sure database.drop_all exists in order to drop a db."
class Test(Command):
"""
Run tests
"""
verbosity = 2
failfast = False
def get_options(self):
return [
Option('--verbosity', '-v', dest='verbose',
type=int, default=self.verbosity),
Option('--failfast', dest='failfast',
default=self.failfast, action='store_false')
]
def run(self, verbosity, failfast):
import sys
import glob
import unittest
exists = os.path.exists
isdir = os.path.isdir
join = os.path.join
project_path = os.path.abspath(os.path.dirname('.'))
sys.path.insert(0, project_path)
# our special folder for blueprints
if exists('apps'):
sys.path.insert(0, join('apps'))
loader = unittest.TestLoader()
all_tests = []
if exists('apps'):
for path in glob.glob('apps/*'):
if isdir(path):
tests_dir = join(path, 'tests')
if exists(join(path, 'tests.py')):
all_tests.append(loader.discover(path, 'tests.py'))
elif exists(tests_dir):
all_tests.append(loader.discover(tests_dir, pattern='test*.py'))
if exists('tests') and isdir('tests'):
all_tests.append(loader.discover('tests', pattern='test*.py'))
elif exists('tests.py'):
all_tests.append(loader.discover('.', pattern='tests.py'))
test_suite = unittest.TestSuite(all_tests)
unittest.TextTestRunner(
verbosity=verbosity, failfast=failfast).run(test_suite)