OILS / opy / tools / regrtest.py View on Github | oilshell.org

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