root/branch/BTSniff/tests/run_all.py @ 5396

Revision 5396, 1.8 kB (checked in by qsy, 4 years ago)

PM updated with new namespace

Line 
1'''
2
3
4    Simple testing tool.
5    TODO: find out about nosetest
6
7
8'''
9
10import os, re, sys
11
12             
13def getbuilddirroot():
14    bdroot = ''.join([os.getcwd(), os.sep, 'build', os.sep])
15    build_dir_p = re.compile(r'^lib')
16    for dir in os.listdir(bdroot):
17        if build_dir_p.match(dir):
18            bdroot = ''.join([bdroot, dir])
19            break
20    return bdroot
21
22
23if not sys.platform == 'linux2':
24    print 'BTSniffing development only on Linux for now'
25    exit()
26
27# get into project root
28print "Checking we're in project root .... ",
29bdroot = testsroot = None
30if 'setup.py' in os.listdir(os.getcwd()):
31     print "yes"
32     print 'Doing disutils build'
33     os.system('python setup.py build')
34     bdroot = getbuilddirroot()
35     print 'build dir project root: ', bdroot
36else:
37    raise IOError("run_tests: not in project root. Run script in BTSniffer root")
38    exit()
39
40print 'Checking that tests exist ... ', 
41if 'tests' in os.listdir(os.getcwd()):
42    print 'yes'
43    testsroot = ''.join([os.getcwd(), os.sep, 'tests'])
44else:
45    raise IOError("run_tests: no tests folder.")
46    exit()
47   
48# Get all tests files
49testfiles = []
50testfile_p = re.compile(r'^[Tt]est')
51for f in os.listdir(testsroot):
52    if testfile_p.search(f):
53        testfiles.append(f)
54if len(testfiles) == 0:
55    raise IOError('Serious error')
56# Copy the test files over
57print 'Copying test files....'
58for file in testfiles:
59    orgtest = os.sep.join([testsroot, file])
60    print 'Copying %s to %s' % (orgtest, bdroot)
61    os.system('cp %s %s' % (os.sep.join([testsroot, file]), bdroot))
62
63print 'Running tests...'
64os.chdir(bdroot)
65os.system('nosetests')
66
67print 'Cleaning up...'
68for f in testfiles:
69    os.remove(f)
70    pycfile = ''.join([f, 'c'])
71    if os.path.exists(pycfile):
72        os.remove(pycfile)
73
Note: See TracBrowser for help on using the browser.