Update: makefiles, sphinx docs, tests
[cookiecutter.git] / project_template / tests / run_all.py
1 #! /usr/bin/env python
2
3
4 import os
5 import sys
6 import subprocess
7
8
9 def isexecutable(filename):
10     infile = open(filename, 'r')
11     magic = infile.read(2)
12     infile.close()
13     return magic == "#!"
14
15
16 def collect_tests():
17     tests = []
18     for dirpath, dirs, files in os.walk("tests"):
19         tests.extend(
20             [os.path.join(dirpath, filename) for filename in files
21              if filename.startswith("test") and filename.endswith(".py")
22              ])
23     return [test[:-3].replace(os.sep, '.') for test in tests
24             if isexecutable(test)]
25
26
27 def main():
28     os.chdir(os.path.join(os.path.dirname(sys.argv[0]), os.pardir))
29     tests = collect_tests()
30
31     os.environ["PYTHONPATH"] = os.curdir
32
33     for test in sorted(tests):
34         print test
35         subprocess.call((sys.executable, '-m', test))
36
37 if __name__ == '__main__':
38     main()