symbian-qemu-0.9.1-12/python-2.6.1/Tools/compiler/regrtest.py
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 """Run the Python regression test using the compiler
       
     2 
       
     3 This test runs the standard Python test suite using bytecode generated
       
     4 by this compiler instead of by the builtin compiler.
       
     5 
       
     6 The regression test is run with the interpreter in verbose mode so
       
     7 that import problems can be observed easily.
       
     8 """
       
     9 
       
    10 from compiler import compileFile
       
    11 
       
    12 import os
       
    13 import sys
       
    14 import test
       
    15 import tempfile
       
    16 
       
    17 def 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 
       
    23 def 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 
       
    31 def 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 
       
    62 def 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 
       
    67 def cleanup(dir):
       
    68     os.system("rm -rf %s" % dir)
       
    69 
       
    70 def 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 
       
    77 if __name__ == "__main__":
       
    78     main()