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

Tests refacto #259

Merged
merged 75 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
068ed70
Replace nose2 by pytest
Guts May 8, 2022
2b22407
Rm nose2 refs
Guts May 8, 2022
d717419
Rename test folder into tests
Guts May 8, 2022
04589c7
Add pytest config for IDE
Guts May 8, 2022
ad22408
Aplly new tests path
Guts May 8, 2022
f4d447a
Rm test launcher
Guts May 8, 2022
c533c63
Ignore junit report
Guts May 8, 2022
3715f1e
Reorganize tests related to qgis
Guts May 8, 2022
4d92551
Move dependencies related to test into a dedicated file
Guts May 8, 2022
29f173e
Add how to run tests
Guts May 8, 2022
71d8bf0
Add a dockerfile that can be used to run tests
Guts May 8, 2022
70c60a7
Fix repo name. Must be lowercase
Guts May 8, 2022
e9040ef
Add minimal unit test
Guts May 8, 2022
16596f1
Add GA aworkflow to run tests
Guts May 8, 2022
125d230
Fix deps path
Guts May 8, 2022
1521b9e
Improve omit
Guts May 8, 2022
76e4283
Rm qgis import a tests level
Guts May 8, 2022
14fe89d
Travis config
Guts May 8, 2022
f7d53fb
Rù qgis import
Guts May 8, 2022
6206dd8
Move metadata check to unit
Guts May 8, 2022
3ff0037
Specify PYTHONPATH to the container
Guts May 8, 2022
6857e01
Use qgis_setup script
Guts May 8, 2022
b1eccf7
Use latest version of checkout
Guts May 8, 2022
20cd2b0
Add codecov config
Guts May 8, 2022
e603161
Merge branch 'master' into tests/nose2-to-pytest
Guts May 8, 2022
9f13a96
Coment out setup script
Guts May 8, 2022
3dc2faf
Merge branch 'tests/nose2-to-pytest' of github.com:QGIS-Contribution/…
Guts May 8, 2022
5187532
Add dockerignore
Guts May 8, 2022
94575e0
Fix tests utilities import
Guts May 9, 2022
965ca61
Use more env vars
Guts May 9, 2022
c8d8348
Try other env
Guts May 9, 2022
9ec5245
Set display to 1
Guts May 9, 2022
5a41295
Merge branch 'master' into tests/nose2-to-pytest
Guts Jul 23, 2022
8224d3f
Fix reserved keyword
Guts Jul 23, 2022
1147f45
Move test data to fixtures subfolder
Guts Jul 23, 2022
14dd293
Improve docstring (type hints)
Guts Jul 23, 2022
e09c24a
Apply alphabetical order to parsed metadata
Guts Jul 23, 2022
7b8c62e
Create a base class for unit tests improving utils
Guts Jul 23, 2022
2d6c77c
Split test of base handler
Guts Jul 23, 2022
153efbc
clean up
Guts Jul 23, 2022
3145e87
Rm base test handler
Guts Jul 23, 2022
ad9f0aa
Move test of local file system handler
Guts Jul 23, 2022
e75e4ee
clean up
Guts Jul 23, 2022
d4826f9
Fix handler for Git OSGeo platform (gitea)
Guts Jul 24, 2022
7d3160f
cleanup
Guts Jul 24, 2022
7416dee
Refacto and fix tests against remote git repos
Guts Jul 24, 2022
057cf6d
Refacto test_data_path
Guts Sep 3, 2022
bc79291
Add a bit of type hint and path check
Guts Sep 3, 2022
0403b8a
Fix fixture path
Guts Sep 3, 2022
47dc060
Merge branch 'master' into tests/nose2-to-pytest
Guts Sep 3, 2022
1114943
Fix fixtures path
Guts Sep 3, 2022
33c8903
Merge branch 'tests/nose2-to-pytest' of github.com:QGIS-Contribution/…
Guts Sep 3, 2022
aa141c4
Check if xml path exists
Guts Sep 3, 2022
181e7f8
Handle case where test_data_path is a apthlib obj
Guts Sep 3, 2022
9aad112
Exploding resolve paths tests
Guts Sep 3, 2022
ce01b32
Fix typo in search path
Guts Sep 3, 2022
fd6a6ea
A bit of type hint
Guts Sep 3, 2022
e3c6989
Fix typo in repo name
Guts Sep 3, 2022
b4406ea
Fix test to xml mode
Guts Sep 3, 2022
aa28ebd
Fix expected path
Guts Sep 4, 2022
0523744
Set maxdiff to None to see full diff in comparison test
Guts Sep 4, 2022
386ffa4
Solve diff
Guts Sep 4, 2022
0b6db53
Disable cov warning
Guts Sep 4, 2022
5f71b0f
Skip false postifive test failure
Guts Sep 4, 2022
12ed2c1
rm test of main dialog
Guts Sep 4, 2022
b3246c9
Add test of plugin load
Guts Sep 4, 2022
c73d78c
Do not crash if a default repository is not reachable anymore
Guts Sep 5, 2022
f9e90bb
Disable pytest-qgis
Guts Sep 5, 2022
0dd4ddb
Revert "Disable pytest-qgis"
Guts Sep 5, 2022
ae68114
Try to avoid segmentation fault
Guts Sep 5, 2022
bbf958d
Revert "Try to avoid segmentation fault"
Guts Sep 5, 2022
bd0ff7d
Use conftest
Guts Sep 5, 2022
9460ea7
Add QT_QPA_PLATFORM
Guts Sep 5, 2022
5731b77
DO not start ap
Guts Sep 5, 2022
ae3e027
Clean up
Guts Sep 5, 2022
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
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/__pycache__
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.github
**/.gitignore
**/.project
**/.pytest_cache
**/.settings
**/.toolstarget
**/.venv
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/htmlcov
**/docker-compose*
**/Dockerfile*
**/junit
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/site
**/values.dev.yaml
81 changes: 81 additions & 0 deletions .github/workflows/tester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "🎳 Tester"

