#!/usr/bin/make -f
export PYBUILD_TEST_ARGS=-vv
# pybuild's copy_test_files copies the tests/ tree with shutil.copytree()
# (which dereferences symlinks), turning the fixtures/tar_data/test_symlink ->
# test1 link into a real directory and breaking the tests.  Pre-populate the
# test build dir with a symlink-preserving copy (cp -a) so copy_test_files
# skips its dereferencing copy. This runs for both the build-time test and the
# pybuild-autopkgtest autopkgtest.
export PYBUILD_BEFORE_TEST=mkdir -p {build_dir}/tests && cp -a $(CURDIR)/tests/. {build_dir}/tests/

%:
	dh $@ --buildsystem=pybuild

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	for dir in ./.pybuild/*; do \
		cp -av $(CURDIR)/tests $$dir/build; \
	done
	dh_auto_test
	# Remove test-generated artifacts so they are not installed in dist-packages.
	find ./.pybuild/*/build -maxdepth 1 -type f \( -name "test.tar" -o -name "<Mock id='*'>" \) -delete
	rm -r ./.pybuild/*/build/tests ./.pybuild/*/build/core*tar.gz*
endif
