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

Introduce Testing #233

Merged
merged 22 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

name: Testing

on:
pull_request:

jobs:
test_3_16:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run test 3.16
run: |
docker run -v ${GITHUB_WORKSPACE}:/src -w /src qgis/qgis:release-3_16 sh -c 'apt-get -y update && apt-get -y install xvfb && export ORS_API_KEY=${{ secrets.ORS_API_KEY }} && export DISPLAY=:0.0 && pip install -U pytest && xvfb-run pytest'
env:
DOCKER_IMAGE: ${{ steps.docker-build.outputs.FULL_IMAGE_NAME }}
test_3_22:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run test 3.22
run: |
docker run -v ${GITHUB_WORKSPACE}:/src -w /src qgis/qgis:release-3_22 sh -c 'apt-get -y update && apt-get -y install xvfb && export DISPLAY=:0.0 && export ORS_API_KEY=${{ secrets.ORS_API_KEY }} && export DISPLAY=:0.0 && pip install -U pytest && xvfb-run pytest'
env:
DOCKER_IMAGE: ${{ steps.docker-build.outputs.FULL_IMAGE_NAME }}
test_latest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run test latest
run: |
docker run -v ${GITHUB_WORKSPACE}:/src -w /src qgis/qgis:latest sh -c 'apt-get -y update && apt-get -y install xvfb && export DISPLAY=:0.0 && export ORS_API_KEY=${{ secrets.ORS_API_KEY }} && pip install -U pytest && xvfb-run pytest'
env:
DOCKER_IMAGE: ${{ steps.docker-build.outputs.FULL_IMAGE_NAME }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ RELEASING:
-->


# Unreleased
### Added
- Unit- and e2e-testing

## [1.7.1] - 2024-01-15

### Added
Expand Down
1 change: 1 addition & 0 deletions ORStools/proc/base_processing_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* *
***************************************************************************/
"""

from PyQt5.QtCore import QCoreApplication, QSettings
from qgis.core import (
QgsProcessing,
Expand Down
1 change: 1 addition & 0 deletions ORStools/utils/configmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* *
***************************************************************************/
"""

import os

import yaml
Expand Down
1 change: 1 addition & 0 deletions ORStools/utils/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* *
***************************************************************************/
"""

import os
from qgis.core import QgsPointXY

Expand Down
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ORS Tools QGIS plugin

![Testing](https://github.com/Merydian/orstools-qgis-plugin/actions/workflows/test.yml/badge.svg)
![Ruff](https://github.com/Merydian/orstools-qgis-plugin/actions/workflows/ruff.yml/badge.svg)

![ORS Tools](https://user-images.githubusercontent.com/23240110/122937401-3ee72400-d372-11eb-8e3b-6c435d1dd964.png)

Set of tools for QGIS to use the [openrouteservice](https://openrouteservice.org) (ORS) API.
Expand Down Expand Up @@ -120,6 +123,49 @@ where `<qgis_plugins_path>` is one of:
- Windows: `C:\Users\USER\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ORStools`
- Mac OS: `Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/ORStools`

### CI
#### Testing
The repository tests on the QGis Versions *3.16*, *3.22* and the *latest* version.
Until now, it's only possible to test one version at a time.

To do local test runs you can use a [conda installation](https://github.com/opengisch/qgis-conda-builder) of the QGis version you want to test.
You will also have to install *xvfb* to run the tests on involving an interface.
Lastly, we need [*Pytest*](https://docs.pytest.org/en/8.0.x/) to run tests in general.

To do the above run use these commands:
1. Install a version of anaconda, preferrably [*miniforge*](https://github.com/conda-forge/miniforge).

2. Create and prepare the environment.
```shell
# create environment
mamba create --name qgis_test
# activate envotonment
conda activate qgis_test
# install pip
mamba install qgis pip
```
3. Install QGis using mamba.
```shell
mamba install -c conda-forge qgis=[3.16, 3.22, latest] # choose one
```
koebi marked this conversation as resolved.
Show resolved Hide resolved

4. Install *xvfb*
```shell
sudo apt-get update
sudo apt install xvfb
```
merydian marked this conversation as resolved.
Show resolved Hide resolved

5. Install *Pytest* using pip in testing environment.
```shell
pip install -U pytest
```
merydian marked this conversation as resolved.
Show resolved Hide resolved

To run the tests you will need an ORS-API key:
```shell
cd orstools-qgis-plugin
export ORS_API_KEY=[Your API key here] && xvfb-run pytest
```

### Debugging
In the **PyCharm community edition** you will have to use logging and printing to inspect elements.
The First Aid QGIS plugin can probably also be used additionally.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
merydian marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ruff
pytest
Empty file added tests/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
import yaml
merydian marked this conversation as resolved.
Show resolved Hide resolved

from ORStools.utils.configmanager import read_config

with open("ORStools/config.yml", "r+") as file:
data = yaml.safe_load(file)
merydian marked this conversation as resolved.
Show resolved Hide resolved


def pytest_sessionstart(session):
"""
Called after the Session object has been created and
before performing collection and entering the run test loop.
"""
if data["providers"][0]["key"] == "":
data["providers"][0]["key"] = os.environ.get("ORS_API_KEY")
with open("ORStools/config.yml", "w") as file:
yaml.dump(data, file)
else:
raise ValueError("API key is not empty.")


def pytest_sessionfinish(session, exitstatus):
"""
Called after whole test run finished, right before
returning the exit status to the system.
"""
with open("ORStools/config.yml", "w") as file:
if not data["providers"][0]["key"] == "":
data['providers'][0]['key'] = '' # fmt: skip
yaml.dump(data, file)

config = read_config()
assert config["providers"][0]["key"] == '' # fmt: skip
Loading
Loading