forked from panpanpandas/ultrafinance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupCommand.py
58 lines (48 loc) · 1.57 KB
/
setupCommand.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
'''
Created on July 4, 2011
@author: ppa
copied from http://da44en.wordpress.com/2002/11/22/using-distutils/
'''
from distutils.core import Command
from unittest import TextTestRunner, TestLoader
from glob import glob
from os.path import splitext, basename, join as pjoin
import os
class TestCommand(Command):
''' test command for setup.py '''
user_options = [ ]
def initialize_options(self):
self._dir = os.getcwd()
def finalize_options(self):
pass
def run(self):
'''
Finds all the tests modules in tests/, and runs them.
'''
testfiles = []
for t in glob(pjoin(self._dir, 'tests', 'unit', '*.py')):
if not t.endswith('__init__.py'):
testfiles.append('.'.join(
['tests', 'unit', splitext(basename(t))[0]])
)
print('Running tests: %s' % testfiles)
tests = TestLoader().loadTestsFromNames(testfiles)
t = TextTestRunner(verbosity = 1)
t.run(tests)
class CleanCommand(Command):
''' clean command for setup.py '''
user_options = [ ]
def initialize_options(self):
self._clean_me = [ ]
for root, _, files in os.walk('.'):
for f in files:
if f.endswith('.pyc'):
self._clean_me.append(pjoin(root, f))
def finalize_options(self):
pass
def run(self):
for clean_me in self._clean_me:
try:
os.unlink(clean_me)
except:
pass