2011-12-22 01:36:26 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
'''
|
|
|
|
Discover all instances of unittest.TestCase in this directory.
|
|
|
|
'''
|
2012-02-12 08:24:20 +00:00
|
|
|
# Import python libs
|
|
|
|
import os
|
2012-04-04 17:49:28 +00:00
|
|
|
import optparse
|
2012-02-12 09:58:15 +00:00
|
|
|
# Import salt libs
|
2012-02-12 23:03:31 +00:00
|
|
|
import saltunittest
|
2012-02-20 12:18:13 +00:00
|
|
|
from integration import TestDaemon
|
2012-02-12 09:58:15 +00:00
|
|
|
|
2012-02-12 23:03:31 +00:00
|
|
|
TEST_DIR = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))
|
2011-12-22 01:36:26 +00:00
|
|
|
|
2012-04-04 16:58:11 +00:00
|
|
|
PNUM = 50
|
|
|
|
|
2012-04-04 17:49:28 +00:00
|
|
|
|
|
|
|
def run_integration_tests(opts=None):
|
|
|
|
'''
|
|
|
|
Execute the integration tests suite
|
|
|
|
'''
|
|
|
|
if not opts:
|
|
|
|
opts = {}
|
2012-04-20 19:13:02 +00:00
|
|
|
print('~' * PNUM)
|
|
|
|
print('Setting up Salt daemons to execute tests')
|
|
|
|
print('~' * PNUM)
|
2012-02-20 12:18:13 +00:00
|
|
|
with TestDaemon():
|
2012-04-04 17:49:28 +00:00
|
|
|
if opts.get('module', True):
|
|
|
|
moduleloader = saltunittest.TestLoader()
|
|
|
|
moduletests = moduleloader.discover(
|
|
|
|
os.path.join(TEST_DIR, 'integration', 'modules'),
|
|
|
|
'*.py'
|
|
|
|
)
|
2012-04-20 19:13:02 +00:00
|
|
|
print('~' * PNUM)
|
|
|
|
print('Starting Module Tests')
|
|
|
|
print('~' * PNUM)
|
2012-04-04 17:49:28 +00:00
|
|
|
saltunittest.TextTestRunner(verbosity=1).run(moduletests)
|
|
|
|
if opts.get('client', True):
|
|
|
|
clientloader = saltunittest.TestLoader()
|
|
|
|
clienttests = clientloader.discover(os.path.join(TEST_DIR, 'integration', 'client'), '*.py')
|
2012-04-20 19:13:02 +00:00
|
|
|
print('~' * PNUM)
|
|
|
|
print('Starting Client Tests')
|
|
|
|
print('~' * PNUM)
|
2012-04-04 17:49:28 +00:00
|
|
|
saltunittest.TextTestRunner(verbosity=1).run(clienttests)
|
|
|
|
|
|
|
|
|
|
|
|
def run_unit_tests(opts=None):
|
|
|
|
'''
|
|
|
|
Execute the unit tests
|
|
|
|
'''
|
|
|
|
if not opts:
|
|
|
|
opts = {}
|
|
|
|
if not opts.get('unit', True):
|
|
|
|
return
|
2012-02-20 12:18:13 +00:00
|
|
|
loader = saltunittest.TestLoader()
|
|
|
|
tests = loader.discover(os.path.join(TEST_DIR, 'unit', 'templates'), '*.py')
|
2012-04-20 19:13:02 +00:00
|
|
|
print('~' * PNUM)
|
|
|
|
print('Starting Unit Tests')
|
|
|
|
print('~' * PNUM)
|
2012-02-20 12:18:13 +00:00
|
|
|
saltunittest.TextTestRunner(verbosity=1).run(tests)
|
|
|
|
|
2012-02-12 08:24:20 +00:00
|
|
|
|
2012-04-04 17:49:28 +00:00
|
|
|
def parse_opts():
|
|
|
|
'''
|
|
|
|
Parse command line options for running specific tests
|
|
|
|
'''
|
|
|
|
parser = optparse.OptionParser()
|
|
|
|
parser.add_option('-m',
|
|
|
|
'--module',
|
|
|
|
'--module-tests',
|
|
|
|
dest='module',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run tests for modules')
|
|
|
|
parser.add_option('-c',
|
|
|
|
'--client',
|
|
|
|
'--client-tests',
|
|
|
|
dest='client',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run tests for client')
|
|
|
|
parser.add_option('-u',
|
|
|
|
'--unit',
|
|
|
|
'--unit-tests',
|
|
|
|
dest='unit',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run unit tests')
|
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
reverse = False
|
|
|
|
|
|
|
|
opts = {}
|
|
|
|
|
2012-04-20 19:13:02 +00:00
|
|
|
for key, val in list(options.__dict__.items()):
|
2012-04-04 17:49:28 +00:00
|
|
|
if val:
|
|
|
|
reverse = True
|
|
|
|
opts[key] = not val
|
|
|
|
|
|
|
|
if reverse:
|
2012-04-20 19:13:02 +00:00
|
|
|
for key, val in list(opts.items()):
|
2012-04-04 17:49:28 +00:00
|
|
|
opts[key] = not opts[key]
|
|
|
|
|
|
|
|
return opts
|
|
|
|
|
|
|
|
|
2011-12-22 01:36:26 +00:00
|
|
|
if __name__ == "__main__":
|
2012-04-04 17:49:28 +00:00
|
|
|
opts = parse_opts()
|
|
|
|
run_integration_tests(opts)
|
|
|
|
run_unit_tests(opts)
|