GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a ruby-to-pyc compiler
Clone URL: git://github.com/why/unholy.git
commit  12d52c4ce7154d3cd8300be129d15ed7e57e8b1e
tree    e914a334f60827097074f2570f76e66d0588f0b1
parent  3fa5d7dd9a996c915b4c7415283b493de0790ede
unholy / decompyle / test / compile_tests
100644 77 lines (57 sloc) 2.289 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
"""
compile_tests -- compile test patterns for the decompyle test suite
 
This source is part of the decompyle test suite.
 
decompyle is a Python byte-code decompiler
See http://www.goebel-consult.de/decompyle/ for download and
for further information
"""
 
import py_compile, os, sys, getopt
 
work_dir = os.path.dirname(sys.argv[0])
src_dir = work_dir
 
opts, args = getopt.getopt(sys.argv[1:], 's:w:')
 
for opt, val in opts:
    if opt == '-s':
        src_dir = val
    if opt == '-w':
        work_dir = val
    else:
        raise "Unknown Option '%s'" % opt
if args:
    raise 'This tool does not want any arguments'
 
print "Using files in dir %s" % src_dir
print "Compiling into dir %s" % work_dir
 
tests = {}
 
tests['1.5'] = ["class", "del", "docstring", 'empty', "exec",
                "exceptions", "expressions", "functions", "global",
                "globals", "import", "integers", "lambda", "loops",
                "misc", "nested_elif", "prettyprint", "print",
                'single_stmt', "slices", "tuple_params", 'tuples']
 
tests['1.6'] = ["applyEquiv", ] + tests['1.5']
 
tests['2.0'] = ["augmentedAssign", "extendedImport", "extendedPrint",
                "import_as", "listComprehensions", 'print_to'] + \
                tests['1.6'] # [ "--extendedarg", ]
 
tests['2.1'] = ['loops2', 'nested_scopes'] + tests['2.0']
 
tests['2.2'] = ['divide_future', 'divide_no_future', 'iterators',
                'yield'] + tests['2.1']
 
total_tests = len(tests['2.2'])
#tests['2.2'].sort(); print tests['2.2']
 
extension = '.py' + (__debug__ and 'c' or 'o')
 
def compile(file, target_dir):
    sfile = os.path.join(src_dir, 'test_%s.py' % file)
    cfile = os.path.join(target_dir, 'test_%s%s' % (file, extension) )
    py_compile.compile(sfile, cfile=cfile)
 
def compile_for_version(version):
    target_dir = os.path.join(work_dir, 'bytecode_' + version)
    if not os.path.exists(target_dir):
        os.mkdir(target_dir)
    for file in tests[version]:
        compile(file, target_dir)
    
try:
    version = '%i.%i' % sys.version_info[:2]
except AttributeError:
    version = sys.version[:3]
 
print 'Compiling test files for Python', version,
print '(%i/%i files)' % (len(tests[version]), total_tests)
compile_for_version(version)
print 'Done.'