| #!/bin/bash
|
| # Test & Cleanup Suite for Ubuntu 22.04
|
| set -e
|
|
|
| PROJECT_DIR="~/clones/autokey"
|
|
|
| echo "--- 2. Installing System Dependencies ---"
|
| sudo apt update
|
| # libssl-dev and build-essential are required for pyenv to compile newer Python versions
|
| sudo apt install -y build-essential libssl-dev zlib1g-dev \
|
| libbz2-dev libreadline-dev libsqlite3-dev curl git \
|
| libncurses5-dev libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev \
|
| libffi-dev liblzma-dev libdbus-1-dev libglib2.0-dev \
|
| libcairo2-dev python3-pyqt5 python3-dbus python3-gi \
|
| gir1.2-gtk-3.0 xvfb xdg-utils
|
|
|
| echo "--- 3. Setting up pyenv & Python Versions ---"
|
| if [ ! -d "$HOME/.pyenv" ]; then
|
| curl https://pyenv.run | bash
|
| export PYENV_ROOT="$HOME/.pyenv"
|
| export PATH="$PYENV_ROOT/bin:$PATH"
|
| eval "$(pyenv init - bash)"
|
| echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
|
| echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
|
| echo 'eval "$(pyenv init - bash)"' >> ~/.bashrc
|
| fi
|
|
|
| # On 22.04, 3.10 is system; install 3.11 and 3.12 via pyenv
|
| pyenv install -s 3.11.15
|
| pyenv install -s 3.12.3
|
| pyenv local system 3.11.15 3.12.3
|
|
|
| echo "--- 4. Generating Essential tox.ini ---"
|
| cat <<EOF > tox.ini
|
| [tox]
|
| envlist = py310, py311, py312
|
| skipsdist = True
|
|
|
| [testenv]
|
| sitepackages = True
|
| passenv = DISPLAY, XAUTHORITY, HOME, XDG_RUNTIME_DIR
|
| setenv =
|
| PYTHONPATH = {toxinidir}/lib
|
| deps =
|
| pytest
|
| pytest-cov
|
| PyHamcrest
|
| PyGObject
|
| dbus-python
|
| python-magic
|
| python-xlib
|
| pyinotify
|
| PyQt5
|
| commands = pytest
|
| EOF
|
|
|
| echo "--- 5. Running Tests with Xvfb ---"
|
| # Ubuntu 22.04 may not strictly enforce PEP 668, but venv is still safest
|
| python3 -m venv .venv
|
| source .venv/bin/activate
|
| pip install --upgrade pip tox
|
| xvfb-run -a tox run -c setup.cfg -r -e clean,coverage,report
|
|
|
| echo "--- 6. Opening Report & Final Cleanup ---"
|
| if [ -f "test_coverage_report_html/index.html" ]; then
|
| echo "Opening coverage report in browser..."
|
| xdg-open test_coverage_report_html/index.html
|
| echo "Report opened. Press any key to DELETE the project folder and clean up..."
|
| read -n 1 -s
|
| fi
|
|
|
| # Cleanup
|
| deactivate || true
|
| cd ..
|
| # rm -rf "$PROJECT_DIR"
|
|
|
| echo "--- VM IS CLEAN. TEST COMPLETE ---"
|