Go over makefiles to make "make check" work. walker, deparser: use zip_longest

This commit is contained in:
rocky
2015-12-20 12:07:49 -05:00
parent aa2fc0f5a5
commit 7880e0d7b1
8 changed files with 50 additions and 56 deletions

View File

@@ -11,36 +11,26 @@ RM ?= rm
LINT = flake8
#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"
all: check
#: Same as "check"
test check: pytest check-long
all test check check_long:
@$(PYTHON) -V && PYTHON_VERSION=`$(PYTHON) -V 2>&1 | cut -d ' ' -f 2 | cut -d'.' -f1,2`; \
$(MAKE) check-$$PYTHON_VERSION
#: Run tests
check-long: 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
#: Run working tests from Python 2.7
check-2.7: pytest
$(MAKE) -C test $@
#: Run tests if Python 3.4
check-3.4: pytest
#: Run working tests from Python 3.4
check-3.4:
$(MAKE) -C test $@
#: check that disassembly exactly matches Python lib's dis
check-disasm:
$(MAKE) -C test check-disasm
#: Run tests
#: Run py.test tests
pytest:
$(MAKE) -C pytest check

View File

@@ -49,13 +49,13 @@ Testing
::
make check-2.7 # if running on Python 2.7
make check-3.4 # if running on Pyton 3.4
make check
Testing right now is largely via utility `test/test_pythonlib.py`. A
GNU makefile has been added to smooth over setting running the right
command. If you have remake_ installed, you can see the list of all
tasks including tests via `remake --tasks`
A GNU makefile has been added to smooth over setting running the right
command, and running tests from fastest to slowest.
If you have remake_ installed, you can see the list of all tasks
including tests via `remake --tasks`
Usage

View File

@@ -13,17 +13,15 @@ COMPILE ?=
check-2.7: check-short-2.7 check-bytecode check-2.7-ok
#: 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:
@echo "For now, use check-2.7 or check-3.4" && false
check: check-short
@$(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
## find in uncompyle2 that causes this to fail.
## parsing.
## the failing program works if run by itself.
## This leads me to believe the problem is an
## initialization bug?
check-short:
@$(PYTHON) -V && PYTHON_VERSION=`$(PYTHON) -V 2>&1 | cut -d ' ' -f 2 | cut -d'.' -f1,2`; \
$(MAKE) check-short-$$PYTHON_VERSION
#: Check deparsing only, but from a different Python version
check-disasm:

View File

@@ -39,10 +39,12 @@ def inst_fmt(inst):
def compare_ok(version, co):
out = StringIO()
if version in (2.6, 2.7):
dis.disco(co)
print("Doesn't work on %d\n yet" % version)
# dis.disco(co)
return True
bytecode = dis.Bytecode(co)
disco(version, co, out)
got_lines = out.getvalue().split("\n")[2:]
i = 0
@@ -82,8 +84,9 @@ files=[
for base in files:
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
if type(co) == list:
for con in co:
ok = compare_ok(version, con)

View File

@@ -61,8 +61,10 @@ from uncompyle6 import parser
from uncompyle6.scanner import Token, Code, get_scanner
if PYTHON3:
from itertools import zip_longest
from io import StringIO
else:
from itertools import izip_longest as zip_longest
from StringIO import StringIO
# FIXME: remove uncompyle dups
@@ -1088,14 +1090,14 @@ class Traverser(walker.Walker, object):
# build parameters
# This would be a nicer piece of code, but I can't get this to work
# now, have to find a usable lambda constuct hG/2000-09-05
# params = map(lambda name, default: build_param(ast, name, default),
# paramnames, defparams)
params = []
for i, name in enumerate(paramnames):
default = defparams[i] if len(defparams) > i else None
params.append( build_param(ast, name, default) )
params = [build_param(ast, name, default) for
name, default in zip_longest(paramnames, defparams, fillvalue=None)]
# params = [ build_param(ast, name, default) for
# name, default in zip(paramnames, defparams) ]
# params = []
# for i, name in enumerate(paramnames):
# default = defparams[i] if len(defparams) > i else None
# params.append( build_param(ast, name, default) )
params.reverse() # back to correct order

View File

@@ -65,8 +65,6 @@ def disco(version, co, out=None):
scanner = get_scanner(version)
tokens, customize = scanner.disassemble(co)
for t in tokens:
print(t, file=real_out)
print(file=out)

View File

@@ -42,6 +42,7 @@ from __future__ import print_function
import inspect, sys, re
from uncompyle6 import PYTHON3
from uncompyle6.parser import get_python_parser
from uncompyle6.parsers.astnode import AST
@@ -50,10 +51,12 @@ import uncompyle6.parser as python_parser
from uncompyle6.scanner import Token, Code, get_scanner
if PYTHON3:
from itertools import zip_longest
from io import StringIO
minint = -sys.maxsize-1
maxint = sys.maxsize
else:
from itertools import izip_longest as zip_longest
from StringIO import StringIO
minint = -sys.maxint-1
maxint = sys.maxint
@@ -1319,14 +1322,14 @@ class Walker(GenericASTTraversal, object):
# build parameters
# This would be a nicer piece of code, but I can't get this to work
# now, have to find a usable lambda constuct hG/2000-09-05
# params = map(lambda name, default: build_param(ast, name, default),
# paramnames, defparams)
params = []
for i, name in enumerate(paramnames):
default = defparams[i] if len(defparams) > i else None
params.append( build_param(ast, name, default) )
params = [build_param(ast, name, default) for
name, default in zip_longest(paramnames, defparams, fillvalue=None)]
# params = [ build_param(ast, name, default) for
# name, default in zip(paramnames, defparams) ]
# params = []
# for i, name in enumerate(paramnames):
# default = defparams[i] if len(defparams) > i else None
# params.append( build_param(ast, name, default) )
params.reverse() # back to correct order