Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests on Windows #854

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Unit and integration tests
on:
push:
branches:
- '**'
# FIXME: restore tests on push
# push:
# branches:
# - '**'
schedule:
- cron: "0 1 * * *"

Expand Down
146 changes: 146 additions & 0 deletions .github/workflows/test_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Test on Windows
on:
# NOTE: enables only scheduled or triggered manually, NOT on pull requests
workflow_dispatch:
inputs:
git-ref:
description: Git Ref
default: master
required: true
push:
branches:
- '**'
# schedule:
# - cron: "0 3 * * *"

jobs:
Tests_and_docs:
strategy:
fail-fast: false
matrix:
# NOTE: checking also master to make sure risk workshop demos keep working also on master
# TODO: it would be better to point to lts and latest if possible
# ENGINE_BR: ['engine-3.16', 'engine-3.18', 'master']
ENGINE_BR: [master']
# NOTE: keep it updated with QGIS ltr
# QGIS_DOCKER_VERSION: ['qgis/qgis:release-3_28', 'qgis/qgis:latest']
# QGIS_INSTALLER: ['QGIS-OSGeo4W-3.28.14-1.msi', 'QGIS-OSGeo4W-3.34.3-1.msi']
QGIS_INSTALLER: ['QGIS-OSGeo4W-3.28.14-1.msi']
# DEMOS: ['oqdata', 'risk-oqdata']
DEMOS: ['risk-oqdata']
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: 🐍 Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
ref: ${{ matrix.ENGINE_BR }}
- name: Install QGIS
run: |
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile("https://qgis.org/downloads/${{matrix.QGIS_INSTALLER}}", ".\${{matrix.QGIS_INSTALLER}}")
Start-Process -FilePath ".\${{matrix.QGIS_INSTALLER}}" -ArgumentList "/quiet /passive" -Wait
# FIXME: make it parametric
& 'C:\Program Files\QGIS 3.28.14\bin\qgis-ltr-bin.exe' --version | echo
- name: ⏳ Clone engine and restore oqdata
run: |
set -x
ENGINE_BR=${{ matrix.ENGINE_BR }}
IRMT_BR=$ENGINE_BR
git fetch
git checkout $IRMT_BR
cp -r svir\ .\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\
curl -O https://raw.githubusercontent.com/gem/oq-engine/master/install.py
ls -lrt install.py
echo "Using branch ${ENGINE_BR}"
# if [ "$(git ls-remote --heads https://github.com/gem/oq-engine.git ${ENGINE_BR})" = "" ]; then
# echo "Branch ${ENGINE_BR} not found in gem/oq-engine repository"
# exit 1
# fi
# get release version from branch name (e.g. 'engine-3.16' -> '3.16')
# prefix="engine-"
# if [[ $ENGINE_BR == ${prefix}* ]]; then
# RELEASE_VERSION="${ENGINE_BR#${prefix}}"
# else
# RELEASE_VERSION=$ENGINE_BR
# fi

# FIXME: use actual RELEASE_VERSION
RELEASE_VERSION=master
python3 install.py user --version=${RELEASE_VERSION}
export PIP_DEFAULT_TIMEOUT=100
echo "Restore ${{matrix.DEMOS}} demos for $ENGINE_BR branch "
$home\openquake\Scripts\activate.ps1
oq reset -y
oq restore https://artifacts.openquake.org/travis/${{matrix.DEMOS}}-${ENGINE_BR}.zip ~/oqdata
oq webui start --skip-browser >> webui.log 2>&1 &
# echo "Waiting WEBUI up on port 8800...."
# while ! nc -z 172.17.0.1 8800; do
# 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`
# # NOTE: release-3_28 needs to be kept updated to the current LTS
# docker run -d --name qgis -v /tmp/.X11-unix:/tmp/.X11-unix -v `pwd`:/tests_directory -e DISPLAY=:99 -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 }}
# docker exec qgis bash -c "apt update --allow-releaseinfo-change; DEBIAN_FRONTEND=noninteractive apt install -y python3-scipy python3-matplotlib python3-pyqt5.qtwebkit"
# docker exec qgis bash -c "python3 -m pip install pytest"
# # OGR_SQLITE_JOURNAL=delete prevents QGIS from using WAL, which modifies geopackages even if they are just read
- name: ℧ Run unit test
run: |
set -x
pip install pytest
$OSGEO4W_ROOT = "C:\Program Files\QGIS 3.28.14\"
$QGISNAME = "qgis-ltr"
$QGIS = "$OSGEO4W_ROOT\apps\$QGISNAME"
$QGIS_PREFIX_PATH = $QGIS
& "$OSGEO4W_ROOT\bin\o4w_env.bat"
$PATH += ";$QGIS\bin"
$PYTHONPATH += ";$QGIS\python"
$LD_LIBRARY_PATH="$QGIS_PREFIX_PATH\lib"
pytest -v .\svir\test\unit\
$OGR_SQLITE_JOURNAL=delete
& 'C:\Program Files\QGIS 3.28.14\bin\qgis-ltr-bin.exe' --nologo --code scripts\run_unit_tests.py
pytest -v svir/test/unit/
# ENGINE_BR=${{ matrix.ENGINE_BR }}
# IRMT_BR=$ENGINE_BR
# git fetch
# git checkout $IRMT_BR
# docker exec -t qgis bash -c "export PYTHONPATH=/usr/share/qgis/python/plugins/:$PYTHONPATH; OGR_SQLITE_JOURNAL=delete pytest -v /tests_directory/svir/test/unit/"
- name: ⨕ Run Integration test
run: |
set -x
ENGINE_BR=${{ matrix.ENGINE_BR }}
IRMT_BR=$ENGINE_BR
git fetch
git checkout $IRMT_BR
# get release version from branch name (e.g. 'engine-3.16' -> '3.16')
prefix="engine-"
if [[ $ENGINE_BR == ${prefix}* ]]; then
RELEASE_VERSION="${ENGINE_BR#${prefix}}"
else
RELEASE_VERSION=$ENGINE_BR
fi
# NOTE: if we want to enable it, we need to use the proper folder after engine user installation
OQ_TEST_RUN_CALC=0
if [ "${{ matrix.DEMOS }}" != "risk-oqdata" -a "${RELEASE_VERSION}" != "3.16" ]; then
OQ_CHECK_MISSING_OUTPUTS=1
else
OQ_CHECK_MISSING_OUTPUTS=0
fi
echo "OQ_CHECK_MISSING_OUTPUTS: ${OQ_CHECK_MISSING_OUTPUTS}"
echo "OQ_TEST_RUN_CALC: ${OQ_TEST_RUN_CALC}"
# # NOTE: the check on the existence of the engine branch is already done in the previous step
# docker exec qgis sh -c "echo 'Running against oq-engine on branch ${ENGINE_BR}'"
# docker exec qgis sh -c "qgis_setup.sh svir"
# docker exec -e OQ_CHECK_MISSING_OUTPUTS=${OQ_CHECK_MISSING_OUTPUTS} -e OQ_TEST_RUN_CALC=${OQ_TEST_RUN_CALC} \
# -t qgis sh -c "env && cd /tests_directory && qgis_testrunner.sh svir.test.integration.test_drive_oq_engine"
- name: ㏒ Save webui log as artifact
uses: actions/upload-artifact@v2
if: always()
with:
name: WebUI-log
path: webui.log
34 changes: 34 additions & 0 deletions scripts/run_unit_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import subprocess
import os
import pip
from qgis.core import QgsMessageLog, Qgis

def install_packages():
for package_name in ['pytest', 'matplotlib', 'scipy', 'pyqt5', 'pytest-qgis']:
subprocess.run(['pip', 'install', package_name], check=True)
# subprocess.run(['pip', 'uninstall', '-y', 'pdbpp'], check=True)
# for package_name in ['pytest', 'matplotlib', 'scipy', 'pyqt5']:
# subprocess.run(['pip', 'install', '-y', package_name], check=True)
# # pip.main('install', '-y', package_name], check=True)
# try:
# pytest_args = ['pytest', '-v', os.path.join('svir', 'test', 'unit')]
# subprocess.run(pytest_args, check=True)
# except subprocess.CalledProcessError as e:
# print(f"Pytest failed with return code {e.returncode}.")
# print(e.output.decode())
# else:
# print("Pytest completed successfully.")
#pip.main(['pytest', 'pyqt5', 'matplotlib', 'scipy'])

def run_pytest():
# pytest_args = ['pytest', '-v', os.path.join('svir', 'test', 'unit')]
pytest_args = ['pytest', '-v', os.path.join('C:', 'Users', 'paolo.tormene', 'GIT', 'oq-irmt-qgis', 'svir', 'test', 'unit')]
sp = subprocess.run(pytest_args, check=False, shell=True, capture_output=True, text=True)
sp2 = subprocess.run(['echo', '%cd%'], check=False, shell=True, capture_output=True, text=True)
QgsMessageLog.logMessage("Unit tests completed: %s" % sp, level=Qgis.Info)
QgsMessageLog.logMessage("Unit tests completed: %s" % sp2, level=Qgis.Info)

if __name__ == "__main__":
install_packages()
run_pytest()
# pip.main(['install', 'pytest']) #, 'pyqt5', 'matplotlib', 'scipy'])
2 changes: 2 additions & 0 deletions svir/test/unit/test_calculate_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def setUp(self):
self.layer = ProcessLayer(orig_layer).duplicate_in_memory()

def test_custom_operator(self):
# FIXME
1/0
proj_def = deepcopy(self.project_definition)
operator = OPERATORS_DICT['CUSTOM']
# set economy's operator to custom and use a custom formula
Expand Down
Loading