cortesi / pry

A unit testing framework with integrated coverage

This URL has Read+Write access

pry / pry
100755 115 lines (102 sloc) 3.766 kb
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python
import sys
import libpry
 
 
def main():
    from optparse import OptionParser, OptionGroup
    parser = OptionParser(
                usage = "%prog [options] [testfilter]",
                version="%prog 0.1",
            )
    parser.add_option("-l", "--list",
                      action="store_true", dest="list",
                      help="List all tests.")
    parser.add_option("-r", "--recurse",
                      action="store_true", dest="recurse", default=False,
                      help="Recurse through child directories.")
    parser.add_option("-s", "--stats",
                      action="store_true", dest="stats",
                      help="Print coverage summary.")
    parser.add_option("-n", "--benchmark",
                      action="store", dest="benchmark", type="int", default=1,
                      help="Run each test N times.")
    parser.add_option("-q", "--quiet",
                      action="store_true", dest="quiet",
                      help="Quiet.")
    parser.add_option("-v", "--verbose",
                      action="count", dest="verbose", default=1,
                      help="Increase verbosity. Can be passed multiple times.")
    parser.add_option(
                        "--debug-dump",
                        action="store_true", dest="debug",
                        help="For debugging only. Like -l,"
                           " but dump the full tree structure."
                    )
 
    group = OptionGroup(
                        parser,
                        "Profiling",
                        "Generating run profiles for unit tests."
                    )
    group.add_option(
                        "-p", "--profile",
                        action="store_true", dest="profile",
                        help="Do a profiling run. Usually used"
                        " in conjunction with -n to specify multiple runs."
                    )
    group.add_option(
                        "", "--profile-sort",
                        action="store", dest="profile_sort",
                        default="time", type="choice",
                        choices=[
                            "calls",
                            "cumulative",
                            "file",
                            "module",
                            "pcalls",
                            "line",
                            "name",
                            "nfl",
                            "stdname",
                            "time"
                        ],
                        help="Profile result sorting key. "
                        "See Python documentation for pstats module."
                    )
    parser.add_option_group(group)
 
    (options, args) = parser.parse_args()
 
    if not args:
        path, pattern = ".", None
    elif len(args) == 1:
        path, pattern = libpry.utils._splitSpec(args[0])
    else:
        parser.error("Please pass only one argument.")
 
    if options.stats:
        coverage = True
    else:
        coverage = False
 
    if options.quiet:
        verbose = 0
    else:
        verbose = options.verbose
 
    if options.profile:
        p = options.profile_sort
    else:
        p = None
    r = libpry.test._RootNode(coverage, p)
    r.addPath(path or ".", options.recurse)
    if pattern:
        r.mark(pattern)
    r.prune()
 
    output = libpry.test._Output(r, verbose)
 
    if options.list:
        r.printStructure()
        print "Total: %s"%len(r.tests())
        sys.exit()
    elif options.debug:
        r.dump()
        print "Total: %s"%len(r.tests())
        sys.exit()
    else:
        r._run(output, options.benchmark)
        output.final(r)
    
 
if __name__ == "__main__":
    main()