#!/bin/bash -eu
pushd "$(dirname $0)" >/dev/null
test_dir="$(pwd)"
gen_code_path=${test_dir}
runtime_library_dir=${test_dir}/../python
${test_dir}/../flatc -p -o ${gen_code_path} -I include_test monster_test.fbs --gen-object-api
${test_dir}/../flatc -p -o ${gen_code_path} -I include_test monster_test.fbs --gen-object-api --gen-onefile
${test_dir}/../flatc -p -o ${gen_code_path} -I include_test monster_extra.fbs --gen-object-api
interpreters_tested=()
function run_tests() {
if $(which ${1} >/dev/null); then
echo "Testing with interpreter: ${1}"
PYTHONDONTWRITEBYTECODE=1 \
JYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=${runtime_library_dir}:${gen_code_path} \
JYTHONPATH=${runtime_library_dir}:${gen_code_path} \
COMPARE_GENERATED_TO_GO=0 \
COMPARE_GENERATED_TO_JAVA=0 \
$1 py_test.py $2 $3 $4 $5
if [ $1 = python3 ]; then
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=${runtime_library_dir}:${gen_code_path} \
$1 py_flexbuffers_test.py
fi
interpreters_tested+=(${1})
echo
fi
}
run_tests python2.6 100 100 100 false
run_tests python2.7 100 100 100 false
run_tests python2.7 100 100 100 true
run_tests python3 100 100 100 false
run_tests python3 100 100 100 true
run_tests pypy 100 100 100 false
if [ ${#interpreters_tested[@]} -eq 0 ]; then
echo "No Python interpeters found on this system, could not run tests."
exit 1
fi
if $(which coverage >/dev/null); then
echo 'Found coverage utility, running coverage with default Python:'
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=${runtime_library_dir}:${gen_code_path} \
coverage run --source=flatbuffers,MyGame py_test.py 0 0 0 > /dev/null
echo
cov_result=`coverage report --omit="*flatbuffers/vendor*,*py_test*" \
| tail -n 1 | awk ' { print $4 } '`
echo "Code coverage: ${cov_result}"
else
echo -n "Did not find coverage utility for default Python, skipping. "
echo "Install with 'pip install coverage'."
fi
echo
echo "OK: all tests passed for ${#interpreters_tested[@]} interpreters: ${interpreters_tested[@]}."