diff options
author | Guido van Rossum <guido@python.org> | 1998-12-22 14:23:50 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-12-22 14:23:50 (GMT) |
commit | af5add46296797010f34b42b09344b2a10ac2fbb (patch) | |
tree | 06782b653b8b672622a71768ebd3a62691d14eea /Lib | |
parent | 7ea1d972d1519ac8cb8051ff0e99d02e9ef71251 (diff) | |
download | cpython-af5add46296797010f34b42b09344b2a10ac2fbb.zip cpython-af5add46296797010f34b42b09344b2a10ac2fbb.tar.gz cpython-af5add46296797010f34b42b09344b2a10ac2fbb.tar.bz2 |
New test function by Sjoerd, adding -t option.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/xmllib.py | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/Lib/xmllib.py b/Lib/xmllib.py index 235f16a..e31d040 100644 --- a/Lib/xmllib.py +++ b/Lib/xmllib.py @@ -795,16 +795,20 @@ class TestXMLParser(XMLParser): self.flush() def test(args = None): - import sys + import sys, getopt + from time import time if not args: args = sys.argv[1:] - if args and args[0] == '-s': - args = args[1:] - klass = XMLParser - else: - klass = TestXMLParser + opts, args = getopt.getopt(args, 'st') + klass = TestXMLParser + do_time = 0 + for o, a in opts: + if o == '-s': + klass = XMLParser + elif o == '-t': + do_time = 1 if args: file = args[0] @@ -825,13 +829,24 @@ def test(args = None): f.close() x = klass() + t0 = time() try: - for c in data: - x.feed(c) - x.close() + if do_time: + x.feed(data) + x.close() + else: + for c in data: + x.feed(c) + x.close() except RuntimeError, msg: + t1 = time() print msg + if do_time: + print 'total time: %g' % (t1-t0) sys.exit(1) + t1 = time() + if do_time: + print 'total time: %g' % (t1-t0) if __name__ == '__main__': |