Skip to content

Commit aeb587e

Browse files
committed
testing
1 parent 73ca6fa commit aeb587e

13 files changed

+413
-60
lines changed

.coveragerc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[report]
2+
omit =
3+
tests/*
4+
/usr/lib/python3/dist-packages/*

.github/workflows/test.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
jobs:
9+
Test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
qgis_image_tag: [release-3_28]
14+
env:
15+
OS: ubuntu
16+
QGIS_IMAGE_TAG: ${{ matrix.qgis_image_tag }}
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Pull QGIS
21+
run: docker pull qgis/qgis:${{ matrix.qgis_image_tag }}
22+
23+
- name: Export requirements.txt
24+
run: |
25+
pip3 install poetry
26+
poetry export --with dev --without pyqt5 -f requirements.txt -o requirements.txt
27+
28+
- name: Run tests
29+
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"
30+
31+
- name: Upload coverage reports to Codecov
32+
uses: codecov/[email protected]
33+
with:
34+
token: ${{ secrets.CODECOV_TOKEN }}
35+
slug: MIERUNE/GTFS-GO

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
Desktop.ini
33
__pycache__/
44
.venv/
5+
.coverage
6+
coverage.xml
7+
.pytest_cache/
8+
.ruff_cache/
9+
requirements.txt

__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import os
2+
import sys
3+
4+
# to import modules as non-relative
5+
sys.path.append(os.path.dirname(__file__))
6+
7+
18
def classFactory(iface): # pylint: disable=invalid-name
29
"""Load GTFSGo class from file GTFSGo.
310

gtfs_go.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from qgis.PyQt.QtWidgets import QAction
66

77
# Import the code for the DockWidget
8-
from .gtfs_go_dialog import GTFSGoDialog
8+
from gtfs_go_dialog import GTFSGoDialog
99

1010

1111
class GTFSGo:

gtfs_go_dialog.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
from qgis.gui import QgisInterface
1919
from qgis.PyQt import uic
2020

21-
from . import constants, repository
22-
from .gtfs_go_labeling import get_labeling_for_stops
23-
from .gtfs_go_renderer import Renderer
24-
from .gtfs_go_settings import (
21+
import constants
22+
import gtfs_parser
23+
import repository
24+
from gtfs_go_labeling import get_labeling_for_stops
25+
from gtfs_go_renderer import Renderer
26+
from gtfs_go_settings import (
2527
STOPS_MINIMUM_VISIBLE_SCALE,
2628
)
27-
from .gtfs_parser import gtfs_parser
28-
from .repository.japan_dpf.table import HEADERS, HEADERS_TO_HIDE
29+
from repository.japan_dpf.table import HEADERS, HEADERS_TO_HIDE
2930

3031
DATALIST_JSON_PATH = os.path.join(os.path.dirname(__file__), "gtfs_go_datalist.json")
3132
TEMP_DIR = os.path.join(tempfile.gettempdir(), "GTFSGo")

gtfs_go_labeling.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
)
77
from qgis.PyQt.QtGui import QColor, QFont
88

9-
from .gtfs_go_settings import (
9+
from gtfs_go_settings import (
1010
STOPS_LABEL_BUFFER_COLOR,
1111
STOPS_LABEL_BUFFER_SIZE_MM,
1212
STOPS_LABEL_DIST_MM,

gtfs_go_renderer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from qgis.PyQt.QtCore import Qt
1111
from qgis.PyQt.QtGui import QColor
1212

13-
from .gtfs_go_settings import (
13+
from gtfs_go_settings import (
1414
ROUTES_COLOR_LIST,
1515
ROUTES_LINE_WIDTH_MM,
1616
ROUTES_OUTLINE_COLOR,

poetry.lock

+308-50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ authors = ["Kanahiro <[email protected]>"]
66
readme = "README.md"
77

88
[tool.poetry.dependencies]
9-
python = "^3.7"
9+
python = "^3.9"
1010

1111

1212
[tool.poetry.group.dev.dependencies]
1313
pytest = "^7.2.1"
1414
ruff = "^0.4.3"
15+
pytest-qt = "^4.4.0"
16+
pytest-cov = "^5.0.0"
17+
pandas = "^2.2.2"
18+
pytest-mock = "^3.14.0"
19+
pytest-qgis = "^2.0.0"
1520

1621
[build-system]
1722
requires = ["poetry-core"]

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import Iterable
2+
3+
import pytest
4+
from pytest_mock import MockerFixture
5+
from qgis.gui import QgisInterface
6+
from qgis.PyQt.QtCore import QSettings
7+
8+
from ..__init__ import classFactory
9+
10+
11+
@pytest.fixture()
12+
def plugin(qgis_iface: QgisInterface, mocker: MockerFixture) -> Iterable[None]:
13+
# mock
14+
mocker.patch.object(QSettings, "value", return_value="en")
15+
qgis_iface.addPluginToWebMenu = lambda x, y: None # pytest-qgisで未実装
16+
17+
_plugin = classFactory(qgis_iface)
18+
_plugin.initGui()
19+
20+
yield _plugin
21+
22+
# _plugin.unload() QgisInterface.removePluginMenu()がpytest-qgisで未実装

tests/test_gtfs_go.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from gtfs_go import GTFSGo
2+
3+
4+
def test_run(plugin: GTFSGo):
5+
"""ダイアログを表示する関数のテスト"""
6+
7+
# 初期状態でダイアログは未初期化
8+
assert plugin.dialog is None
9+
10+
plugin.run()
11+
assert plugin.dialog.isVisible()
12+
13+
plugin.dialog.close()
14+
15+
assert not plugin.dialog.isVisible() # ダイアログが閉じられても
16+
assert plugin.dialog is not None # インスタンスは保持される

0 commit comments

Comments
 (0)