#!/bin/bash
set -efu

arch=$(dpkg-architecture -qDEB_HOST_ARCH)

EXTRA_TEST_FLAGS=""

# some tests are expected to fail
# so list tests to skip in array variable SKIP_TEST_LIST
declare -a SKIP_TEST_LIST

# test_pmg_view in test_pmg.py generates an XIO error when shutting down (after successfully running the test)
SKIP_TEST_LIST=("${SKIP_TEST_LIST[@]}" test_pmg_view)

SKIP_TESTS=""
list_initialised=0
for t in "${SKIP_TEST_LIST[@]}"; do
    if [ ${list_initialised} = 0 ]; then
        SKIP_TESTS=$t
        list_initialised=1
    else
        SKIP_TESTS="${SKIP_TESTS} or $t"
    fi
done
if [ "x${SKIP_TESTS}" != "x" ]; then
    SKIP_TESTS="not ( ${SKIP_TESTS} )"
fi
echo "skipping tests with SKIP_TEST_LIST=${SKIP_TEST_LIST[@]}"

for py in `py3versions -s`; do
  PMG_TEST_FILES_DIR=/usr/share/doc/pymatgen-test-files/examples/test-files \
    $py -m pytest -v ${EXTRA_TEST_FLAGS} --durations=30 --color=no  -k "${SKIP_TESTS}" tests
done
