tests/installed: Prefer python3 over python2
In a world progressively unapproving of python2, let's be a bit smarter and support testing on platforms that only have python3 installed. Closes: #1546 Approved by: cgwalters
This commit is contained in:
parent
c0c9cfdb9d
commit
d56058bc9a
|
|
@ -37,6 +37,16 @@ prepare_tmpdir() {
|
||||||
cd ${test_tmpdir}
|
cd ${test_tmpdir}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if test -x /usr/bin/python3; then
|
||||||
|
export PYTHON=/usr/bin/python3
|
||||||
|
export PYTHONHTTPSERVER=http.server
|
||||||
|
elif test -x /usr/bin/python; then
|
||||||
|
export PYTHON=/usr/bin/python
|
||||||
|
export PYTHONHTTPSERVER=SimpleHTTPServer
|
||||||
|
else
|
||||||
|
fatal "no python found"
|
||||||
|
fi
|
||||||
|
|
||||||
# This is copied from flatpak/flatpak/tests/test-webserver.sh
|
# This is copied from flatpak/flatpak/tests/test-webserver.sh
|
||||||
run_tmp_webserver() {
|
run_tmp_webserver() {
|
||||||
dir=$1
|
dir=$1
|
||||||
|
|
@ -44,22 +54,22 @@ run_tmp_webserver() {
|
||||||
test -n ${test_tmpdir}
|
test -n ${test_tmpdir}
|
||||||
|
|
||||||
cd ${dir}
|
cd ${dir}
|
||||||
env PYTHONUNBUFFERED=1 setsid python -m SimpleHTTPServer 0 &>${test_tmpdir}/httpd-output &
|
env PYTHONUNBUFFERED=1 setsid $PYTHON -m $PYTHONHTTPSERVER 0 &>${test_tmpdir}/httpd-output &
|
||||||
cd -
|
cd -
|
||||||
child_pid=$!
|
child_pid=$!
|
||||||
|
|
||||||
for x in $(seq 50); do
|
for x in $(seq 10); do
|
||||||
# Snapshot the output
|
# Snapshot the output
|
||||||
cp ${test_tmpdir}/httpd-output{,.tmp}
|
cp ${test_tmpdir}/httpd-output{,.tmp}
|
||||||
# If it's non-empty, see whether it matches our regexp
|
# If it's non-empty, see whether it matches our regexp
|
||||||
if test -s ${test_tmpdir}/httpd-output.tmp; then
|
if test -s ${test_tmpdir}/httpd-output.tmp; then # py3's http.server prints the http:// address also
|
||||||
sed -e 's,Serving HTTP on 0.0.0.0 port \([0-9]*\) \.\.\.,\1,' < ${test_tmpdir}/httpd-output.tmp > ${test_tmpdir}/httpd-port
|
sed -e 's,Serving HTTP on 0.0.0.0 port \([0-9]*\)\( (http://[^)]*)\)\? \.\.\.,\1,' < ${test_tmpdir}/httpd-output.tmp > ${test_tmpdir}/httpd-port
|
||||||
if ! cmp ${test_tmpdir}/httpd-output.tmp ${test_tmpdir}/httpd-port 1>/dev/null; then
|
if ! cmp ${test_tmpdir}/httpd-output.tmp ${test_tmpdir}/httpd-port 1>/dev/null; then
|
||||||
# If so, we've successfully extracted the port
|
# If so, we've successfully extracted the port
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
sleep 0.1
|
sleep 1
|
||||||
done
|
done
|
||||||
port=$(cat ${test_tmpdir}/httpd-port)
|
port=$(cat ${test_tmpdir}/httpd-port)
|
||||||
echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
|
echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
|
||||||
|
|
@ -75,16 +85,6 @@ fi
|
||||||
# We need to be root
|
# We need to be root
|
||||||
assert_streq $(id -u) 0
|
assert_streq $(id -u) 0
|
||||||
|
|
||||||
PYTHON=
|
|
||||||
for py in /usr/bin/python3 /usr/bin/python; do
|
|
||||||
if ! test -x ${py}; then continue; fi
|
|
||||||
export PYTHON=${py}
|
|
||||||
break
|
|
||||||
done
|
|
||||||
if test -z "${PYTHON}"; then
|
|
||||||
fatal "no python found"
|
|
||||||
fi
|
|
||||||
|
|
||||||
rpmostree_query_json() {
|
rpmostree_query_json() {
|
||||||
query=$1
|
query=$1
|
||||||
rpm-ostree status --json | $PYTHON -c 'import json,sys; v=json.load(sys.stdin); print(v'${query}')'
|
rpm-ostree status --json | $PYTHON -c 'import json,sys; v=json.load(sys.stdin); print(v'${query}')'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue