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

Fix pytest segmentation fault #154

Merged
merged 9 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions .github/workflows/python-app-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,14 @@ jobs:
export PYTHONPATH="/usr/lib/python3/dist-packages":PYTHONPATH && echo "import qgis" | python3
export PYTHONPATH="$PYTHONPATH:$(pwd)/src"
export PYTHONPATH="$PYTHONPATH:$(pwd)"
# apparently there is some issue with opencv-python-headless, we need to reinstall it

# apparently there is some issue with opencv-python-headless, we need to reinstall it
pip uninstall opencv-python-headless --yes

pip install --upgrade -r ./src/deepness/python_requirements/requirements.txt
# run one this without pytest, because pytest creates obfuscated error messages

# we need 'xvfb-run' to simulate UI - otherwise qgis crushes
xvfb-run python3 test/test_map_processor_segmentation.py

# run the actual tests
xvfb-run python3 -m pytest --cov=src/deepness/ --cov-report html test/
xvfb-run -e /dev/stdout python3 -m pytest --cov=src/deepness/ --cov-report html test/
- name: 'Upload Artifact - test coverage'
uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions test/test_map_processor_detection_oils_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_map_processor_detection_oil_example():

map_processor.run()


def test_map_processor_detection_oil_example_using_cache():
qgs = init_qgis()
rlayer = create_rlayer_from_file(RASTER_FILE_PATH)
Expand Down Expand Up @@ -85,6 +86,7 @@ def test_map_processor_detection_oil_example_using_cache():

map_processor.run()


def test_map_processor_detection_oil_example_with_remove_small():
qgs = init_qgis()
rlayer = create_rlayer_from_file(RASTER_FILE_PATH)
Expand Down
24 changes: 22 additions & 2 deletions test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Optional

from qgis.core import (QgsApplication, QgsCoordinateReferenceSystem, QgsProject, QgsRasterLayer, QgsRectangle,
QgsVectorLayer)
Expand All @@ -17,53 +18,61 @@ def get_dummy_segmentation_model_path():
"""
return os.path.join(TEST_DATA_DIR, 'dummy_model', 'dummy_segmentation_model.onnx')


def get_dummy_segmentation_model_different_output_size_path():
"""
Get path of a dummy onnx model. See details in README in model directory.
Model used for unit tests processing purposes. Its output size is different than input size.
"""
return os.path.join(TEST_DATA_DIR, 'dummy_model', 'dummy_segmentation_model_different_output_size.onnx')


def get_dummy_recognition_model_path():
"""
Get path of a dummy onnx model. See details in README in model directory.
Model used for unit tests processing purposes
"""
return os.path.join(TEST_DATA_DIR, 'dummy_model', 'dummy_recognition_model.onnx')


def get_dummy_recognition_image_path():
"""
Get path of a dummy image, which can be used for testing with conjunction with dummy_mode (see get_dummy_model_path)
"""
return os.path.join(TEST_DATA_DIR, 'dummy_recognition_image.png')


def get_dummy_recognition_map_path():
"""
Get path of a dummy map, which can be used for testing with conjunction with dummy_mode (see get_dummy_model_path)
"""
return os.path.join(TEST_DATA_DIR, 'dummy_recognition_map.tif')


def get_dummy_regression_model_path():
"""
Get path of a dummy onnx model. See details in README in model directory.
Model used for unit tests processing purposes
"""
return os.path.join(TEST_DATA_DIR, 'dummy_model', 'dummy_regression_model.onnx')


def get_dummy_regression_model_path_batched():
"""
Get path of a dummy onnx model. See details in README in model directory.
Model used for unit tests processing purposes
"""
return os.path.join(TEST_DATA_DIR, 'dummy_model', 'dummy_regression_model_batched.onnx')


def get_dummy_superresolution_model_path():
"""
Get path of a dummy onnx model. See details in README in model directory.
Model used for unit tests processing purposes
"""
return os.path.join(TEST_DATA_DIR, 'dummy_model', 'dummy_superresolution_model.onnx')


def get_dummy_fotomap_small_path():
"""
Get path of dummy fotomap tif file, which can be used
Expand Down Expand Up @@ -189,8 +198,19 @@ def get_first_arg(self):
raise Exception("No argument were provided for the signal!")


_APP_INSTANCE: Optional[QgsApplication] = None


def init_qgis():
qgs = QgsApplication([b''], False)
print("Initializing QGIS")
global _APP_INSTANCE
if _APP_INSTANCE:
print("QGIS already initialized")
return _APP_INSTANCE

print("QGIS not initialized yet")
qgs = QgsApplication([b''], GUIenabled=False)
qgs.setPrefixPath('/usr/bin/qgis', True)
qgs.initQgis()
return qgs
_APP_INSTANCE = qgs
return _APP_INSTANCE
Loading