1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#!/usr/bin/env python
import string, time
import TestSuite
### Methods ###
def runTests(tests, testSuite):
banner = 'Performing a test of DOM Core/Traversal/HTML'
markers = '#'*((testSuite.columns - len(banner)) / 2 - 1)
print markers, banner, markers
total = 0.0
for test in tests:
module = __import__('test_' + string.lower(test))
start = time.time()
module.test(testSuite)
total = total + time.time() - start
return total
### Application ###
if __name__ == '__main__':
logLevel = 1
logFile = None
haltOnError = 1
test_list = ['Node',
'NodeList',
'NamedNodeMap',
'NodeIterator',
'TreeWalker',
'Attr',
'Element',
'DocumentFragment',
'Document',
'DOMImplementation',
'CharacterData',
'Comment',
'Text',
'CDATASection',
'DocumentType',
'Entity',
'EntityReference',
'Notation',
'ProcessingInstruction',
'Struct',
'HTML',
#'Demo',
#'Pythonic'
]
import sys, os, getopt
prog_name = os.path.split(sys.argv[0])[1]
short_opts = 'hl:nqtv:'
long_opts = ['help',
'log=',
'no-error'
'tests'
'quiet',
'verbose='
]
usage = '''Usage: %s [options] [[all] [test]...]
Options:
-h, --help Print this message and exit
-l, --log <file> Write output to a log file (default=%s)
-n, --no-error Continue testing if error condition
-q, --quiet Display as little as possible
-t, --tests Show a list of tests that can be run
-v, --verbose <level> Set the output level (default=%s)
0 - display nothing
1 - errors only (same as --quiet)
2 - warnings and errors
3 - information, warnings and errors
4 - display everything
''' %(prog_name, logFile, logLevel)
command_line_error = 0
bad_options = []
finished = 0
args = sys.argv[1:]
while not finished:
try:
optlist, args = getopt.getopt(args, short_opts, long_opts)
except getopt.error, data:
bad_options.append(string.split(data)[1])
args.remove(bad_options[-1])
command_line_error = 1
else:
finished = 1
display_usage = 0
display_tests = 0
for op in optlist:
if op[0] == '-h' or op[0] == '--help':
display_usage = 1
elif op[0] == "-l" or op[0] == '--log':
logFile = op[1]
elif op[0] == '-n' or op[0] == '--no-error':
haltOnError = 0
elif op[0] == '-t' or op[0] == '--tests':
display_tests = 1
elif op[0] == '-q' or op[0] == '--quiet':
logLevel = 1
elif op[0] == '-v' or op[0] == '--verbose':
logLevel = int(op[1])
all_tests = 0
if args:
lower_test = []
for test in test_list:
lower_test.append(string.lower(test))
for test in args:
if string.lower(test) == 'all':
all_tests = 1
break
if string.lower(test) not in lower_test:
print "%s: Test not found '%s'" %(prog_name, test)
args.remove(test)
display_tests = 1
if len(args) and not all_tests:
tests = args
elif not display_tests:
tests = test_list
if command_line_error or display_usage or display_tests:
for op in bad_options:
print "%s: Unrecognized option '%s'" %(prog_name,op)
if display_usage:
print usage
if display_tests:
print 'Available tests are:'
for t in test_list:
print ' %s' % t
sys.exit(command_line_error)
testSuite = TestSuite.TestSuite(haltOnError)
total = runTests(tests, testSuite)
print "Test Time - %.3f secs" % total
|