New test function by Sjoerd, adding -t option.

This commit is contained in:
Guido van Rossum 1998-12-22 14:23:50 +00:00
parent 7ea1d972d1
commit af5add4629
1 changed files with 24 additions and 9 deletions

View File

@ -795,16 +795,20 @@ class TestXMLParser(XMLParser):
self.flush() self.flush()
def test(args = None): def test(args = None):
import sys import sys, getopt
from time import time
if not args: if not args:
args = sys.argv[1:] args = sys.argv[1:]
if args and args[0] == '-s': opts, args = getopt.getopt(args, 'st')
args = args[1:] klass = TestXMLParser
klass = XMLParser do_time = 0
else: for o, a in opts:
klass = TestXMLParser if o == '-s':
klass = XMLParser
elif o == '-t':
do_time = 1
if args: if args:
file = args[0] file = args[0]
@ -825,13 +829,24 @@ def test(args = None):
f.close() f.close()
x = klass() x = klass()
t0 = time()
try: try:
for c in data: if do_time:
x.feed(c) x.feed(data)
x.close() x.close()
else:
for c in data:
x.feed(c)
x.close()
except RuntimeError, msg: except RuntimeError, msg:
t1 = time()
print msg print msg
if do_time:
print 'total time: %g' % (t1-t0)
sys.exit(1) sys.exit(1)
t1 = time()
if do_time:
print 'total time: %g' % (t1-t0)
if __name__ == '__main__': if __name__ == '__main__':