Skip to content

Commit

Permalink
Tests refactor pytest (#129)
Browse files Browse the repository at this point in the history
* refactors tests
* add some test cases
* change test infrastructure
* add algorithm runs to test
  • Loading branch information
JanCaha authored Dec 4, 2023
1 parent ca9ac59 commit 83a8169
Show file tree
Hide file tree
Showing 74 changed files with 2,671 additions and 3,066 deletions.
35 changes: 23 additions & 12 deletions .github/workflows/test_plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ env:
TESTS_RUN_FUNCTION: processing_r.test_suite.test_package
# Docker settings
DOCKER_IMAGE: qgis/qgis
PYTHON_SETUP: "PYTHONPATH=/usr/share/qgis/python/:/usr/share/qgis/python/plugins:/usr/lib/python3/dist-packages/qgis:/usr/share/qgis/python/qgis:/tests_directory"


jobs:
Expand All @@ -25,28 +26,38 @@ jobs:

strategy:
matrix:
docker_tags: [release-3_28, release-3_30, release-3_34, latest]
docker_tags: [release-3_28, release-3_30, release-3_32, release-3_34, latest]

steps:

- name: Checkout
uses: actions/checkout@v4

- name: Docker pull and create qgis-testing-environment
- name: Docker pull and create qgis-test-env
run: |
docker pull "$DOCKER_IMAGE":${{ matrix.docker_tags }}
docker run -d --name qgis-testing-environment -v "$GITHUB_WORKSPACE":/tests_directory -e DISPLAY=:99 "$DOCKER_IMAGE":${{ matrix.docker_tags }}
docker run -d --name qgis-test-env -v "$GITHUB_WORKSPACE":/tests_directory -e DISPLAY=:99 "$DOCKER_IMAGE":${{ matrix.docker_tags }}
- name: Docker set up QGIS
- name: Docker set up
run: |
docker exec qgis-testing-environment sh -c "qgis_setup.sh $PLUGIN_NAME"
docker exec qgis-testing-environment sh -c "rm -f /root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/$PLUGIN_NAME"
docker exec qgis-testing-environment sh -c "ln -s /tests_directory/$PLUGIN_NAME /root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/$PLUGIN_NAME"
docker exec qgis-testing-environment sh -c "pip3 install -r /tests_directory/REQUIREMENTS_TESTING.txt"
docker exec qgis-testing-environment sh -c "apt-get update"
docker exec qgis-testing-environment sh -c "apt-get install -y r-base"
docker exec qgis-test-env sh -c "pip3 install -r /tests_directory/REQUIREMENTS_TESTING.txt"
docker exec qgis-test-env sh -c "apt-get update"
docker exec qgis-test-env sh -c "apt-get install -y --no-install-recommends wget ca-certificates gnupg"
- name: Add Keys and Sources for R and binary packages
run: |
docker exec qgis-test-env sh -c "wget -q -O- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc"
docker exec qgis-test-env sh -c "echo \"deb [arch=amd64] https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/\" > /etc/apt/sources.list.d/cran_r.list"
docker exec qgis-test-env sh -c "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 67C2D66C4B1D4339 51716619E084DAB9"
docker exec qgis-test-env sh -c "wget -q -O- https://eddelbuettel.github.io/r2u/assets/dirk_eddelbuettel_key.asc | tee -a /etc/apt/trusted.gpg.d/cranapt_key.asc"
docker exec qgis-test-env sh -c "echo \"deb [arch=amd64] https://r2u.stat.illinois.edu/ubuntu jammy main\" > /etc/apt/sources.list.d/cranapt.list"
- name: Install R and necessary packages
run: |
docker exec qgis-test-env sh -c "apt update -qq"
docker exec qgis-test-env sh -c "apt-get install -y r-base r-cran-sf r-cran-raster"
- name: Docker run plugin tests
run: |
docker exec qgis-testing-environment sh -c "qgis_testrunner.sh $TESTS_RUN_FUNCTION"
docker exec qgis-test-env sh -c "$PYTHON_SETUP && cd tests_directory && pytest"
3 changes: 3 additions & 0 deletions REQUIREMENTS_TESTING.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ deepdiff
mock
flake8
pep257
pytest
pytest-cov
pytest-qgis
8 changes: 3 additions & 5 deletions processing_r/processing/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@
from processing_r.processing.actions.edit_script import EditScriptAction
from processing_r.processing.algorithm import RAlgorithm
from processing_r.processing.exceptions import InvalidScriptException
from processing_r.processing.utils import RUtils
from processing_r.processing.utils import RUtils, plugin_version


class RAlgorithmProvider(QgsProcessingProvider):
"""
Processing provider for executing R scripts
"""

VERSION = "3.0.0"

def __init__(self):
super().__init__()
self.algs = []
Expand Down Expand Up @@ -141,9 +139,9 @@ def versionInfo(self):
Provider plugin version
"""
if not self.r_version:
return "QGIS R Provider version {}".format(self.VERSION)
return "QGIS R Provider version {}".format(plugin_version())

return "QGIS R Provider version {}, {}".format(self.VERSION, self.r_version)
return "QGIS R Provider version {}, {}".format(plugin_version(), self.r_version)

def id(self):
"""
Expand Down
22 changes: 22 additions & 0 deletions processing_r/processing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* *
***************************************************************************
"""
import configparser
import os
import pathlib
import platform
import re
import subprocess
Expand Down Expand Up @@ -419,3 +421,23 @@ def log(message: str) -> None:
Simple logging function, most for debuging.
"""
QgsMessageLog.logMessage(message, "Processing R Plugin", Qgis.Info)


def _read_metadata() -> configparser.ConfigParser:
"""
Read metadata file.
"""
path = pathlib.Path(__file__).parent / "metadata.txt"

config = configparser.ConfigParser()
config.read(path)

return config


def plugin_version() -> str:
"""
Get plugin version.
"""
config = _read_metadata()
return config["general"]["version"]
2 changes: 0 additions & 2 deletions processing_r/r_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

from processing_r.processing.provider import RAlgorithmProvider

VERSION = "3.1.0"


class RProviderPlugin:
"""QGIS Plugin Implementation."""
Expand Down
4 changes: 0 additions & 4 deletions processing_r/test/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions processing_r/test/data/test_input_point.rsx

This file was deleted.

1 change: 0 additions & 1 deletion processing_r/test/data/test_rasterin.rsx

This file was deleted.

227 changes: 0 additions & 227 deletions processing_r/test/qgis_interface.py

This file was deleted.

19 changes: 0 additions & 19 deletions processing_r/test/tenbytenraster.asc

This file was deleted.

Loading

0 comments on commit 83a8169

Please sign in to comment.