Duplicate package test to other script for testing

This commit is contained in:
ChillerDragon 2023-04-07 08:58:37 +02:00
parent d8790e94f4
commit 2052ff6da0

73
scripts/test_package.sh Executable file
View file

@ -0,0 +1,73 @@
#!/bin/bash
if [ ! -f ./scripts/run_tests.sh ]
then
echo "Error: ./scripts/run_tests.sh not found"
exit 1
fi
if [ ! -f pyproject.toml ]
then
echo "Error: pyproject.toml not found"
exit 1
fi
echo "[*] wiping old dist ..."
[[ -d dist ]] && rm -rf dist
if ! python -m build
then
echo "Error: build failed"
exit 1
fi
if ! compgen -G ./dist/twnet_parser-*.tar.gz > /dev/null
then
echo "Error: build did not generate expected file"
echo " dist/twnet_parser-*.tar.gz"
exit 1
fi
if ! pip install dist/twnet_parser-*.tar.gz
then
echo "Error: local test install of package failed"
exit 1
fi
if ! python -c "import twnet_parser"
then
echo "Error: local test import failed"
exit 1
fi
rm -rf /tmp/twnet_parser_test
mkdir -p /tmp/twnet_parser_test
cp -r tests /tmp/twnet_parser_test || exit 1
cp dist/twnet_parser-*.tar.gz /tmp/twnet_parser_test/
(
deactivate &>/dev/null
cd /tmp/twnet_parser_test || exit 1
python -m venv venv
# shellcheck disable=SC1091
source venv/bin/activate
if ! pip install twnet_parser-*.tar.gz
then
echo "Error: local test install of package failed (venv)"
exit 1
fi
if ! python -c "import twnet_parser"
then
echo "Error: local test import failed (venv)"
exit 1
fi
if ! python -c "import twnet_parser.packet"
then
echo "Error: local test import twnet_parser.packet failed (venv)"
exit 1
fi
pip install pytest
python -m pytest tests || exit 1
) || {
echo "[*] venv install tests failed.";
exit 1;
}
echo "[*] venv tests passed."