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

Adding ci test #12

Merged
merged 20 commits into from
Aug 21, 2024
32 changes: 32 additions & 0 deletions .github/workflows/test_plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
schedule:
# runs once a week
# - cron: '0 6 * * 0'
# runs every day
- cron: '0 12 * * *'
axelande marked this conversation as resolved.
Show resolved Hide resolved
push:
branches: [ "main"]
pull_request:
branches: [ "master" ]
axelande marked this conversation as resolved.
Show resolved Hide resolved

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Pull qgis image
run: docker pull qgis/qgis:stable

- name: Run tests
run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python3 -m pip install pytest-qgis --break-system-packages && xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s"
axelande marked this conversation as resolved.
Show resolved Hide resolved

17 changes: 12 additions & 5 deletions a00_qpip/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
class Plugin:
"""QGIS Plugin Implementation."""

def __init__(self, iface):
def __init__(self, iface, test_path=None):
axelande marked this conversation as resolved.
Show resolved Hide resolved
self.iface = iface
self._defered_packages = []
self.settings = QgsSettings()
self.settings.beginGroup("QPIP")

self.plugins_path = os.path.join(
QgsApplication.qgisSettingsDirPath(), "python", "plugins"
)

if test_path is None:
self.plugins_path = os.path.join(
QgsApplication.qgisSettingsDirPath(), "python", "plugins"
)
self.test_mode = False
else:
self.plugins_path = test_path
self.test_mode = True
self.prefix_path = os.path.join(
QgsApplication.qgisSettingsDirPath().replace("/", os.path.sep),
"python",
Expand Down Expand Up @@ -170,6 +175,8 @@ def check_deps_and_prompt_install(self, additional_plugins=[], force_gui=False):
dialog = MainDialog(
libs.values(), self._check_on_startup(), self._check_on_install()
)
if self.test_mode:
return dialog.reqs_to_install
axelande marked this conversation as resolved.
Show resolved Hide resolved
if dialog.exec_():
reqs_to_uninstall = dialog.reqs_to_uninstall
if reqs_to_uninstall:
Expand Down
6 changes: 5 additions & 1 deletion a00_qpip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ def run_cmd(args, description="running a system command"):
f"Encountered an error while {description} !",
parent=iface.mainWindow(),
)
message.setDetailedText(full_output)
if "no module named pip" in full_output.lower():
axelande marked this conversation as resolved.
Show resolved Hide resolved
msg = """It looks like that the python installation of qgis is missing pip, please install this separately first."""
message.setDetailedText(msg)
else:
message.setDetailedText(full_output)
message.exec_()
else:
log("Command succeeded.")
Expand Down
38 changes: 38 additions & 0 deletions tests/test_finding_req.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os

import pytest
from pytest_qgis import qgis_iface

from PyQt5.QtCore import QSettings, QDate

from a00_qpip.plugin import Plugin

class initializationCompleted:
def connect(self):
pass

def popWidget():
return True

THIS_DIR = os.path.dirname(__file__)

@pytest.fixture()
def plugin(qgis_iface):
qgis_iface.initializationCompleted = initializationCompleted
qgis_iface.messageBar().popWidget = popWidget
plugin = Plugin(qgis_iface, '.')
yield plugin


def test_plugin_a(plugin: Plugin):
plugin_a = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_a')
libs = plugin.check_deps_and_prompt_install([plugin_a])
assert len(libs) == 2
assert libs[0] == 'cowsay==4.0'


def test_plugin_b(plugin: Plugin):
plugin_b = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_b')
libs = plugin.check_deps_and_prompt_install([plugin_b])
assert len(libs) == 2
assert libs[0] == 'cowsay==5.0'