2008-08-10 17:43:24 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
"""Run the doctest on a text file
|
|
|
|
|
|
|
|
Usage: doctext.py [file]
|
|
|
|
|
|
|
|
[file] defaults to ``test.txt``
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import doctest
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = sys.argv[1:]
|
|
|
|
filename = None
|
|
|
|
verbose = False
|
|
|
|
|
|
|
|
for word in args:
|
|
|
|
if word in ("-v", "-verbose"):
|
|
|
|
verbose = True
|
|
|
|
elif word in ("-h", "-help", "/?", "/help", "--help"):
|
|
|
|
print __doc__
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
if filename:
|
|
|
|
print "Filename '%s' already specified"%filename
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
filename = word
|
|
|
|
|
|
|
|
if not filename:
|
|
|
|
filename = "test.txt"
|
|
|
|
|
2008-08-28 20:33:47 +00:00
|
|
|
print
|
|
|
|
print 'Ignore any output lines starting ### or !!!. These are written by the'
|
|
|
|
print 'underlying C library, and are not "seen" (or hidden) by doctest.'
|
|
|
|
print
|
|
|
|
|
2008-08-19 14:49:00 +00:00
|
|
|
(failures,tests) = doctest.testfile(filename,verbose=verbose)
|
2008-08-10 17:43:24 +00:00
|
|
|
|
|
|
|
testword = "test"
|
|
|
|
if tests != 1: testword = "tests"
|
|
|
|
failword = "failure"
|
|
|
|
if failures != 1: failword = "failures"
|
2008-08-19 14:49:00 +00:00
|
|
|
print
|
2008-08-10 17:43:24 +00:00
|
|
|
print "File %s: %d %s, %d %s"%(filename,tests,testword,failures,failword)
|
2008-08-28 20:33:47 +00:00
|
|
|
print
|
|
|
|
if failures == 0:
|
|
|
|
print 'The little light is GREEN'
|
|
|
|
else:
|
|
|
|
print 'The little light is RED'
|
2008-08-10 17:43:24 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|