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 |
fvlingen |
1.1 |
|
8 |
metson |
1.22 |
"""
|
9 |
|
|
Build, clean and test the WMCore package.
|
10 |
|
|
"""
|
11 |
|
|
|
12 |
metson |
1.21 |
class TestCommand(Command):
|
13 |
metson |
1.22 |
"""
|
14 |
|
|
Handle setup.py test with this class - walk through the directory structure
|
15 |
|
|
and build up a list of tests, then build a test suite and execute it.
|
16 |
|
|
|
17 |
|
|
TODO: Pull database URL's from environment, and skip tests where database
|
18 |
|
|
URL is not present (e.g. for a slave without Oracle connection)
|
19 |
|
|
"""
|
20 |
metson |
1.21 |
user_options = [ ]
|
21 |
|
|
|
22 |
|
|
def initialize_options(self):
|
23 |
|
|
self._dir = os.getcwd()
|
24 |
|
|
|
25 |
|
|
def finalize_options(self):
|
26 |
|
|
pass
|
27 |
|
|
|
28 |
|
|
def run(self):
|
29 |
|
|
'''
|
30 |
|
|
Finds all the tests modules in tests/, and runs them.
|
31 |
|
|
'''
|
32 |
|
|
testfiles = [ ]
|
33 |
|
|
# Walk the directory tree
|
34 |
|
|
for dirpath, dirnames, filenames in os.walk('./test/python/WMCore_t'):
|
35 |
|
|
# skipping CVS directories and their contents
|
36 |
|
|
pathelements = dirpath.split('/')
|
37 |
|
|
if not 'CVS' in pathelements:
|
38 |
|
|
# to build up a list of file names which contain tests
|
39 |
|
|
for file in filenames:
|
40 |
|
|
if file not in ['__init__.py']:
|
41 |
|
|
if file.endswith('_t.py'):
|
42 |
|
|
testmodpath = pathelements[3:]
|
43 |
|
|
testmodpath.append(file.replace('.py',''))
|
44 |
|
|
testfiles.append('.'.join(testmodpath))
|
45 |
|
|
|
46 |
|
|
testsuite = TestSuite()
|
47 |
|
|
for test in testfiles:
|
48 |
|
|
try:
|
49 |
|
|
testsuite.addTest(TestLoader().loadTestsFromName(test))
|
50 |
|
|
except Exception, e:
|
51 |
|
|
print "Could not load %s test - fix it!\n %s" % (test, e)
|
52 |
|
|
print "Running %s tests" % testsuite.countTestCases()
|
53 |
|
|
|
54 |
|
|
t = TextTestRunner(verbosity = 1)
|
55 |
|
|
t.run(testsuite)
|
56 |
|
|
|
57 |
|
|
class CleanCommand(Command):
|
58 |
metson |
1.22 |
"""
|
59 |
|
|
Clean up (delete) compiled files
|
60 |
|
|
"""
|
61 |
metson |
1.21 |
user_options = [ ]
|
62 |
|
|
|
63 |
|
|
def initialize_options(self):
|
64 |
|
|
self._clean_me = [ ]
|
65 |
|
|
for root, dirs, files in os.walk('.'):
|
66 |
|
|
for f in files:
|
67 |
|
|
if f.endswith('.pyc'):
|
68 |
|
|
self._clean_me.append(pjoin(root, f))
|
69 |
|
|
|
70 |
|
|
def finalize_options(self):
|
71 |
|
|
pass
|
72 |
|
|
|
73 |
|
|
def run(self):
|
74 |
|
|
for clean_me in self._clean_me:
|
75 |
|
|
try:
|
76 |
|
|
os.unlink(clean_me)
|
77 |
|
|
except:
|
78 |
|
|
pass
|
79 |
|
|
|
80 |
metson |
1.22 |
def getPackages(package_dirs = []):
|
81 |
|
|
packages = []
|
82 |
|
|
for dir in package_dirs:
|
83 |
|
|
for dirpath, dirnames, filenames in os.walk('./%s' % dir):
|
84 |
|
|
# Exclude things here
|
85 |
|
|
if dirpath not in ['./src/python/', './src/python/IMProv']:
|
86 |
|
|
pathelements = dirpath.split('/')
|
87 |
|
|
if not 'CVS' in pathelements:
|
88 |
|
|
path = pathelements[3:]
|
89 |
|
|
packages.append('.'.join(path))
|
90 |
|
|
return packages
|
91 |
|
|
|
92 |
|
|
package_dir = {'WMCore': 'src/python/WMCore',
|
93 |
|
|
'WMComponent' : 'src/python/WMComponent',
|
94 |
|
|
'WMQuality' : 'src/python/WMQuality'}
|
95 |
|
|
|
96 |
|
|
setup (name = 'wmcore',
|
97 |
|
|
version = '1.0',
|
98 |
metson |
1.21 |
cmdclass = { 'test': TestCommand, 'clean': CleanCommand },
|
99 |
metson |
1.22 |
package_dir = package_dir,
|
100 |
|
|
packages = getPackages(package_dir.values()),)
|
101 |
fvlingen |
1.7 |
|