Skip to content

Unit and integration tests #554

Unit and integration tests

Unit and integration tests #554

Workflow file for this run

name: Unit and integration tests
on:
push:
branches:
- '**'
schedule:
- cron: "0 1 * * *"
jobs:
Tests_and_docs:
strategy:
matrix:
# NOTE: macos complains about wheels; windows complains about script syntax
# os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest]
# NOTE: we might test also for qgis/qgis:3.22 that is the version of qgis-server that we are currently using in the Geoviewer, but it currently causes a segfault
# NOTE: qgis:stable points to the latest release, wheread qgis:latest points to qgis master
QGIS_DOCKER_VERSION: ['qgis/qgis:ltr', 'qgis/qgis:stable']
# NOTE: qgis uses its own python, but we want to check if there are problems interfacing with the engine while it uses different python versions
PYTHON_VERSION: ['3.9', '3.10', '3.11']
runs-on: ${{ matrix.os }}
env:
GITHUB_DEF_BR: master
steps:
- uses: actions/checkout@v2
- name: 🐍 Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.PYTHON_VERSION }}
- name: Prepare Start file for docker
run: |
set -x
$(cat << EOF > ./startX.sh
apt update --allow-releaseinfo-change
DEBIAN_FRONTEND=noninteractive apt install -y python3-scipy python3-matplotlib python3-pyqt5.qtwebkit python3-pytest python3-pexpect xvfb git expect
chmod +x /tests_directory/qgis_startup.py
cp /tests_directory/qgis_startup.py /usr/bin/
cp /tests_directory/qgis_testrunner.py /usr/bin/
export DISPLAY=:1.0
Xvfb :1 -screen 0 1024x768x16
EOF
)
curl -O https://raw.githubusercontent.com/qgis/QGIS/master/.docker/qgis_resources/test_runner/qgis_setup.sh
curl -O https://raw.githubusercontent.com/qgis/QGIS/master/.docker/qgis_resources/test_runner/qgis_testrunner.sh
curl -O https://raw.githubusercontent.com/qgis/QGIS/master/.docker/qgis_resources/test_runner/qgis_testrunner.py
curl -O https://raw.githubusercontent.com/qgis/QGIS/master/.docker/qgis_resources/test_runner/qgis_startup.py
chmod +x ./qgis_setup.sh
chmod +x ./qgis_testrunner.sh
chmod +x ./qgis_testrunner.py
chmod +x ./startX.sh
- name: ⏳ Install engine and restore oqdata and docker container
run: |
PY_VER=${{ matrix.PYTHON_VERSION }}
echo "Python version to use: $PY_VER"
python3 --version
python$PY_VER --version
echo "Check if this is a pull request or not"
if [ -z "$GITHUB_HEAD_REF" ]
then
echo "It is not a pull request, use branch: $GITHUB_DEF_BR"
IRMT_BR=$GITHUB_DEF_BR
else
echo "It is a pull request, use branch: $GITHUB_HEAD_REF"
IRMT_BR=$GITHUB_HEAD_REF
fi
ENGINE_BR=$IRMT_BR
if [ "$(git ls-remote --heads https://github.com/gem/oq-engine.git ${ENGINE_BR})" == "" ]; then
ENGINE_BR='master';
fi
curl -O https://raw.githubusercontent.com/gem/oq-engine/master/install.py
ls -lrt install.py
echo "Engine branch: ${ENGINE_BR}"
python$PY_VER install.py user --version=${ENGINE_BR}
export PIP_DEFAULT_TIMEOUT=100
echo "Restore OQ-Engine demos for $ENGINE_BR branch "
source $HOME/openquake/bin/activate
oq reset -y
oq restore https://artifacts.openquake.org/travis/oqdata-${ENGINE_BR}.zip ~/oqdata
oq --version
oq webui start 172.17.0.1:8800 --skip-browser &> webui.log &
echo "Waiting WEBUI up on port 8800...."
while ! nc -z 172.17.0.1 8800; do
cat webui.log
sleep 5
done
curl http://172.17.0.1:8800/v1/engine_version
#
DOCKER_HOST=`ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+'`
ENGINE_HOST=`echo http://$DOCKER_HOST:8800`
docker run -d -t --name qgis -v /tmp/.X11-unix:/tmp/.X11-unix -v ${PWD}:/tests_directory -e OQ_ENGINE_HOST='http://172.17.0.1:8800' \
-e BRANCH="$IRMT_BR" -e ONLY_CALC_ID="$ONLY_CALC_ID" -e ONLY_OUTPUT_TYPE="$ONLY_OUTPUT_TYPE" -e GEM_QGIS_TEST=y ${{ matrix.QGIS_DOCKER_VERSION }} \
bash -c "/tests_directory/startX.sh"
sleep 10
- name: ℧ Run unit test
run: |
set -x
# OGR_SQLITE_JOURNAL=delete prevents QGIS from using WAL, which modifies geopackages even if they are just read
docker exec -t qgis bash -c "export DISPLAY=:1.0; export PYTHONPATH=/usr/share/qgis/python/plugins/:$PYTHONPATH; OGR_SQLITE_JOURNAL=delete python3 -m pytest -v /tests_directory/svir/test/unit/"
- name: ⨕ Run Integration test
run: |
set -x
echo " Check if this is a pull request or not"
if [ -z "$GITHUB_HEAD_REF" ]
then
echo " Is not a pull request, use branch: $GITHUB_DEF_BR"
IRMT_BR=$GITHUB_DEF_BR
else
echo " Is a pull request, use branch: $GITHUB_HEAD_REF"
IRMT_BR=$GITHUB_HEAD_REF
fi
# NOTE: we needto clone the engine inside the qgis docker in order to have demos folders available
ENGINE_BR=$IRMT_BR
if [ "$(git ls-remote --heads https://github.com/gem/oq-engine.git ${ENGINE_BR})" == "" ]; then
ENGINE_BR='master';
fi
# NOTE: cloning the engine is needed to find the demos directory, therefore being able to test running a calculation
docker exec qgis sh -c "export DISPLAY=:1.0; git clone -q -b $ENGINE_BR --depth=1 https://github.com/gem/oq-engine.git && echo 'Running against oq-engine/$GITHUB_BR'"
docker exec qgis sh -c "export DISPLAY=:1.0; /tests_directory/qgis_setup.sh svir"
docker exec -t qgis sh -c "export DISPLAY=:1.0; cd /tests_directory && ./qgis_testrunner.sh svir.test.integration.test_drive_oq_engine"
- name: 📖 Make documentation
run: |
set -x
docker exec qgis sh -c "export DISPLAY=:1.0; apt update --allow-releaseinfo-change; DEBIAN_FRONTEND=noninteractive apt install -y latexmk texlive-latex-extra python3-matplotlib python3-sphinx python3-sphinx-rtd-theme dvipng"
docker exec -t qgis sh -c "export DISPLAY=:1.0; export PYTHONPATH=$PYTHONPATH:/tests_directory; cd /tests_directory/svir/help; make latexpdf; make html"
- name: ㏒ Display web logs
run: |
set -x
cat webui.log