Skip to content

Commit

Permalink
Add darius' test. Start to reorg test/examples...
Browse files Browse the repository at this point in the history
So that it groups test examples like the tests runners do.
  • Loading branch information
rocky committed May 4, 2020
1 parent c59ce0a commit e4782c0
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 14 deletions.
7 changes: 5 additions & 2 deletions test/examples/add-test.sh → test/add-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
if [[ $# == 0 ]]; then
print 2>&1 "Need to pass a python file to compile"
fi
mydir=$(dirname ${BASH_SOURCE[0]})

PYENV_VERSIONS=${PYENV_VERSIONS:-"3.3.7 3.4.10 3.5.9 2.7.18 2.6.9 2.5.6"}
for file in $*; do
for version in $PYENV_VERSIONS; do
pyenv local $version
python ./compile-file.py "$file"
python ${mydir}/compile-file.py "$file"
done
rm -v .pyenv_version *~ || /bin/true
short=$(basename $file .py)
git add -f ../bytecode-*/${short}*
git add -f ${mydir}./bytecode-*/${short}*
done
rm .python-version
Binary file modified test/bytecode-2.6/test_break_in_with.pyc
Binary file not shown.
Binary file modified test/bytecode-2.6/test_continue_in_with.pyc
Binary file not shown.
Binary file removed test/bytecode-2.7/compile-file.pyc
Binary file not shown.
Binary file modified test/bytecode-2.7/test_break_in_with.pyc
Binary file not shown.
Binary file modified test/bytecode-2.7/test_continue_in_with.pyc
Binary file not shown.
Binary file removed test/bytecode-3.3/compile-file.pyc
Binary file not shown.
Binary file modified test/bytecode-3.3/test_break_in_with.pyc
Binary file not shown.
Binary file modified test/bytecode-3.3/test_continue_in_with.pyc
Binary file not shown.
Binary file modified test/bytecode-3.4/test_break_in_with.pyc
Binary file not shown.
Binary file not shown.
Binary file modified test/bytecode-3.4/test_continue_in_with.pyc
Binary file not shown.
Binary file modified test/bytecode-3.5/test_break_in_with.pyc
Binary file not shown.
Binary file not shown.
Binary file modified test/bytecode-3.5/test_continue_in_with.pyc
Binary file not shown.
Binary file modified test/bytecode-3.5/test_map_unpack.pyc
Binary file not shown.
32 changes: 20 additions & 12 deletions test/examples/compile-file.py → test/compile-file.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
#!/usr/bin/env python
import sys
import re, sys
import os.path as osp

# We do this crazy conversion from float to support Python 2.6 which
# doesn't support version_major, and has a bug in
# floating point so we can't divide 26 by 10 and get
# 2.6
PY_VERSION = sys.version_info[0] + (sys.version_info[1] / 10.0)

def get_srcdir():
filename = osp.normcase(osp.dirname(__file__))
return osp.realpath(filename)
if PY_VERSION > 2.5:
return osp.relpath(osp.normcase(osp.dirname(__file__)))
else:
return osp.normcase(osp.dirname(__file__))

if len(sys.argv) != 2:
print("Usage: compile-file.py *byte-compiled-file*")
sys.exit(1)
source = sys.argv[1]

assert source.endswith('.py')
basename = source[:-3]
if PY_VERSION > 2.6:
source = osp.normpath(osp.relpath(sys.argv[1]))
else:
source = osp.normpath(sys.argv[1])

# We do this crazy conversion from float to support Python 2.6 which
# doesn't support version_major, and has a bug in
# floating point so we can't divide 26 by 10 and get
# 2.6
PY_VERSION = sys.version_info[0] + (sys.version_info[1] / 10.0)
assert source.endswith('.py')
basename = osp.basename(source[:-3])

bytecode_path = osp.join(get_srcdir(), "..", "bytecode-%s" % PY_VERSION, "%s.pyc" % basename)
bytecode_path = osp.normpath(osp.join(get_srcdir(),
"bytecode-%s" % PY_VERSION,
"%s.pyc" % basename))

import py_compile
print("compiling %s to %s" % (source, bytecode_path))
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions test/examples/functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.python-version
15 changes: 15 additions & 0 deletions test/examples/functions/test_closure_vars_from_static_parent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Test provided by Darius
#
# https://github.com/nedbat/byterun/pull/20/commits/70727da1e5c6f98075b2eeecc597cb81b43e7c4f
# for issue https://github.com/nedbat/byterun/issues/17
def f(xs):
return lambda: xs[0]


def g(h):
xs = 5
lambda: xs
return h()


assert g(f([42])) == 42
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ def test_no_builtins(self):


class TestClosures(vmtest.VmTestCase):
if PYTHON_VERSION > 3.2:
def test_closure_vars_from_static_parent(self):
self.self_checking()

def test_closures(self):
self.assert_ok("""\
def make_adder(x):
Expand Down

0 comments on commit e4782c0

Please sign in to comment.