limits: make direct @debug faster (minor)
[sympy.git] / bin / test_isolated
blob3632acc4b9d381bd598db5221f5da2d591adae64
1 #! /usr/bin/python
2 """
3 Generates a bash script, that executes py.test or nosetest on each file
4 individually.
6 Example:
8 $ bin/test_isolated
9 Generating py.test isolated testsuite...
10 Done. Run '/tmp/test_sympy.sh'.
12 Help:
14 $ bin/test_isolated -h
15 [...]
16 """
18 from os import chmod, getcwd
19 from glob import glob
20 from optparse import OptionParser
21 from stat import S_IREAD, S_IWRITE, S_IXUSR, S_IRGRP, S_IROTH, S_IXGRP, S_IXOTH
23 filemode = S_IREAD | S_IWRITE | S_IXUSR | S_IRGRP | S_IROTH | S_IXGRP | S_IXOTH
25 def get_paths(level=6):
26 """
27 Generates a set of paths for testfiles searching.
29 Example:
30 >>> get_paths(2)
31 ['sympy/test_*.py', 'sympy/*/test_*.py', 'sympy/*/*/test_*.py']
32 >>> get_paths(6)
33 ['sympy/test_*.py', 'sympy/*/test_*.py', 'sympy/*/*/test_*.py',
34 'sympy/*/*/*/test_*.py', 'sympy/*/*/*/*/test_*.py',
35 'sympy/*/*/*/*/*/test_*.py', 'sympy/*/*/*/*/*/*/test_*.py']
36 """
37 wildcards = ["/"]
38 for i in range(level):
39 wildcards.append(wildcards[-1]+"*/")
40 my_dir = getcwd()
41 p = [my_dir+"/sympy"+x+"test_*.py" for x in wildcards]
42 return p
44 def generate_test_script1(testlib="py.test"):
45 """Generates a bash script for doing the test.
47 "testlib" is the name of the executable, that is going to execute the test,
48 for example "py.test" or "nosetests".
49 """
50 g = []
51 for x in get_paths(10):
52 g.extend(glob(x))
53 f = open("/tmp/test_sympy.sh","w")
54 f.write("#! /bin/sh\n")
55 f.write("# Autogenerated script for a reliable test of SymPy.\n")
56 f.write("# Execute with 'sh test_sympy.sh' (in any directory).\n\n")
57 for x in g:
58 f.write(testlib+" " + x + "\n")
59 chmod(f.name, filemode)
61 def generate_test_script2(testlib="nosetests"):
62 """Generates a bash script for doing the test.
64 "testlib" is the name of the executable, that is going to execute the test,
65 for example "py.test" or "nosetests".
66 """
67 g = []
68 for x in get_paths(10):
69 g.extend(glob(x))
70 f = open("/tmp/test_sympy.sh","w")
71 f.write("#! /bin/sh\n")
72 f.write("# Autogenerated script for a reliable test of SymPy.\n")
73 f.write("# Execute with 'sh test_sympy.sh' (in any directory).\n\n")
74 for x in g:
75 f.write(testlib+" " + x + " && \\\n")
76 f.write("echo 'all tests passed, ok to commit'")
77 chmod(f.name, filemode)
79 def main():
80 parser = OptionParser()
81 parser.add_option("-p","--py.test", action="store_false", dest="nosetests",
82 help="Use py.test (default)")
83 parser.add_option("-n","--nosetests", action="store_true", dest="nosetests",
84 help="Use nosetests")
85 parser.add_option("-q","--quiet", action="store_false", dest="verbose")
86 parser.set_defaults(nosetests=False, verbose=True)
88 options, args = parser.parse_args()
89 if len(args) != 0:
90 parser.error("too many arguments")
91 if options.nosetests:
92 if options.verbose:
93 print "Generating nosetests isolated testsuite..."
94 generate_test_script2("nosetests")
95 else:
96 if options.verbose:
97 print "Generating py.test isolated testsuite..."
98 generate_test_script1("py.test")
99 if options.verbose:
100 print "Done. Run '/tmp/test_sympy.sh'."
102 if __name__ == "__main__":
103 main()