#!/bin/bash
set -e

pkg=snakemake
ROOT=$(pwd)

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

# copy the test tree so we're allowed to write to it
cd "${AUTOPKGTEST_TMP}"
cp -r ${ROOT}/tests .

export HOME="${AUTOPKGTEST_TMP}"

# workaround for #928826
. /etc/profile.d/modules.sh

#sometimes hangs, so use timeout and retry
python3 -m pytest -o faulthandler_timeeout=60 -v tests/test*.py -k 'test_pipes_fail' || python3 -m pytest -o faulthandler_timeeout=60 -v tests/test*.py -k 'test_pipes_fail' || python3 -m pytest -o faulthandler_timeeout=60 -v tests/test*.py -k 'test_pipes_fail'

#See debian/rules for why these are excluded
python3 -m pytest -v tests/test*.py -k 'not test_cwl and not test_cwl_singularity and not test_url_include and not test_wrapper and not test_issue1083 and not test_github_issue78 and not test_container and not test_singularity and not test_singularity_conda and not test_convert_to_cwl and not test_report and not test_report_zip and not test_archive and not test_jupyter_notebook and not test_conda and not test_upstream_conda and not test_conda_custom_prefix and not test_script and not test_issue635 and not test_issue1093 and not test_default_resources and not test_default_remote and not test_remote and not test_output_file_cache_remote and not test_tibanna and not test_module_complex and not test_module_complex2 and not test_module_with_script and not test_module_report and not test_modules_meta_wrapper and not test_tes and not test_deploy_script and not test_deploy_hashing and not test_peppy and not test_modules_peppy and not test_report_display_code and not test_wrapper_local_git_prefix and not test_template_engine and not test_github_issue1396 and not test_modules_prefix and not test_env_modules and not test_github_issue1062 and not test_pipes_fail and not test_ancient and not test_symlink_time_handling and not test_github_issue1460 and not test_rule_inheritance_globals'
