5 # Count statistics about SCons test and source files. This must be run
6 # against a fully-populated tree (for example, one that's been freshly
9 # A test file is anything under the src/ directory that begins with
10 # 'test_' or ends in 'Tests.py', or anything under the test/ directory
11 # that ends in '.py'. Note that runtest.py script does *not*, by default,
12 # consider the files that begin with 'test_' to be tests, because they're
13 # tests of SCons packaging and installation, not functional tests of
16 # A source file is anything under the src/engine/ or src/script/
17 # directories that ends in '.py' but does NOT begin with 'test_'
18 # or end in 'Tests.py'. (We should probably ignore the stuff in
19 # src/engine/SCons/Optik, since it doesn't originate with SCons, but
22 # We report the number of tests and sources, the total number of lines
23 # in each category, the number of non-blank lines, and the number of
24 # non-comment lines. The last figure (non-comment) lines is the most
25 # interesting one for most purposes.
28 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
37 return x[:5] == 'test_' or x[-8:] == 'Tests.py'
39 return x[-3:] == '.py'
41 def t(arg, dirname, names):
42 names = filter(is_test, names)
43 arg.extend(map(lambda n, d=dirname: os.path.join(d, n), names))
44 os.path.walk('src', t, tests)
46 def p(arg, dirname, names):
47 names = filter(is_python, names)
48 arg.extend(map(lambda n, d=dirname: os.path.join(d, n), names))
49 os.path.walk('test', p, tests)
51 def s(arg, dirname, names):
52 names = filter(lambda n: is_python(n) and not is_test(n), names)
53 arg.extend(map(lambda n, d=dirname: os.path.join(d, n), names))
54 os.path.walk('src/engine', s, sources)
55 os.path.walk('src/script', s, sources)
60 lines.extend(open(file).readlines())
63 tlines = map(string.lstrip, gather(tests))
64 slines = map(string.lstrip, gather(sources))
66 nbtl = filter(lambda x: x != '', tlines)
67 nbsl = filter(lambda x: x != '', slines)
69 nctl = filter(lambda x: x[0] != '#', nbtl)
70 ncsl = filter(lambda x: x[0] != '#', nbsl)
72 def ratio(over, under):
73 return "%.2f" % (float(len(over)) / float(len(under)))
75 rfiles = ratio(tests, sources)
76 rlines = ratio(tlines, slines)
77 rnonblank = ratio(nbtl, nbsl)
78 rnoncomment = ratio(nctl, ncsl)
80 fmt = "%-8s %12s %12s %12s %12s"
82 print fmt % ('', 'files', 'lines', 'non-blank', 'non-comment')
83 print fmt % ('tests:', len(tests), len(tlines), len(nbtl), len(nctl))
84 print fmt % ('sources:', len(sources), len(slines), len(nbsl), len(ncsl))
85 print fmt % ('ratio:', rfiles, rlines, rnonblank, rnoncomment)