Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 116 lines (93 sloc) 3.44 KB
#!/usr/bin/env python2
# emacs-mode: -*-python-*-
test_pythonlib -- decompyle ans verify Python libraries
test_pythonlib --all # decompyle all tests (suite + libs)
test_pythonlib --all --verify # decomyple all tests and verify results
test_pythonlib --test # decompyle only the testsuite
test_pythonlib --2.2 --verify # decompyle and verify python lib 2.2
Adding own test-trees:
Step 1) Edit this file and add a new entry to 'test_options', eg.
test_options['mylib'] = ('/usr/lib/mylib', PYOC, 'mylib')
Step 2: Run the test:
test_pythonlib --mylib # decompyle 'mylib'
test_pythonlib --mylib --verify # decomyple verify 'mylib'
import decompyle
import os, time, shutil
from fnmatch import fnmatch
#----- configure this for your needs
target_base = '/tmp/py-dis/'
lib_prefix = '/usr/lib'
PYC = ('*.pyc', )
PYO = ('*.pyo', )
PYOC = ('*.pyc', '*.pyo')
test_options = {
# name: (src_basedir, pattern, output_base_suffix)
'test': ('./test', PYOC, 'test'),
'1.5': (os.path.join(lib_prefix, 'python1.5'), PYC, 'python-lib1.5'),
'1.6': (os.path.join(lib_prefix, 'python1.6'), PYC, 'python-lib1.6'),
'2.0': (os.path.join(lib_prefix, 'python2.0'), PYC, 'python-lib2.0'),
'2.1': (os.path.join(lib_prefix, 'python2.1'), PYC, 'python-lib2.1'),
'2.2': (os.path.join(lib_prefix, 'python2.2'), PYC, 'python-lib2.2'),
def do_tests(src_dir, patterns, target_dir, start_with=None, do_verify=0):
def visitor(files, dirname, names):
[os.path.normpath(os.path.join(dirname, n))
for n in names
for pat in patterns
if fnmatch(n, pat)])
files = []
cwd = os.getcwd()
os.path.walk(os.curdir, visitor, files)
if start_with:
start_with = files.index(start_with)
files = files[start_with:]
print '>>> starting with file', files[0]
except ValueError:
print time.ctime()
decompyle.main(src_dir, target_dir, files, do_verify=do_verify)
print time.ctime()
if __name__ == '__main__':
import getopt, sys
do_verify = 0
test_dirs = []
start_with = None
test_options_keys = test_options.keys(); test_options_keys.sort()
opts, args = getopt.getopt(sys.argv[1:], '',
['start-with=', 'verify', 'all', ] \
+ test_options_keys )
for opt, val in opts:
if opt == '--verify':
do_verify = 1
elif opt == '--start-with':
start_with = val
elif opt[2:] in test_options_keys:
elif opt == '--all':
for val in test_options_keys:
for src_dir, pattern, target_dir in test_dirs:
if os.path.exists(src_dir):
target_dir = os.path.join(target_base, target_dir)
if os.path.exists(target_dir):
shutil.rmtree(target_dir, ignore_errors=1)
do_tests(src_dir, pattern, target_dir, start_with, do_verify)
print '### skipping', src_dir
# python 1.5:
# test/re_tests memory error
# test/test_b1 memory error
# Verification notes:
# - xdrlib fails verification due the same lambda used twice
# (verification is successfull when using original .pyo as
# input)