8 parser
= optparse
.OptionParser()
9 parser
.add_option("--limit", dest
="limit", type=int,
10 help="Limit to this number of output entries.", default
=0)
11 (opts
, args
) = parser
.parse_args()
13 third_party_path
= os
.path
.join(os
.path
.dirname(sys
.argv
[0]), "..", "lib")
14 subunit_prefix
= "PYTHONPATH="+ ":".join([
15 os
.path
.join(third_party_path
, "testtools"),
16 os
.path
.join(third_party_path
, "mimeparse"),
17 os
.path
.join(third_party_path
, "extras"),
18 os
.path
.join(third_party_path
, "subunit/python")]) + (
19 " " + os
.path
.join(third_party_path
, "subunit"))
23 cmd
= (os
.path
.join(subunit_prefix
, "filters/subunit-1to2") + " | " +
24 os
.path
.join(subunit_prefix
, "filters/subunit-ls") + " --times --no-passthrough")
26 p
= subprocess
.Popen(cmd
, stdout
=subprocess
.PIPE
, stdin
=sys
.stdin
, shell
=True)
29 (name
, duration
) = l
.rsplit(" ", 1)
30 durations
[name
] = float(duration
)
33 print "Top %d tests by run time:" % opts
.limit
35 for i
, (name
, length
) in enumerate(sorted(
36 durations
.items(), cmp=lambda (k1
,v1
), (k2
, v2
): cmp(v1
, v2
), reverse
=True)):
37 if opts
.limit
and i
== opts
.limit
:
39 print "%d: %s -> %ds" % (i
+1, name
, length
)