on:
push:
branches: [master]
paths:
- "**.py"

pull_request:
branches: [master]
paths:
- "**.py"

env:
PROJECT_FOLDER: "qgis_resource_sharing"
PYTHON_VERSION: 3.9

jobs:
tests-unit:
runs-on: ubuntu-latest

steps:
- name: Get source code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
cache-dependency-path: "requirements/testing.txt"

- name: Install Python requirements
run: |
python -m pip install -U pip setuptools wheel
python -m pip install -U -r requirements/testing.txt

- name: Run Unit tests
run: pytest -p no:qgis tests/unit/

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2

test-qgis:
runs-on: ubuntu-latest

container:
image: qgis/qgis:release-3_22
env:
CI: true
DISPLAY: ":1"
MUTE_LOGS: true
NO_MODALS: 1
PYTHONPATH: "/usr/share/qgis/python/plugins:/usr/share/qgis/python:."
QT_QPA_PLATFORM: "offscreen"
WITH_PYTHON_PEP: false
options: -v /tmp/.X11-unix:/tmp/.X11-unix -v ${{ github.workspace }}:/tests_directory

steps:
- name: Get source code
uses: actions/checkout@v3

- name: Print QGIS version
run: qgis --version

- name: Setup plugin
run: qgis_setup.sh qgis_resource_sharing

- name: Install Python requirements
run: |
python3 -m pip install -U pip setuptools wheel
python3 -m pip install --no-deps -U -r requirements/embedded.txt -t ${{ env.PROJECT_FOLDER }}/embedded_external_libs
python3 -m pip install -U -r requirements/testing.txt

- name: Run Unit tests
run: |
Xvfb :1 &
python3 -m pytest tests/qgis/

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ htmlcov/
nosetests.xml
coverage.xml
*,cover
junit/

# Sphinx documentation
docs/_build/
Expand Down
40 changes: 0 additions & 40 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"--verbose"
],
"python.linting.pylintEnabled": false,
// Tests
"python.testing.pytestArgs": [],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
// Git
"git.enableCommitSigning": true,
// Extensions
Expand Down
23 changes: 23 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
codecov:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "70...100"
status:
project: off
patch: off

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: no
50 changes: 50 additions & 0 deletions docs/development/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Tests

Tests are written in 2 separate folders:

- `tests/unit`: testing code which is independent of QGIS API
- `tests/qgis`: testing code which depends on QGIS API

## Requirements

- QGIS {{ qgis_version_min }}+

```bash
python -m pip install -U pip
python -m pip install -U -r requirements/testing.txt
```

## Running tests

```bash
# run all tests with PyTest and Coverage report
python -m pytest

# run only unit tests
python -m pytest tests/unit

# run only QGIS tests
python -m pytest tests/qgis

# run a specific test module using standard unittest
python -m unittest tests.unit.test_plg_metadata

# run a specific test function using standard unittest
python -m unittest tests.unit.test_plg_metadata.TestPluginMetadata.test_version_semver
```

