Skip to content

Commit

Permalink
Use pytest-qgis
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Jul 3, 2024
1 parent e97f46c commit 9a7e99e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ jobs:
environment-name: jupytergis
create-args: python=${{ matrix.python-version }}

- name: Install test packages
run: pip install pytest pytest-qgis dirty-equals

- name: Run tests
run: pytest --color=yes -v python/jupytergis_core/tests
2 changes: 0 additions & 2 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ channels:
dependencies:
- pip
- qgis
- pytest
- dirty-equals
4 changes: 2 additions & 2 deletions python/jupytergis_core/tests/test_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
FILES = Path(__file__).parent / "files"


def test_qgis():
jgis_layer_tree = import_project_from_qgis(FILES / "project0.qgs")
def test_qgis(qgis_app, qgis_new_project,):
jgis_layer_tree = import_project_from_qgis(FILES / "project0.qgs", qgis_app)
source_id0 = IsStr()
source_id1 = IsStr()
source_id2 = IsStr()
Expand Down
9 changes: 1 addition & 8 deletions python/jupytergis_core/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import shutil
from pathlib import Path
from urllib.parse import unquote
from uuid import uuid4
Expand Down Expand Up @@ -84,20 +83,14 @@ def qgis_to_jgis(
}


def import_project_from_qgis(path: str | Path):
def import_project_from_qgis(path: str | Path, qgis_app: QgsQpplication):
if isinstance(path, Path):
path = str(path)

QgsApplication.setPrefixPath(shutil.which("qgis"), True)
qgs = QgsApplication([], False)
qgs.initQgis()

project = QgsProject.instance()
project.read(path)
layer_tree_root = project.layerTreeRoot()

jgis_layer_tree = qgis_to_jgis(layer_tree_root)

qgs.exitQgis()

return jgis_layer_tree

0 comments on commit 9a7e99e

Please sign in to comment.