# HG changeset patch # User Jeff Hammel # Date 1308272369 25200 # Node ID 20dde2687cfbf41d8e7f38486961463a908da397 # Parent 750dc780d3d822270928e446b25e13405f04973a stub doctests diff -r 750dc780d3d8 -r 20dde2687cfb tests/doctest.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/doctest.txt Thu Jun 16 17:59:29 2011 -0700 @@ -0,0 +1,23 @@ +Test urlmatch +============= + +The obligatory imports:: + + >>> from urlmatcher import UrlMatcher + +Test matching:: + + >>> matcher = UrlMatcher('http://www.example.com/foo/bar/fleem') + >>> matcher.add('http://www.example.com/foo/blah') + >>> matcher.add('https://www.example.com/foo/') + >>> matcher.add('https://www.example.net/foo/') + >>> sorted(matcher.match('example.com/foo/bar')) + ['http://www.example.com/foo/bar/fleem', ] + >>> sorted(matcher.match('http://example.com/foo')) + >>> sorted(matcher.match('example.com')) + >>> sorted(matcher.match('example')) + + +Test url diffs:: + + >>> matcher = urlmatcher() diff -r 750dc780d3d8 -r 20dde2687cfb tests/test.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test.py Thu Jun 16 17:59:29 2011 -0700 @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +""" +doctest runner +""" + +import doctest +import os +import sys +from optparse import OptionParser + + +def run_tests(raise_on_error=False, report_first=False): + + # add results here + results = {} + + # doctest arguments + directory = os.path.dirname(os.path.abspath(__file__)) + extraglobs = {'here': directory} + doctest_args = dict(extraglobs=extraglobs, raise_on_error=raise_on_error) + if report_first: + doctest_args['optionflags'] = doctest.REPORT_ONLY_FIRST_FAILURE + + # gather tests + tests = [ test for test in os.listdir(directory) + if test.endswith('.txt') ] + + # run the tests + for test in tests: + try: + results[test] = doctest.testfile(test, **doctest_args) + except doctest.DocTestFailure, failure: + raise + except doctest.UnexpectedException, failure: + raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2] + + return results + +def main(args=sys.argv[1:]): + + # parse command line args + parser = OptionParser(description=__doc__) + parser.add_option('--raise', dest='raise_on_error', + default=False, action='store_true', + help="raise on first error") + parser.add_option('--report-first', dest='report_first', + default=False, action='store_true', + help="report the first error only (all tests will still run)") + options, args = parser.parse_args(args) + + # run the tests + results = run_tests(**options.__dict__) + if sum([i.failed for i in results.values()]): + sys.exit(1) # error + + +if __name__ == '__main__': + main()