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

testing #86

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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__))
Comment on lines +1 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sys.pathの操作によるモジュールのインポート方法を改善する提案。

絶対インポートを使用することで、sys.pathを操作する必要がなくなり、コードの可読性と保守性が向上します。

- import os
- import sys
- sys.path.append(os.path.dirname(__file__))

Committable suggestion was skipped due low confidence.



Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

関数の型ヒントを追加することを提案します。

関数の引数と戻り値に型ヒントを追加することで、コードの明確性と保守性が向上します。

- def classFactory(iface):
+ def classFactory(iface: QgsInterface) -> GTFSGo:

Committable suggestion was skipped due low confidence.

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で未実装

Comment on lines +11 to +16
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストフィクスチャのセットアップに関するコメントを追加することを提案します。

未実装の関数を使用する際のワークアラウンドを明確にするために、コメントを追加することをお勧めします。

+    # このlambdaはpytest-qgisで未実装の関数をワークアラウンドするためのものです
     qgis_iface.addPluginToWebMenu = lambda x, y: None  # pytest-qgisで未実装

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
@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で未実装
@pytest.fixture()
def plugin(qgis_iface: QgisInterface, mocker: MockerFixture) -> Iterable[None]:
# mock
mocker.patch.object(QSettings, "value", return_value="en")
# このlambdaはpytest-qgisで未実装の関数をワークアラウンドするためのものです
qgis_iface.addPluginToWebMenu = lambda x, y: None # pytest-qgisで未実装

_plugin = classFactory(qgis_iface)
_plugin.initGui()

yield _plugin

# _plugin.unload() QgisInterface.removePluginMenu()がpytest-qgisで未実装
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストフィクスチャのクリーンアップに関するコメントを追加することを提案します。

未実装の関数による制限を明確にするために、コメントを追加することをお勧めします。

+    # QgisInterface.removePluginMenu()がpytest-qgisで未実装のため、この部分はコメントアウトされています
     # _plugin.unload() QgisInterface.removePluginMenu()がpytest-qgisで未実装

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
# _plugin.unload() QgisInterface.removePluginMenu()がpytest-qgisで未実装
# QgisInterface.removePluginMenu()がpytest-qgisで未実装のため、この部分はコメントアウトされています
# _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 # インスタンスは保持される
Loading