PageRenderTime 264ms CodeModel.GetById 150ms app.highlight 7ms RepoModel.GetById 104ms app.codeStats 0ms

/Tools/compiler/regrtest.py

http://unladen-swallow.googlecode.com/
Python | 78 lines | 60 code | 9 blank | 9 comment | 6 complexity | d26be0176aaafbc1c9f8e56dcb37412d MD5 | raw file
 1"""Run the Python regression test using the compiler
 2
 3This test runs the standard Python test suite using bytecode generated
 4by this compiler instead of by the builtin compiler.
 5
 6The regression test is run with the interpreter in verbose mode so
 7that import problems can be observed easily.
 8"""
 9
10from compiler import compileFile
11
12import os
13import sys
14import test
15import tempfile
16
17def copy_test_suite():
18    dest = tempfile.mkdtemp()
19    os.system("cp -r %s/* %s" % (test.__path__[0], dest))
20    print "Creating copy of test suite in", dest
21    return dest
22
23def copy_library():
24    dest = tempfile.mkdtemp()
25    libdir = os.path.split(test.__path__[0])[0]
26    print "Found standard library in", libdir
27    print "Creating copy of standard library in", dest
28    os.system("cp -r %s/* %s" % (libdir, dest))
29    return dest
30
31def compile_files(dir):
32    print "Compiling", dir, "\n\t",
33    line_len = 10
34    for file in os.listdir(dir):
35        base, ext = os.path.splitext(file)
36        if ext == '.py':
37            source = os.path.join(dir, file)
38            line_len = line_len + len(file) + 1
39            if line_len > 75:
40                print "\n\t",
41                line_len = len(source) + 9
42            print file,
43            try:
44                compileFile(source)
45            except SyntaxError, err:
46                print err
47                continue
48            # make sure the .pyc file is not over-written
49            os.chmod(source + "c", 444)
50        elif file == 'CVS':
51            pass
52        else:
53            path = os.path.join(dir, file)
54            if os.path.isdir(path):
55                print
56                print
57                compile_files(path)
58                print "\t",
59                line_len = 10
60    print
61
62def run_regrtest(lib_dir):
63    test_dir = os.path.join(lib_dir, "test")
64    os.chdir(test_dir)
65    os.system("PYTHONPATH=%s %s -v regrtest.py" % (lib_dir, sys.executable))
66
67def cleanup(dir):
68    os.system("rm -rf %s" % dir)
69
70def main():
71    lib_dir = copy_library()
72    compile_files(lib_dir)
73    run_regrtest(lib_dir)
74    raw_input("Cleanup?")
75    cleanup(lib_dir)
76
77if __name__ == "__main__":
78    main()