1 |
fvlingen |
1.1 |
#!/usr/bin/env python
|
2 |
metson |
1.21 |
from distutils.core import setup, Command
|
3 |
|
|
from unittest import TextTestRunner, TestLoader, TestSuite
|
4 |
|
|
from glob import glob
|
5 |
|
|
from os.path import splitext, basename, join as pjoin, walk
|
6 |
|
|
import os
|
7 |
metson |
1.23 |
from pylint import lint
|
8 |
fvlingen |
1.1 |
|
9 |
metson |
1.22 |
"""
|
10 |
|
|
Build, clean and test the WMCore package.
|
11 |
|
|
"""
|
12 |
|
|
|
13 |
metson |
1.21 |
class TestCommand(Command):
|
14 |
metson |
1.22 |
"""
|
15 |
|
|
Handle setup.py test with this class - walk through the directory structure
|
16 |
|
|
and build up a list of tests, then build a test suite and execute it.
|
17 |
|
|
|
18 |
|
|
TODO: Pull database URL's from environment, and skip tests where database
|
19 |
|
|
URL is not present (e.g. for a slave without Oracle connection)
|
20 |
|
|
"""
|
21 |
metson |
1.21 |
user_options = [ ]
|
22 |
|
|
|
23 |
|
|
def initialize_options(self):
|
24 |
|
|
self._dir = os.getcwd()
|
25 |
|
|
|
26 |
|
|
def finalize_options(self):
|
27 |
|
|
pass
|
28 |
|
|
|
29 |
|
|
def run(self):
|
30 |
|
|
'''
|
31 |
metson |
1.25 |
Finds all the tests modules in test/python/WMCore_t, and runs them.
|
32 |
metson |
1.21 |
'''
|
33 |
|
|
testfiles = [ ]
|
34 |
metson |
1.26 |
|
35 |
|
|
# Add the test and src directory to the python path
|
36 |
|
|
testspypath = '/'.join([self._dir, 'test/python/'])
|
37 |
|
|
srcpypath = '/'.join([self._dir, 'src/python/'])
|
38 |
|
|
oldpypath = os.environ['PYTHONPATH']
|
39 |
|
|
os.environ['PYTHONPATH'] = ':'.join([oldpypath, testspypath, srcpypath])
|
40 |
|
|
print os.environ['PYTHONPATH']
|
41 |
metson |
1.21 |
# Walk the directory tree
|
42 |
|
|
for dirpath, dirnames, filenames in os.walk('./test/python/WMCore_t'):
|
43 |
|
|
# skipping CVS directories and their contents
|
44 |
|
|
pathelements = dirpath.split('/')
|
45 |
|
|
if not 'CVS' in pathelements:
|
46 |
|
|
# to build up a list of file names which contain tests
|
47 |
|
|
for file in filenames:
|
48 |
|
|
if file not in ['__init__.py']:
|
49 |
|
|
if file.endswith('_t.py'):
|
50 |
|
|
testmodpath = pathelements[3:]
|
51 |
|
|
testmodpath.append(file.replace('.py',''))
|
52 |
|
|
testfiles.append('.'.join(testmodpath))
|
53 |
|
|
|
54 |
|
|
testsuite = TestSuite()
|
55 |
|
|
for test in testfiles:
|
56 |
|
|
try:
|
57 |
|
|
testsuite.addTest(TestLoader().loadTestsFromName(test))
|
58 |
|
|
except Exception, e:
|
59 |
|
|
print "Could not load %s test - fix it!\n %s" % (test, e)
|
60 |
|
|
print "Running %s tests" % testsuite.countTestCases()
|
61 |
|
|
|
62 |
|
|
t = TextTestRunner(verbosity = 1)
|
63 |
|
|
t.run(testsuite)
|
64 |
metson |
1.26 |
|
65 |
|
|
# Reset the python path
|
66 |
|
|
os.environ['PYTHONPATH'] = oldpypath
|
67 |
|
|
|
68 |
metson |
1.21 |
class CleanCommand(Command):
|
69 |
metson |
1.22 |
"""
|
70 |
|
|
Clean up (delete) compiled files
|
71 |
|
|
"""
|
72 |
metson |
1.21 |
user_options = [ ]
|
73 |
|
|
|
74 |
|
|
def initialize_options(self):
|
75 |
|
|
self._clean_me = [ ]
|
76 |
|
|
for root, dirs, files in os.walk('.'):
|
77 |
|
|
for f in files:
|
78 |
|
|
if f.endswith('.pyc'):
|
79 |
|
|
self._clean_me.append(pjoin(root, f))
|
80 |
|
|
|
81 |
|
|
def finalize_options(self):
|
82 |
|
|
pass
|
83 |
|
|
|
84 |
|
|
def run(self):
|
85 |
|
|
for clean_me in self._clean_me:
|
86 |
|
|
try:
|
87 |
|
|
os.unlink(clean_me)
|
88 |
|
|
except:
|
89 |
|
|
pass
|
90 |
|
|
|
91 |
metson |
1.23 |
class LintCommand(Command):
|
92 |
metson |
1.24 |
"""
|
93 |
|
|
Lint all files in the src tree
|
94 |
|
|
|
95 |
|
|
TODO: better format the test results, get some global result, make output
|
96 |
|
|
more buildbot friendly.
|
97 |
|
|
"""
|
98 |
|
|
|
99 |
metson |
1.23 |
user_options = [ ]
|
100 |
|
|
|
101 |
|
|
def initialize_options(self):
|
102 |
|
|
self._dir = os.getcwd()
|
103 |
|
|
|
104 |
|
|
def finalize_options(self):
|
105 |
|
|
pass
|
106 |
|
|
|
107 |
|
|
def run(self):
|
108 |
|
|
'''
|
109 |
|
|
Find the code and run lint on it
|
110 |
|
|
'''
|
111 |
|
|
files = [ ]
|
112 |
metson |
1.26 |
|
113 |
|
|
srcpypath = '/'.join([self._dir, 'src/python/'])
|
114 |
|
|
oldpypath = os.environ['PYTHONPATH']
|
115 |
|
|
os.environ['PYTHONPATH'] = ':'.join([oldpypath, srcpypath])
|
116 |
|
|
|
117 |
metson |
1.23 |
# Walk the directory tree
|
118 |
|
|
for dirpath, dirnames, filenames in os.walk('./src/python/'):
|
119 |
|
|
# skipping CVS directories and their contents
|
120 |
|
|
pathelements = dirpath.split('/')
|
121 |
metson |
1.27 |
|
122 |
metson |
1.23 |
if not 'CVS' in pathelements:
|
123 |
|
|
# to build up a list of file names which contain tests
|
124 |
|
|
for file in filenames:
|
125 |
metson |
1.27 |
if file.endswith('.py'):
|
126 |
|
|
filepath = '/'.join([dirpath, file])
|
127 |
|
|
files.append(filepath)
|
128 |
|
|
# run individual tests as follows
|
129 |
|
|
try:
|
130 |
|
|
lint.Run(['--rcfile=standards/.pylintrc', filepath])
|
131 |
|
|
except Exception, e:
|
132 |
|
|
print "Couldn't lint %s\n%s %s" % (file, e, type(e))
|
133 |
metson |
1.23 |
# Could run a global test as:
|
134 |
|
|
#input = ['--rcfile=standards/.pylintrc']
|
135 |
|
|
#input.extend(files)
|
136 |
|
|
#lint.Run(input)
|
137 |
metson |
1.26 |
|
138 |
|
|
os.environ['PYTHONPATH'] = oldpypath
|
139 |
metson |
1.23 |
|
140 |
metson |
1.22 |
def getPackages(package_dirs = []):
|
141 |
|
|
packages = []
|
142 |
|
|
for dir in package_dirs:
|
143 |
|
|
for dirpath, dirnames, filenames in os.walk('./%s' % dir):
|
144 |
|
|
# Exclude things here
|
145 |
|
|
if dirpath not in ['./src/python/', './src/python/IMProv']:
|
146 |
|
|
pathelements = dirpath.split('/')
|
147 |
|
|
if not 'CVS' in pathelements:
|
148 |
|
|
path = pathelements[3:]
|
149 |
|
|
packages.append('.'.join(path))
|
150 |
|
|
return packages
|
151 |
|
|
|
152 |
|
|
package_dir = {'WMCore': 'src/python/WMCore',
|
153 |
|
|
'WMComponent' : 'src/python/WMComponent',
|
154 |
|
|
'WMQuality' : 'src/python/WMQuality'}
|
155 |
|
|
|
156 |
|
|
setup (name = 'wmcore',
|
157 |
|
|
version = '1.0',
|
158 |
metson |
1.23 |
cmdclass = { 'test': TestCommand,
|
159 |
|
|
'clean': CleanCommand,
|
160 |
|
|
'lint': LintCommand },
|
161 |
metson |
1.22 |
package_dir = package_dir,
|
162 |
|
|
packages = getPackages(package_dir.values()),)
|
163 |
fvlingen |
1.7 |
|