forked from coleifer/peewee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.py
executable file
·83 lines (67 loc) · 2.24 KB
/
runtests.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
#!/usr/bin/env python
import optparse
import os
import shutil
import sys
import unittest
def collect():
import tests
runtests(tests, 1)
def runtests(suite, verbosity):
results = unittest.TextTestRunner(verbosity=verbosity).run(suite)
return results.failures, results.errors
def get_option_parser():
usage = 'usage: %prog [-e engine_name, other options] module1, module2 ...'
parser = optparse.OptionParser(usage=usage)
basic = optparse.OptionGroup(parser, 'Basic test options')
basic.add_option(
'-e',
'--engine',
dest='engine',
help=('Database engine to test, one of '
'[sqlite, postgres, mysql, apsw, sqlcipher]'))
basic.add_option('-v', '--verbosity', dest='verbosity', default=1, type='int', help='Verbosity of output')
parser.add_option_group(basic)
return parser
def collect_modules(options, args):
modules = []
from peewee import print_
for arg in args:
try:
__import__('tests.%s' % arg)
modules.append(sys.modules['tests.%s' % arg])
except ImportError:
print_('ERROR: unable to import requested tests: "tests.%s"' % arg)
if not modules:
import tests
modules.insert(0, tests)
return modules
if __name__ == '__main__':
parser = get_option_parser()
options, args = parser.parse_args()
if options.engine:
os.environ['PEEWEE_TEST_BACKEND'] = options.engine
os.environ['PEEWEE_TEST_VERBOSITY'] = str(options.verbosity)
suite = unittest.TestSuite()
for module in collect_modules(options, args):
module_suite = unittest.TestLoader().loadTestsFromModule(module)
suite.addTest(module_suite)
failures, errors = runtests(suite, options.verbosity)
files_to_delete = [
'peewee_test.db',
'peewee_test',
'tmp.db',
'peewee_test.bdb.db',
'peewee_test.cipher.db']
paths_to_delete = ['peewee_test.bdb.db-journal']
for filename in files_to_delete:
if os.path.exists(filename):
os.unlink(filename)
for path in paths_to_delete:
if os.path.exists(path):
shutil.rmtree(path)
if errors:
sys.exit(2)
elif failures:
sys.exit(1)
sys.exit(0)