Skip to content

Commit

Permalink
Merge pull request #86 from MIERUNE/testing
Browse files Browse the repository at this point in the history
testing
  • Loading branch information
Kanahiro authored May 27, 2024
2 parents 73ca6fa + b78f09c commit 3f3f915
Show file tree
Hide file tree
Showing 13 changed files with 414 additions and 60 deletions.
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[report]
omit =
tests/*
/usr/lib/python3/dist-packages/*
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test

on:
pull_request:
branches: [main]
workflow_dispatch:

jobs:
Test:
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

- name: Pull QGIS
run: docker pull qgis/qgis:${{ matrix.qgis_image_tag }}

- 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: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: MIERUNE/GTFS-GO
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
Desktop.ini
__pycache__/
.venv/
.coverage
coverage.xml
.pytest_cache/
.ruff_cache/
requirements.txt
7 changes: 7 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import os
import sys

# to import modules as non-relative
sys.path.append(os.path.dirname(__file__))


def classFactory(iface): # pylint: disable=invalid-name
"""Load GTFSGo class from file GTFSGo.
Expand Down
2 changes: 1 addition & 1 deletion gtfs_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from qgis.PyQt.QtWidgets import QAction

# Import the code for the DockWidget
from .gtfs_go_dialog import GTFSGoDialog
from gtfs_go_dialog import GTFSGoDialog


class GTFSGo:
Expand Down
13 changes: 7 additions & 6 deletions gtfs_go_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
from qgis.gui import QgisInterface
from qgis.PyQt import uic

from . import constants, repository
from .gtfs_go_labeling import get_labeling_for_stops
from .gtfs_go_renderer import Renderer
from .gtfs_go_settings import (
import constants
import gtfs_parser
import repository
from gtfs_go_labeling import get_labeling_for_stops
from gtfs_go_renderer import Renderer
from gtfs_go_settings import (
STOPS_MINIMUM_VISIBLE_SCALE,
)
from .gtfs_parser import gtfs_parser
from .repository.japan_dpf.table import HEADERS, HEADERS_TO_HIDE
from repository.japan_dpf.table import HEADERS, HEADERS_TO_HIDE

DATALIST_JSON_PATH = os.path.join(os.path.dirname(__file__), "gtfs_go_datalist.json")
TEMP_DIR = os.path.join(tempfile.gettempdir(), "GTFSGo")
Expand Down
2 changes: 1 addition & 1 deletion gtfs_go_labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
)
from qgis.PyQt.QtGui import QColor, QFont

from .gtfs_go_settings import (
from gtfs_go_settings import (
STOPS_LABEL_BUFFER_COLOR,
STOPS_LABEL_BUFFER_SIZE_MM,
STOPS_LABEL_DIST_MM,
Expand Down
2 changes: 1 addition & 1 deletion gtfs_go_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtGui import QColor

from .gtfs_go_settings import (
from gtfs_go_settings import (
ROUTES_COLOR_LIST,
ROUTES_LINE_WIDTH_MM,
ROUTES_OUTLINE_COLOR,
Expand Down
358 changes: 308 additions & 50 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ authors = ["Kanahiro <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.9"


[tool.poetry.group.dev.dependencies]
pytest = "^7.2.1"
ruff = "^0.4.3"
pytest-qt = "^4.4.0"
pytest-cov = "^5.0.0"
pandas = "^2.2.2"
pytest-mock = "^3.14.0"
pytest-qgis = "^2.0.0"


[build-system]
requires = ["poetry-core"]
Expand Down
Empty file added tests/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Iterable

import pytest
from pytest_mock import MockerFixture
from qgis.gui import QgisInterface
from qgis.PyQt.QtCore import QSettings

from ..__init__ import classFactory


@pytest.fixture()
def plugin(qgis_iface: QgisInterface, mocker: MockerFixture) -> Iterable[None]:
# mock
mocker.patch.object(QSettings, "value", return_value="en")
qgis_iface.addPluginToWebMenu = lambda x, y: None # pytest-qgisで未実装

_plugin = classFactory(qgis_iface)
_plugin.initGui()

yield _plugin

# _plugin.unload() QgisInterface.removePluginMenu()がpytest-qgisで未実装
16 changes: 16 additions & 0 deletions tests/test_gtfs_go.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from gtfs_go import GTFSGo


def test_run(plugin: GTFSGo):
"""ダイアログを表示する関数のテスト"""

# 初期状態でダイアログは未初期化
assert plugin.dialog is None

plugin.run()
assert plugin.dialog.isVisible()

plugin.dialog.close()

assert not plugin.dialog.isVisible() # ダイアログが閉じられても
assert plugin.dialog is not None # インスタンスは保持される

0 comments on commit 3f3f915

Please sign in to comment.