-
Notifications
You must be signed in to change notification settings - Fork 11
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
testing #86
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[report] | ||
omit = | ||
tests/* | ||
/usr/lib/python3/dist-packages/* |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,8 @@ | |
Desktop.ini | ||
__pycache__/ | ||
.venv/ | ||
.coverage | ||
coverage.xml | ||
.pytest_cache/ | ||
.ruff_cache/ | ||
requirements.txt |
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__)) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 関数の型ヒントを追加することを提案します。 関数の引数と戻り値に型ヒントを追加することで、コードの明確性と保守性が向上します。 - def classFactory(iface):
+ def classFactory(iface: QgsInterface) -> GTFSGo:
|
||
def classFactory(iface): # pylint: disable=invalid-name | ||
"""Load GTFSGo class from file GTFSGo. | ||
|
||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"] | ||
|
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||
_plugin = classFactory(qgis_iface) | ||||||||||||||||||||||||
_plugin.initGui() | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
yield _plugin | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
# _plugin.unload() QgisInterface.removePluginMenu()がpytest-qgisで未実装 | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. テストフィクスチャのクリーンアップに関するコメントを追加することを提案します。 未実装の関数による制限を明確にするために、コメントを追加することをお勧めします。 + # QgisInterface.removePluginMenu()がpytest-qgisで未実装のため、この部分はコメントアウトされています
# _plugin.unload() QgisInterface.removePluginMenu()がpytest-qgisで未実装 Committable suggestion
Suggested change
|
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 # インスタンスは保持される |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys.pathの操作によるモジュールのインポート方法を改善する提案。
絶対インポートを使用することで、sys.pathを操作する必要がなくなり、コードの可読性と保守性が向上します。