#!/bin/sh -e

if [ "$AUTOPKGTEST_TMP" = "" ] ; then
  AUTOPKGTEST_TMP=`mktemp -d /tmp/python-biopython-test.XXXXXX`
  trap "rm -rf $AUTOPKGTEST_TMP" 0 INT QUIT ABRT PIPE TERM
fi
cd $AUTOPKGTEST_TMP
cp -a /usr/share/doc/python-biopython-doc/Tests $AUTOPKGTEST_TMP
mkdir -p Doc/
cp -a /usr/share/doc/python-biopython-doc/Doc/Tutorial.tex* Doc
cp -a /usr/share/doc/python-biopython-doc/Doc/Tutorial Doc
cp -a /usr/share/doc/python-biopython-doc/Doc/examples Doc
unset GZIP
find . -name "*.gz" -exec gunzip \{\} \;
SUBSMAT_DIR="Bio/Align/substitution_matrices/data"
mkdir -pv "$SUBSMAT_DIR/"
cp -av "/usr/lib/python3/dist-packages/$SUBSMAT_DIR"/* "$SUBSMAT_DIR/"
cd Tests
# we really need this gzipped duplicate of the example.fastq and E3MFGYR02_random_10_reads.sff files to pass the BGZF compression test
gzip --keep Quality/example.fastq
gzip --keep Roche/E3MFGYR02_random_10_reads.sff
gzip --keep Fasta/flowers.pro


echo "Remove test test_Tutorial.py which is bound to fail"
find . -name test_Tutorial.py -delete

# bwa is only available on amd64
BUILDARCH=
if [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" != "amd64" ]; then
    rm -f test_BWA_tool.py
fi

# execute tests
################################################################################
# in the Debian package dialign it is not needed to set DIALIGN2_DIR but the
# test is verifying this dir to run the EMBOSS test
# test_Emboss also requires to have the environment variable EMBOSS_ROOT set

for pi in $(py3versions -s); do
    LC_ALL=C.UTF-8 DIALIGN2_DIR=/usr/share/dialign EMBOSS_ROOT=/usr/lib/emboss HOME=$AUTOPKGTEST_TMP ${pi} run_tests.py --offline
done

