#!/usr/bin/bash

set -e 

testname=$(basename $0)
pkgname=${testname/%-unittests/}

mkdir -p "$AUTOPKGTEST_TMP/$pkgname"
cp -r "$pkgname"/tests "$AUTOPKGTEST_TMP/$pkgname"

dpkgarch=$(dpkg --print-architecture)
echo "Running on arch: $dpkgarch"

echo "Ignoring flaky test test_import_duplicated_docx"
testfilter="not test_import_duplicated_docx"
if [ "$dpkgarch" = s390x ]; then
	echo "Ignoring test_get_boxes on s390x arch"
	testfilter="$testfilter and not test_get_boxes"
elif [ "$dpkgarch" = riscv64 ]; then
	echo "Ignoring libreoffice related tests on riscv64"
	testfilter="$testfilter and not TestLibreOfficePdf and not TestConvertedImport and not TestConvertedPdf"
fi

cd "$AUTOPKGTEST_TMP/$pkgname"
python3 -m pytest -o 'python_files=tests_*.py' --cov=${pkgname/-/_} --cov-report=term-missing --cov-branch -k "$testfilter" tests/
