annotate tests/test.py @ 0:53cfd6e1ad0f

initial commit, from http://k0s.org/portfolio/ideas/textshaper.py , see also http://k0s.org/portfolio/ideas/cleanuptext.py So you have a block of text ... What do you want to do with it?!? == Desired Functionality == == Previous work == /corpus of past programs -> consolidate/ - onelineit - quoting - dequoting (including e.g. +/-, diff-ish shit) - removing timestamps - removing/adding irc quote tags Interface: - library code - (n)curses - javascript/REST Consider the pattern: * things that add and/or remove a thing * things that alter spacing == Reference == Previous k0s.ware (big and small): - http://k0s.org/hg/config/rev/5e0b4ec36013 Highly related (~> identity): http://k0s.org/portfolio/ideas/cleanuptext.py Ubuntu packages: - par (paragraph reformatter)
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 10 Aug 2013 15:47:30 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 doctest runner
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 """
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 import doctest
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 import os
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 import sys
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 from optparse import OptionParser
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 def run_tests(raise_on_error=False, report_first=False):
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 # add results here
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 results = {}
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 # doctest arguments
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 directory = os.path.dirname(os.path.abspath(__file__))
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 extraglobs = {'here': directory}
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 doctest_args = dict(extraglobs=extraglobs, raise_on_error=raise_on_error)
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 doctest_args['optionsflags'] = doctest.ELLIPSIS
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 if report_first:
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 doctest_args['optionflags'] |= doctest.REPORT_ONLY_FIRST_FAILURE
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 # gather tests
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 tests = [test for test in os.listdir(directory)
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 if test.endswith('.txt')]
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 # run the tests
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 for test in tests:
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 try:
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 results[test] = doctest.testfile(test, **doctest_args)
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 except doctest.DocTestFailure, failure:
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 raise
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 except doctest.UnexpectedException, failure:
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2]
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 return results
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 def main(args=sys.argv[1:]):
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 # parse command line args
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 parser = OptionParser(description=__doc__)
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 parser.add_option('--raise', dest='raise_on_error',
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 default=False, action='store_true',
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47 help="raise on first error")
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48 parser.add_option('--report-first', dest='report_first',
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49 default=False, action='store_true',
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50 help="report the first error only (all tests will still run)")
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51 options, args = parser.parse_args(args)
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53 # run the tests
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
54 results = run_tests(**options.__dict__)
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
55 if sum([i.failed for i in results.values()]):
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
56 sys.exit(1) # error
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
57
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
58
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59 if __name__ == '__main__':
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
60 main()
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61