### Using Docker

Build the image:

```bash
docker build --pull --rm -f "tests/tests_qgis.dockerfile" -t qgis_lts:plugin_tester .
```

Run tests:

```bash
docker run -v "$(pwd):/tmp/plugin" qgis_lts:plugin_tester python3 -m pytest
```

Please note that will use the root rights on some folders.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ maxdepth: 1
---
development/contributing
development/environment
development/testing
development/update_dependencies
development/documentation
development/packaging
Expand Down
4 changes: 2 additions & 2 deletions qgis_resource_sharing/collection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ def get_installed_collections(self, repo_url=None):
:rtype: dict
"""
installed_collections = {}
for id, collection in config.COLLECTIONS.items():
for collection_id, collection in config.COLLECTIONS.items():
if collection["status"] != COLLECTION_INSTALLED_STATUS:
continue

if repo_url:
if collection["repository_url"] != repo_url:
continue

installed_collections[id] = collection
installed_collections[collection_id] = collection

return installed_collections

Expand Down
23 changes: 12 additions & 11 deletions qgis_resource_sharing/repository_handler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from configparser import ConfigParser
from io import StringIO
from typing import Dict, List
from urllib.parse import urlparse

from ext_libs.giturlparse import validate as git_validate
Expand Down Expand Up @@ -127,11 +128,11 @@ def fetch_metadata(self):
self.metadata = bytes(network_manager.content).decode("utf8")
return status, fetcherror

def parse_metadata(self):
def parse_metadata(self) -> List[Dict]:
"""Parse str metadata to collection dict.

:return: collections
:rtype: (dict)
:rtype: List[Dict]
"""
if not self.metadata:
msg = "The metadata content is None"
Expand Down Expand Up @@ -227,20 +228,20 @@ def parse_metadata(self):
raise MetadataError("Error parsing metadata: %s" % e)

collection_dict = {
"register_name": collection,
"author": author,
"author_email": email,
"repository_url": self.url,
"repository_name": "",
"status": COLLECTION_NOT_INSTALLED_STATUS,
"name": name,
"tags": tags,
"description": description,
"qgis_min_version": qgis_min_version,
"qgis_max_version": qgis_max_version,
"preview": preview_list,
"license": license_str,
"license_url": license_url,
"name": name,
"preview": preview_list,
"qgis_max_version": qgis_max_version,
"qgis_min_version": qgis_min_version,
"register_name": collection,
"repository_name": "",
"repository_url": self.url,
"status": COLLECTION_NOT_INSTALLED_STATUS,
"tags": tags,
}
collections.append(collection_dict)

Expand Down
34 changes: 28 additions & 6 deletions qgis_resource_sharing/repository_handler/gogs_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#! python3 # noqa E265

# standard library
from urllib.parse import ParseResult, urlparse

# Plugin
from qgis_resource_sharing.repository_handler.remote_git_handler import RemoteGitHandler


Expand All @@ -8,16 +14,32 @@ class GogsHandler(RemoteGitHandler):

def __init__(self, url):
RemoteGitHandler.__init__(self, url)
self.url = url

@property
def url_parsed(self) -> ParseResult:
return urlparse(self.url)

@property
def git_host(self):
return "git.osgeo.org"

@property
def git_owner(self):
return self.url_parsed.path.split("/")[2]

@property
def git_platform(self):
return "gogs"

@property
def git_service(self):
return "gitea"

def can_handle(self):
if self.git_platform == "gogs":
return True
return False

def file_url(self, relative_path):
return "https://%s/%s/%s/raw/master/%s" % (
self.git_host,
self.git_owner,
self.git_repository,
relative_path,
)
return f"https://{self.git_host}/{self.git_service}/{self.git_owner}/{self.git_repository}/raw/branch/master/{relative_path}"
13 changes: 10 additions & 3 deletions qgis_resource_sharing/repository_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,16 @@ def load_directories(self):
LOGGER.warning(nameWarn)
break
if not repo_present:
self.add_directory(
online_dir_name, self._online_directories[online_dir_name]
)
try:
self.add_directory(
online_dir_name, self._online_directories[online_dir_name]
)
except Exception as exc:
LOGGER.error(
f"Error occured adding '{online_dir_name}' repository. Trace: {exc}"
)
continue

for repo_name in settings.childGroups():
self._directories[repo_name] = {}
url = settings.value(repo_name + "/url", "", type=str)
Expand Down
Loading