Skip to content

Commit

Permalink
Set env variables, run qgis from command line to install required pyt…
Browse files Browse the repository at this point in the history
…hon packages
  • Loading branch information
ptormene committed Feb 14, 2024
1 parent ac9943f commit b85b5aa
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
26 changes: 21 additions & 5 deletions .github/workflows/test_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
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}"
Expand All @@ -64,11 +65,13 @@ jobs:
# 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 "
source $HOME/openquake/bin/activate
$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 &
Expand All @@ -89,10 +92,23 @@ jobs:
- name: ℧ Run unit test
run: |
set -x
ENGINE_BR=${{ matrix.ENGINE_BR }}
IRMT_BR=$ENGINE_BR
git fetch
git checkout $IRMT_BR
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: |
Expand Down
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

0 comments on commit b85b5aa

Please sign in to comment.