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
|
#!/usr/bin/python
import inspect
import os
import sys
# This makes sure that users don't have to set up their environment specially
# in order to run these programs from bin/.
if os.path.abspath(sys.argv[0]).find(os.sep+'Testdoc') != -1:
sys.path.insert(0, os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir)))
if getattr(os, "getuid", 0) != 0:
sys.path.insert(0, os.curdir)
from testdoc import documenter, finder, formatter, reflect
def usage():
return "Usage: testdoc <fully-qualified module name>"
def string_to_module(argument):
if os.path.exists(argument):
return reflect.filenameToModule(argument)
obj = reflect.namedAny(argument)
if not inspect.ismodule(obj):
raise ValueError('%r is not a Python module' % (argument,))
return obj
def make_options():
from optparse import OptionParser
parser = OptionParser(
usage="usage: %prog [options] MODULE_NAME [MODULE_NAME ...]")
format_choices = sorted(formats.keys())
parser.add_option("-f", "--format", dest="format",
choices=format_choices, metavar="FORMAT",
help="Format to emit. One of: " + ', '.join(format_choices),
default="moin")
return parser
formats = {
'moin': formatter.WikiFormatter,
'rest': formatter.ReSTFormatter,
'trial': formatter.TrialLikeTreeFormatter,
}
def main():
parser = make_options()
(options, args) = parser.parse_args()
format = formats[options.format](sys.stdout)
doc = documenter.Documenter(format)
for arg in args:
module = string_to_module(arg)
finder.find_tests(doc, module)
if __name__ == '__main__':
main()
|