#!/bin/bash
set -e

test_pkg=dnaio
# using these data for testing
source_pkg=unicycler-data

if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${test_pkg}-test.XXXXXX)
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

if [ -d /usr/share/${source_pkg}/sample_data ] ; then
  cp -a /usr/share/${source_pkg}/sample_data/ ${AUTOPKGTEST_TMP}
else
  echo "Please install package unicycler-data to run this script"
  exit 1
fi

cd ${AUTOPKGTEST_TMP}

cat > simple_test.py << EOL
import os
import dnaio

dir = 'sample_data'

for filename in os.listdir(dir):
    print(filename)
    with dnaio.open(dir + '/' + filename) as inf:
        bp = 0
        for record in inf:
            bp += len(record)
    print(f'The input file contains {bp/1E6:.1f} Mbp')
EOL

# run test
python3 ./simple_test.py

echo "PASS"
