1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("UTF-8")
import doctest, os, sys, glob
import click
"""
This will doctest all files ending with .rst in this directory.
"""
@click.command()
@click.option('-f', '--file_paths', help="specific rst files to test")
@click.option('-j', '--just', help='comma separated list of names to be matched to files to be tested')
@click.option('-x', '--exclude', help='comma separated list of names to be matched to files to be excluded')
@click.option('-v', '--verbose', is_flag=True, help='verbose output')
def main(file_paths, just, exclude, verbose):
"""runs doctests for the indicated files"""
if not file_paths:
# find all files that end with rest
file_paths = [fname for fname in os.listdir(os.getcwd()) if fname.endswith('.rst')]
elif "*" in file_paths:
file_paths = glob.glob(file_paths)
if verbose:
print file_paths
if just:
just = just.split(',')
new = []
for fn in file_paths:
for sub_word in just:
if sub_word in fn:
new.append(fn)
file_paths = new
elif exclude:
exclude = exclude.split(',')
new = []
for fn in file_paths:
keep = True
for sub_word in exclude:
if sub_word in fn:
keep = False
break
if keep:
new.append(fn)
file_paths = new
if verbose:
print "File paths, after filtering: %s" % str(file_paths)
for test in file_paths:
print
print "#" * 40
print test
doctest.testfile(test, optionflags=doctest.ELLIPSIS, verbose=True, encoding='utf-8')
if __name__ == "__main__":
main()
|