#!/bin/sh
# This script copies those tests that were failing in the build process
# for no obvious reasons and the data needed by the tests into a temporary
# directory and runs them with all available Python interpreters

if [ "$ADTTMP" = "" ] ; then
  ADTTMP=`mktemp -d /tmp/python-biopython-failed-tests.XXXXXX`
fi

DOC=/usr/share/doc/python-biopython-doc/
DATA=$DOC/Tests
TESTS=$DOC/Tests_avoid

cd $ADTTMP
mkdir Doc
cp -a $DOC/Doc/Tutorial.tex*		Doc
mkdir Tests
cd Tests
cp -a $DATA/run_tests.py*		.
mkdir Clustalw
mkdir Fasta
cp -a $DATA/Fasta/f00[12]*		Fasta
mkdir GenBank
cp -a $DATA/GenBank/NC_005816.gb*	GenBank
mkdir Graphics
cp -a $DATA/Graphics/README*		Graphics
mkdir Medline
cp -a $DATA/Medline/pubmed_result1.txt*	Medline
mkdir Phylip
cp -a $DATA/Phylip/hennigian.phy*	Phylip
mkdir Quality
cp -a $DATA/Quality/example.fasta*	Quality

FAILINGTESTS="GenomeDiagram Fasttree_tool Mafft_tool Tutorial ColorSpiral trie"
for ft in $FAILINGTESTS ; do
    cp -a $TESTS/test_${ft}.py* .
done
find .. -name "*.gz" -exec gunzip \{\} \;

for ft in $FAILINGTESTS ; do
    for pi in $(pyversions -i) $(py3versions -i); do
        LC_ALL=C.UTF-8 $pi run_tests.py -v test_$ft 2>&1 | tee > ../${ft}_${pi}.log
        if grep -qwi fail ../${ft}_${pi}.log ; then
            echo "Test ${ft} with ${pi}: FAIL"
        else
            echo "Test ${ft} with ${pi}: ok"
        fi
    done
done
rm -fr *.pyc __pycache__
echo "Log files of tests can be found in $ADTTMP"
