#!/bin/bash
set -e

pkg=python3-biom-format

if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  # Double quote below to expand the temporary directory variable now versus
  # later is on purpose.
  # shellcheck disable=SC2064
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

cp -a /usr/share/doc/${pkg}/examples "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

biom show-install-info
# we can only validate the tables if we have H5PY
for table in examples/*hdf5.biom; do
  biom validate-table -i ${table}
done

# validate JSON formatted tables
for table in examples/*table.biom; do
  biom validate-table -i ${table}
done

python3 /usr/lib/python3/dist-packages/biom/assets/exercise_api.py examples/rich_sparse_otu_table_hdf5.biom sample
python3 /usr/lib/python3/dist-packages/biom/assets/exercise_api.py examples/rich_sparse_otu_table_hdf5.biom observation
sh /usr/lib/python3/dist-packages/biom/assets/exercise_cli.sh
