forked from Mirrors/flatpak-builder
Add test for python .pyc/.pyo rewriting
This catches regressions in the fix in the previous commit, where old stale .py[oc] files can wrongly become "unstale" when we change the .py file mtime to 1.tingping/wmclass
parent
006d9a1927
commit
9c57a5751e
|
@ -85,6 +85,12 @@ installed_test_data = \
|
|||
tests/test.json \
|
||||
tests/session.conf.in \
|
||||
tests/0001-Add-test-logo.patch \
|
||||
tests/org.test.Python.json \
|
||||
tests/empty-configure \
|
||||
tests/testpython.py \
|
||||
tests/testpython.py \
|
||||
tests/importme.py \
|
||||
tests/importme2.py \
|
||||
$(NULL)
|
||||
|
||||
installed_test_keyringdir = $(installed_testdir)/test-keyring
|
||||
|
@ -111,6 +117,7 @@ dist_test_scripts = \
|
|||
tests/test-bundle.sh \
|
||||
tests/test-bundle-system.sh \
|
||||
tests/test-builder.sh \
|
||||
tests/test-builder-python.sh \
|
||||
$(NULL)
|
||||
|
||||
test_programs = testdb test-doc-portal testlibrary
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/sh
|
||||
|
||||
cat <<EOF > Makefile
|
||||
all:
|
||||
echo Building
|
||||
|
||||
install:
|
||||
echo Installing
|
||||
EOF
|
|
@ -0,0 +1,2 @@
|
|||
import sys
|
||||
foo = "first"
|
|
@ -0,0 +1,2 @@
|
|||
import sys
|
||||
foo = "modified"
|
|
@ -193,6 +193,12 @@ setup_sdk_repo () {
|
|||
update_repo
|
||||
}
|
||||
|
||||
setup_python2_repo () {
|
||||
GPGARGS="$FL_GPGARGS" . $(dirname $0)/make-test-runtime.sh org.test.PythonPlatform bash python2 ls cat echo readlink > /dev/null
|
||||
GPGARGS="$FL_GPGARGS" . $(dirname $0)/make-test-runtime.sh org.test.PythonSdk python2 bash ls cat echo readlink make mkdir cp touch > /dev/null
|
||||
update_repo
|
||||
}
|
||||
|
||||
install_repo () {
|
||||
${FLATPAK} ${U} install test-repo org.test.Platform master
|
||||
${FLATPAK} ${U} install test-repo org.test.Hello master
|
||||
|
@ -202,6 +208,11 @@ install_sdk_repo () {
|
|||
${FLATPAK} ${U} install test-repo org.test.Sdk master
|
||||
}
|
||||
|
||||
install_python2_repo () {
|
||||
${FLATPAK} ${U} install test-repo org.test.PythonPlatform master
|
||||
${FLATPAK} ${U} install test-repo org.test.PythonSdk master
|
||||
}
|
||||
|
||||
run () {
|
||||
${CMD_PREFIX} flatpak run "$@"
|
||||
|
||||
|
@ -230,6 +241,14 @@ skip_without_bwrap () {
|
|||
fi
|
||||
}
|
||||
|
||||
skip_without_python2 () {
|
||||
if ! test -f /usr/bin/python2 || ! test -f /usr/lib*/python2.7/os.py ; then
|
||||
echo "1..0 # SKIP this test requires /usr/bin/python2 (2.7) support"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
sed s#@testdir@#${test_builddir}# ${test_srcdir}/session.conf.in > session.conf
|
||||
dbus-daemon --fork --config-file=session.conf --print-address=3 --print-pid=4 \
|
||||
3> dbus-session-bus-address 4> dbus-session-bus-pid
|
||||
|
|
|
@ -20,6 +20,21 @@ for i in $@; do
|
|||
I=`which $i`
|
||||
cp $I ${DIR}/usr/bin
|
||||
ldd $I | sed "s/.* => //" | awk '{ print $1}' | grep ^/ | grep ^/ >> $T
|
||||
if test $i == python2; then
|
||||
mkdir -p ${DIR}/usr/lib/python2.7/lib-dynload
|
||||
# This is a hardcoded minimal set of modules we need in the current tests.
|
||||
# Pretty hacky stuff. Add modules as needed.
|
||||
for py in site os stat posixpath genericpath warnings \
|
||||
linecache types UserDict abc _abcoll \
|
||||
_weakrefset copy_reg traceback sysconfig \
|
||||
re sre_compile sre_parse sre_constants \
|
||||
_sysconfigdata ; do
|
||||
cp /usr/lib*/python2.7/$py.py ${DIR}/usr/lib/python2.7
|
||||
done
|
||||
for so in _locale strop ; do
|
||||
cp /usr/lib*/python2.7/lib-dynload/${so}module.so ${DIR}/usr/lib/python2.7/lib-dynload
|
||||
done
|
||||
fi
|
||||
done
|
||||
ln -s bash ${DIR}/usr/bin/sh
|
||||
for i in `sort -u $T`; do
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
"app-id": "org.test.Python",
|
||||
"runtime": "org.test.PythonPlatform",
|
||||
"sdk": "org.test.PythonSdk",
|
||||
"command": "testpython.py",
|
||||
"modules": [
|
||||
{
|
||||
"name": "compiled-python",
|
||||
"post-install": [
|
||||
"mkdir /app/bin",
|
||||
"cp testpython.py /app/bin",
|
||||
"cp importme.py /app/bin",
|
||||
/* Compile importme.py */
|
||||
"/app/bin/testpython.py"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"type": "file",
|
||||
"path": "empty-configure",
|
||||
"dest-filename": "configure"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"path": "testpython.py"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"path": "importme.py"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "modify-python",
|
||||
"post-install": [
|
||||
"cp importme2.py /app/bin/importme.py"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"type": "file",
|
||||
"path": "empty-configure",
|
||||
"dest-filename": "configure"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"path": "importme2.py"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "recompile-modified-python",
|
||||
"post-install": [
|
||||
"/app/bin/testpython.py"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"type": "file",
|
||||
"path": "empty-configure",
|
||||
"dest-filename": "configure"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
. $(dirname $0)/libtest.sh
|
||||
|
||||
skip_without_bwrap
|
||||
skip_without_user_xattrs
|
||||
skip_without_python2
|
||||
|
||||
echo "1..1"
|
||||
|
||||
setup_repo
|
||||
install_repo
|
||||
setup_python2_repo
|
||||
install_python2_repo
|
||||
|
||||
# Need /var/tmp cwd for xattrs
|
||||
REPO=`pwd`/repo
|
||||
cd $TEST_DATA_DIR/
|
||||
|
||||
cp $(dirname $0)/org.test.Python.json .
|
||||
cp -a $(dirname $0)/empty-configure .
|
||||
cp -a $(dirname $0)/testpython.py .
|
||||
cp $(dirname $0)/importme.py .
|
||||
cp $(dirname $0)/importme2.py .
|
||||
flatpak-builder --force-clean appdir org.test.Python.json
|
||||
|
||||
assert_has_file appdir/files/bin/importme.pyc
|
||||
|
||||
flatpak-builder --run appdir org.test.Python.json testpython.py > testpython.out
|
||||
|
||||
assert_file_has_content testpython.out ^modified$
|
||||
|
||||
echo "ok handled pyc rewriting multiple times"
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/python2
|
||||
|
||||
import importme
|
||||
print importme.foo
|
Loading…
Reference in New Issue