#! /bin/bash
#
# debian/tests/upstream-testsuite
# Part of Debian ‘jaraco.logging’ package.
#
# This is free software, and you are welcome to redistribute it under
# certain conditions; see the end of this file for copyright
# information, grant of license, and disclaimer of warranty.

# Run the upstream test suite on the installed Python package.

set -o errexit
set -o errtrace
set -o nounset

program_dir="$(dirname "$(realpath --strip "$0")")"

DISTRIBUTION_NAME=jaraco
python_package="/usr/lib/python3/dist-packages"/"${DISTRIBUTION_NAME}"

# Use a working directory away from the source package root,
# so that Python imports will not find the local source package.
working_dir="$(mktemp --tmpdir --directory)"

# Copy the PyTest configuration file.
pytest_config_name="pytest.ini"
pytest_config_copy="${working_dir}"/"${pytest_config_name}"
cp ./"${pytest_config_name}" "${pytest_config_copy}"

# Symlink the installed Python package to the working directory for testing.
python_package_symlink="${working_dir}"/"${DISTRIBUTION_NAME}"
ln --symbolic "$python_package" "$python_package_symlink"

cd "$working_dir"/

for py in $(py3versions --supported 2>/dev/null) ; do
    printf "Python command: %s\n" $py
    $py -m pytest --doctest-modules .
    printf "\n"
done

cd "$program_dir"/

# Clean temporary files.
rm -v "$python_package_symlink"
rm -v "$pytest_config_copy"
rm -vr "$working_dir"/


# Copyright © 2016–2026 Ben Finney <bignose@debian.org>
# This is free software: you may copy, modify, and/or distribute this work
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; version 3 of that license or any later version.
# No warranty expressed or implied.

# Local variables:
# coding: utf-8
# mode: shell-script
# End:
# vim: fileencoding=utf-8 filetype=sh :
