| 1 |
#!/usr/bin/env python |
|---|
| 2 |
# |
|---|
| 3 |
# Run all dm tests. |
|---|
| 4 |
# |
|---|
| 5 |
|
|---|
| 6 |
import os |
|---|
| 7 |
import sys |
|---|
| 8 |
import re |
|---|
| 9 |
import unittest |
|---|
| 10 |
from optparse import OptionParser |
|---|
| 11 |
|
|---|
| 12 |
os.environ['DJANGO_SETTINGS_MODULE'] = 'dm.django.settings.main' |
|---|
| 13 |
|
|---|
| 14 |
if __name__ == "__main__": |
|---|
| 15 |
usage = 'usage: %prog [options] [module_name]' |
|---|
| 16 |
usage += '\n\tmodule_name specifies the module to test. ' |
|---|
| 17 |
usage += 'If none supplied then run all tests.' |
|---|
| 18 |
parser = OptionParser(usage) |
|---|
| 19 |
parser.add_option('-v', '--verbose', |
|---|
| 20 |
action='store_true', dest='verbose', default=False, |
|---|
| 21 |
help='Be verbose in printing status messages') |
|---|
| 22 |
parser.add_option('-l', '--level', |
|---|
| 23 |
action='store', type='int', dest='level', default=1, |
|---|
| 24 |
help='Verbosity level of test runner') |
|---|
| 25 |
# todo: fix this, which breaks optparse v1.4.1: |
|---|
| 26 |
# optparse.OptionError: option -c/--conf: invalid option type: 'str' |
|---|
| 27 |
parser.add_option('-c', '--conf', |
|---|
| 28 |
action='store', dest='config', default='', |
|---|
| 29 |
# action='store', type='str', dest='config', default='', |
|---|
| 30 |
help='Path to configuration file. If not provided please ensure relevant environment variable is set.' |
|---|
| 31 |
) |
|---|
| 32 |
parser.add_option('-p', '--profile', |
|---|
| 33 |
action='store_true', dest='profile', default=False, |
|---|
| 34 |
help='Profile the performance of a test suite') |
|---|
| 35 |
|
|---|
| 36 |
(options, args) = parser.parse_args() |
|---|
| 37 |
if options.config: |
|---|
| 38 |
os.environ['DOMAINMODEL_SETTINGS'] = options.config |
|---|
| 39 |
|
|---|
| 40 |
import dm.testunit |
|---|
| 41 |
dm.testunit.DevApplication() |
|---|
| 42 |
|
|---|
| 43 |
(options, args) = parser.parse_args() |
|---|
| 44 |
# by default always 1 argument (name of file itself) |
|---|
| 45 |
suiteToRun = None |
|---|
| 46 |
moduleName = '' |
|---|
| 47 |
moduleName = 'dm.test' |
|---|
| 48 |
if len(args) == 1: |
|---|
| 49 |
moduleName = args[0] |
|---|
| 50 |
elif len(args) >= 1: |
|---|
| 51 |
parser.print_help() |
|---|
| 52 |
sys.exit(1) |
|---|
| 53 |
|
|---|
| 54 |
testModuleName = moduleName |
|---|
| 55 |
testModule = __import__(testModuleName,'','','*') |
|---|
| 56 |
testSuite = testModule.suite() |
|---|
| 57 |
|
|---|
| 58 |
testRunner = unittest.TextTestRunner(verbosity=options.level) |
|---|
| 59 |
if options.profile: |
|---|
| 60 |
code = "result = testRunner.run(testSuite)" |
|---|
| 61 |
import profile |
|---|
| 62 |
profile.run(code) |
|---|
| 63 |
else: |
|---|
| 64 |
result = testRunner.run(testSuite) |
|---|
| 65 |
|
|---|
| 66 |
if not result.wasSuccessful(): |
|---|
| 67 |
sys.exit(1) |
|---|
| 68 |
|
|---|