2010-07-23 23:51:41 +00:00
|
|
|
#!/usr/bin/env python
|
2011-08-25 04:54:36 +00:00
|
|
|
|
2010-01-08 07:01:19 +00:00
|
|
|
import os
|
2011-08-25 04:54:36 +00:00
|
|
|
import sys
|
2013-05-17 10:18:00 +00:00
|
|
|
sys.path=['/Users/jocke/Dropbox/06_dev/SleekXMPP']+sys.path
|
|
|
|
|
2011-08-25 04:54:36 +00:00
|
|
|
import logging
|
|
|
|
import unittest
|
|
|
|
import distutils.core
|
|
|
|
|
2013-05-17 10:18:00 +00:00
|
|
|
|
2011-08-25 04:54:36 +00:00
|
|
|
from glob import glob
|
2011-08-25 07:21:53 +00:00
|
|
|
from os.path import splitext, basename, join as pjoin
|
2011-08-25 04:54:36 +00:00
|
|
|
|
|
|
|
|
2013-05-17 10:18:00 +00:00
|
|
|
def run_tests(exlude=None, include=[]):
|
2011-08-25 04:54:36 +00:00
|
|
|
"""
|
|
|
|
Find and run all tests in the tests/ directory.
|
|
|
|
|
|
|
|
Excludes live tests (tests/live_*).
|
|
|
|
"""
|
|
|
|
testfiles = ['tests.test_overall']
|
|
|
|
exclude = ['__init__.py', 'test_overall.py']
|
2011-08-25 07:21:53 +00:00
|
|
|
for t in glob(pjoin('tests', '*.py')):
|
2011-08-25 04:54:36 +00:00
|
|
|
if True not in [t.endswith(ex) for ex in exclude]:
|
|
|
|
if basename(t).startswith('test_'):
|
|
|
|
testfiles.append('tests.%s' % splitext(basename(t))[0])
|
2013-05-17 10:18:00 +00:00
|
|
|
testsToUse=[]
|
|
|
|
if not(include==[]):
|
|
|
|
# use only test that has any text include in them
|
|
|
|
for match in include:
|
|
|
|
for test in testfiles:
|
|
|
|
if test.find(match)>-1:
|
|
|
|
# add the test'
|
|
|
|
# print "REMOVE "+match + " test " + test + " " + str(test.find(match))
|
|
|
|
testsToUse.append(test)
|
|
|
|
|
|
|
|
|
|
|
|
testfiles=testsToUse
|
2011-08-25 04:54:36 +00:00
|
|
|
suites = []
|
|
|
|
for file in testfiles:
|
|
|
|
__import__(file)
|
|
|
|
suites.append(sys.modules[file].suite)
|
|
|
|
|
|
|
|
tests = unittest.TestSuite(suites)
|
|
|
|
runner = unittest.TextTestRunner(verbosity=2)
|
|
|
|
|
|
|
|
# Disable logging output
|
|
|
|
logging.basicConfig(level=100)
|
|
|
|
logging.disable(100)
|
|
|
|
|
|
|
|
result = runner.run(tests)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
# Add a 'test' command for setup.py
|
|
|
|
|
|
|
|
class TestCommand(distutils.core.Command):
|
|
|
|
|
|
|
|
user_options = [ ]
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
self._dir = os.getcwd()
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
run_tests()
|
2010-01-08 07:01:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2013-05-17 10:18:00 +00:00
|
|
|
result = run_tests(include=['323'])
|
2011-08-25 04:54:36 +00:00
|
|
|
print("<tests %s ran='%s' errors='%s' fails='%s' success='%s' />" % (
|
|
|
|
"xmlns='http//andyet.net/protocol/tests'",
|
|
|
|
result.testsRun, len(result.errors),
|
|
|
|
len(result.failures), result.wasSuccessful()))
|