-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from MIERUNE/testing
migrate to unittest
- Loading branch information
Showing
16 changed files
with
550 additions
and
427 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,47 @@ | ||
name: Test | ||
name: Test plugin | ||
|
||
on: | ||
pull_request: | ||
branches: [main] | ||
workflow_dispatch: | ||
branches: | ||
- main | ||
|
||
env: | ||
# plugin name/directory where the code for the plugin is stored | ||
PLUGIN_NAME: gtfsgo | ||
# python notation to test running inside plugin | ||
TESTS_RUN_FUNCTION: gtfsgo.test_suite.test_package | ||
# Docker settings | ||
DOCKER_IMAGE: qgis/qgis | ||
|
||
jobs: | ||
Test: | ||
Test-plugin-gtfsgo: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
qgis_image_tag: [release-3_28] | ||
env: | ||
OS: ubuntu | ||
QGIS_IMAGE_TAG: ${{ matrix.qgis_image_tag }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
docker_tags: [release-3_28, release-3_34] | ||
|
||
- name: Pull QGIS | ||
run: docker pull qgis/qgis:${{ matrix.qgis_image_tag }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Export requirements.txt | ||
run: | | ||
pip3 install poetry | ||
poetry export --with dev -f requirements.txt -o requirements.txt | ||
- name: Run tests | ||
run: docker run --rm --net=host --volume .:/app -w=/app -e QGIS_PLUGIN_IN_CI=1 qgis/qgis:${{ matrix.qgis_image_tag }} sh -c "pip3 install -r /app/requirements.txt && xvfb-run -s '+extension GLX -screen 0 1024x768x24' pytest -v --cov --cov-report=xml --cov-report=term" | ||
- name: Docker pull and create qgis-testing-environment | ||
run: | | ||
docker pull "$DOCKER_IMAGE":${{ matrix.docker_tags }} | ||
docker run -d --name qgis-testing-environment -v .:/tests_directory/gtfsgo -e DISPLAY=:99 "$DOCKER_IMAGE":${{ matrix.docker_tags }} | ||
- name: Docker set up QGIS | ||
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/$PLUGIN_NAME/requirements.txt" | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
slug: MIERUNE/GTFS-GO | ||
- name: Docker run plugin tests | ||
run: | | ||
docker exec qgis-testing-environment sh -c "qgis_testrunner.sh $TESTS_RUN_FUNCTION" |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
""" | ||
Test Suite. | ||
""" | ||
|
||
import os | ||
import sys | ||
import tempfile | ||
import unittest | ||
|
||
from osgeo import gdal | ||
from qgis.core import Qgis | ||
|
||
try: | ||
from pip import main as pipmain | ||
except ImportError: | ||
from pip._internal import main as pipmain | ||
|
||
try: | ||
import coverage | ||
except ImportError: | ||
pipmain(["install", "coverage"]) | ||
import coverage | ||
|
||
__author__ = "Alessandro Pasotti" | ||
__revision__ = "$Format:%H$" | ||
__date__ = "30/04/2018" | ||
__copyright__ = "Copyright 2018, North Road" | ||
|
||
|
||
def _run_tests(test_suite, package_name, with_coverage=False): | ||
"""Core function to test a test suite.""" | ||
count = test_suite.countTestCases() | ||
print("########") | ||
print("%s tests has been discovered in %s" % (count, package_name)) | ||
print("Python GDAL : %s" % gdal.VersionInfo("VERSION_NUM")) | ||
print("QGIS version : {}".format(Qgis.version())) | ||
print("########") | ||
if with_coverage: | ||
cov = coverage.Coverage( | ||
source=["/processing_r"], | ||
omit=["*/test/*"], | ||
) | ||
cov.start() | ||
|
||
unittest.TextTestRunner(verbosity=3, stream=sys.stdout).run(test_suite) | ||
|
||
if with_coverage: | ||
cov.stop() | ||
cov.save() | ||
|
||
with tempfile.NamedTemporaryFile(delete=False) as report: | ||
cov.report(file=report) | ||
# Produce HTML reports in the `htmlcov` folder and open index.html | ||
# cov.html_report() | ||
report.close() | ||
|
||
with open(report.name, "r", encoding="utf8") as fin: | ||
print(fin.read()) | ||
|
||
|
||
def test_package(package="gtfsgo"): | ||
"""Test package. | ||
This function is called by travis without arguments. | ||
:param package: The package to test. | ||
:type package: str | ||
""" | ||
test_loader = unittest.defaultTestLoader | ||
try: | ||
test_suite = test_loader.discover(package) | ||
except ImportError: | ||
test_suite = unittest.TestSuite() | ||
_run_tests(test_suite, package) | ||
|
||
|
||
def test_environment(): | ||
"""Test package with an environment variable.""" | ||
package = os.environ.get("TESTING_PACKAGE", "gtfsgo") | ||
test_loader = unittest.defaultTestLoader | ||
test_suite = test_loader.discover(package) | ||
_run_tests(test_suite, package) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_package() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.