You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Go over makefiles to make "make check" work. walker, deparser: use zip_longest
This commit is contained in:
32
Makefile
32
Makefile
@@ -11,36 +11,26 @@ RM ?= rm
|
|||||||
LINT = flake8
|
LINT = flake8
|
||||||
|
|
||||||
#EXTRA_DIST=ipython/ipy_trepan.py trepan
|
#EXTRA_DIST=ipython/ipy_trepan.py trepan
|
||||||
PHONY=check clean pytest dist distclean lint flake8 test test-unit test-functional rmChangeLog clean_pyc nosetests
|
PHONY=all check clean pytest check-long dist distclean lint flake8 test rmChangeLog clean_pyc
|
||||||
|
|
||||||
|
TEST_TYPES=check-long check-short check-2.7 check-3.4
|
||||||
|
|
||||||
#: Default target - same as "check"
|
#: Default target - same as "check"
|
||||||
all: check
|
all: check
|
||||||
|
|
||||||
#: Same as "check"
|
all test check check_long:
|
||||||
test check: pytest check-long
|
@$(PYTHON) -V && PYTHON_VERSION=`$(PYTHON) -V 2>&1 | cut -d ' ' -f 2 | cut -d'.' -f1,2`; \
|
||||||
|
$(MAKE) check-$$PYTHON_VERSION
|
||||||
|
|
||||||
#: Run tests
|
#: Run working tests from Python 2.7
|
||||||
check-long: pytest
|
check-2.7: pytest
|
||||||
$(MAKE) -C test check-2.7
|
|
||||||
|
|
||||||
#: Run quick tests
|
|
||||||
check-short: pytest
|
|
||||||
$(MAKE) -C test check-short-2.7
|
|
||||||
|
|
||||||
#: Run tests if Python 2.7
|
|
||||||
check-2.7: pytest
|
|
||||||
$(MAKE) -C test $@
|
$(MAKE) -C test $@
|
||||||
|
|
||||||
#: Run tests if Python 3.4
|
#: Run working tests from Python 3.4
|
||||||
check-3.4: pytest
|
check-3.4:
|
||||||
$(MAKE) -C test $@
|
$(MAKE) -C test $@
|
||||||
|
|
||||||
|
#: Run py.test tests
|
||||||
#: check that disassembly exactly matches Python lib's dis
|
|
||||||
check-disasm:
|
|
||||||
$(MAKE) -C test check-disasm
|
|
||||||
|
|
||||||
#: Run tests
|
|
||||||
pytest:
|
pytest:
|
||||||
$(MAKE) -C pytest check
|
$(MAKE) -C pytest check
|
||||||
|
|
||||||
|
12
README.rst
12
README.rst
@@ -49,13 +49,13 @@ Testing
|
|||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
make check-2.7 # if running on Python 2.7
|
make check
|
||||||
make check-3.4 # if running on Pyton 3.4
|
|
||||||
|
|
||||||
Testing right now is largely via utility `test/test_pythonlib.py`. A
|
A GNU makefile has been added to smooth over setting running the right
|
||||||
GNU makefile has been added to smooth over setting running the right
|
command, and running tests from fastest to slowest.
|
||||||
command. If you have remake_ installed, you can see the list of all
|
|
||||||
tasks including tests via `remake --tasks`
|
If you have remake_ installed, you can see the list of all tasks
|
||||||
|
including tests via `remake --tasks`
|
||||||
|
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
|
@@ -13,17 +13,15 @@ COMPILE ?=
|
|||||||
check-2.7: check-short-2.7 check-bytecode check-2.7-ok
|
check-2.7: check-short-2.7 check-bytecode check-2.7-ok
|
||||||
|
|
||||||
#: Run working tests from Python 3.4
|
#: Run working tests from Python 3.4
|
||||||
check-3.4: check-short-2.7 check-bytecode check-native-short
|
check-3.4: check-short-3.4 check-short-2.7 check-bytecode
|
||||||
|
|
||||||
check:
|
check: check-short
|
||||||
@echo "For now, use check-2.7 or check-3.4" && false
|
@$(PYTHON) -V && PYTHON_VERSION=`$(PYTHON) -V 2>&1 | cut -d ' ' -f 2 | cut -d'.' -f1,2`; \
|
||||||
|
$(MAKE) check-$$PYTHON_VERSION
|
||||||
|
|
||||||
## FIXME: there is a bug in our code that I don't
|
check-short:
|
||||||
## find in uncompyle2 that causes this to fail.
|
@$(PYTHON) -V && PYTHON_VERSION=`$(PYTHON) -V 2>&1 | cut -d ' ' -f 2 | cut -d'.' -f1,2`; \
|
||||||
## parsing.
|
$(MAKE) check-short-$$PYTHON_VERSION
|
||||||
## the failing program works if run by itself.
|
|
||||||
## This leads me to believe the problem is an
|
|
||||||
## initialization bug?
|
|
||||||
|
|
||||||
#: Check deparsing only, but from a different Python version
|
#: Check deparsing only, but from a different Python version
|
||||||
check-disasm:
|
check-disasm:
|
||||||
|
@@ -39,10 +39,12 @@ def inst_fmt(inst):
|
|||||||
def compare_ok(version, co):
|
def compare_ok(version, co):
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
if version in (2.6, 2.7):
|
if version in (2.6, 2.7):
|
||||||
dis.disco(co)
|
print("Doesn't work on %d\n yet" % version)
|
||||||
|
# dis.disco(co)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
bytecode = dis.Bytecode(co)
|
bytecode = dis.Bytecode(co)
|
||||||
|
|
||||||
disco(version, co, out)
|
disco(version, co, out)
|
||||||
got_lines = out.getvalue().split("\n")[2:]
|
got_lines = out.getvalue().split("\n")[2:]
|
||||||
i = 0
|
i = 0
|
||||||
@@ -82,8 +84,9 @@ files=[
|
|||||||
|
|
||||||
for base in files:
|
for base in files:
|
||||||
filename = "bytecode_%s/%s.pyc" % (PYTHON_VERSION_STR, base)
|
filename = "bytecode_%s/%s.pyc" % (PYTHON_VERSION_STR, base)
|
||||||
version, co = uncompyle6.load_module(filename)
|
version, magic_int, co = uncompyle6.load_module(filename)
|
||||||
ok = True
|
ok = True
|
||||||
|
|
||||||
if type(co) == list:
|
if type(co) == list:
|
||||||
for con in co:
|
for con in co:
|
||||||
ok = compare_ok(version, con)
|
ok = compare_ok(version, con)
|
||||||
|
@@ -61,8 +61,10 @@ from uncompyle6 import parser
|
|||||||
from uncompyle6.scanner import Token, Code, get_scanner
|
from uncompyle6.scanner import Token, Code, get_scanner
|
||||||
|
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
|
from itertools import zip_longest
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
else:
|
else:
|
||||||
|
from itertools import izip_longest as zip_longest
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
# FIXME: remove uncompyle dups
|
# FIXME: remove uncompyle dups
|
||||||
@@ -1088,14 +1090,14 @@ class Traverser(walker.Walker, object):
|
|||||||
|
|
||||||
# build parameters
|
# build parameters
|
||||||
|
|
||||||
# This would be a nicer piece of code, but I can't get this to work
|
params = [build_param(ast, name, default) for
|
||||||
# now, have to find a usable lambda constuct hG/2000-09-05
|
name, default in zip_longest(paramnames, defparams, fillvalue=None)]
|
||||||
# params = map(lambda name, default: build_param(ast, name, default),
|
# params = [ build_param(ast, name, default) for
|
||||||
# paramnames, defparams)
|
# name, default in zip(paramnames, defparams) ]
|
||||||
params = []
|
# params = []
|
||||||
for i, name in enumerate(paramnames):
|
# for i, name in enumerate(paramnames):
|
||||||
default = defparams[i] if len(defparams) > i else None
|
# default = defparams[i] if len(defparams) > i else None
|
||||||
params.append( build_param(ast, name, default) )
|
# params.append( build_param(ast, name, default) )
|
||||||
|
|
||||||
params.reverse() # back to correct order
|
params.reverse() # back to correct order
|
||||||
|
|
||||||
|
@@ -65,8 +65,6 @@ def disco(version, co, out=None):
|
|||||||
scanner = get_scanner(version)
|
scanner = get_scanner(version)
|
||||||
tokens, customize = scanner.disassemble(co)
|
tokens, customize = scanner.disassemble(co)
|
||||||
|
|
||||||
for t in tokens:
|
|
||||||
print(t, file=real_out)
|
|
||||||
print(file=out)
|
print(file=out)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -42,6 +42,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import inspect, sys, re
|
import inspect, sys, re
|
||||||
|
|
||||||
|
|
||||||
from uncompyle6 import PYTHON3
|
from uncompyle6 import PYTHON3
|
||||||
from uncompyle6.parser import get_python_parser
|
from uncompyle6.parser import get_python_parser
|
||||||
from uncompyle6.parsers.astnode import AST
|
from uncompyle6.parsers.astnode import AST
|
||||||
@@ -50,10 +51,12 @@ import uncompyle6.parser as python_parser
|
|||||||
from uncompyle6.scanner import Token, Code, get_scanner
|
from uncompyle6.scanner import Token, Code, get_scanner
|
||||||
|
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
|
from itertools import zip_longest
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
minint = -sys.maxsize-1
|
minint = -sys.maxsize-1
|
||||||
maxint = sys.maxsize
|
maxint = sys.maxsize
|
||||||
else:
|
else:
|
||||||
|
from itertools import izip_longest as zip_longest
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
minint = -sys.maxint-1
|
minint = -sys.maxint-1
|
||||||
maxint = sys.maxint
|
maxint = sys.maxint
|
||||||
@@ -1319,14 +1322,14 @@ class Walker(GenericASTTraversal, object):
|
|||||||
|
|
||||||
# build parameters
|
# build parameters
|
||||||
|
|
||||||
# This would be a nicer piece of code, but I can't get this to work
|
params = [build_param(ast, name, default) for
|
||||||
# now, have to find a usable lambda constuct hG/2000-09-05
|
name, default in zip_longest(paramnames, defparams, fillvalue=None)]
|
||||||
# params = map(lambda name, default: build_param(ast, name, default),
|
# params = [ build_param(ast, name, default) for
|
||||||
# paramnames, defparams)
|
# name, default in zip(paramnames, defparams) ]
|
||||||
params = []
|
# params = []
|
||||||
for i, name in enumerate(paramnames):
|
# for i, name in enumerate(paramnames):
|
||||||
default = defparams[i] if len(defparams) > i else None
|
# default = defparams[i] if len(defparams) > i else None
|
||||||
params.append( build_param(ast, name, default) )
|
# params.append( build_param(ast, name, default) )
|
||||||
|
|
||||||
params.reverse() # back to correct order
|
params.reverse() # back to correct order
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user