Weblate テストスイートと継続的な連携¶
現在、ほぼすべてのコードにテストスイートがあります。新しい機能のテストケースを追加し、検査対象を増やして動作を検証します。
継続的な連携¶
Weblate relies on GitHub Actions to run tests, build documentation, code linting, and other tasks to ensure code quality.
Codecov collects the code coverage information from the tests that were run.
さまざまな側面を検証するためのジョブ:
Unit and functional tests using pytest.
Documentation build and external links using Sphinx.
Code security scanning using CodeQL.
Code formatting using pre-commit.
対応しているすべてのリリースからの移行テスト
設定の検証(生成された dist ファイルに間違いがなく、テスト済みを保証する)
The configuration for the CI is in .github/workflows directory. It
heavily uses helper scripts stored in ci directory. The scripts can be
also executed manually, but they require several environment variables, mostly
defining Django settings file to use and test database connection. The example
definition of that is in scripts/test-database.sh:
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Simple way to configure test database from environment
# shellcheck shell=sh
# Database backend to use postgresql / mysql / mariadb
export CI_DATABASE="${1:-postgresql}"
# Database server configuration
export CI_DB_USER=weblate
export CI_DB_PASSWORD=weblate
export CI_DB_HOST=127.0.0.1
# Django settings module to use
export DJANGO_SETTINGS_MODULE=weblate.settings_test
単純な実行例:
source scripts/test-database.sh
./ci/run-migrate
./ci/run-test
./ci/run-docs
Local testing of Weblate¶
テストを実行する前に、テストの依存関係がインストールされていることを確認してください。これは、pip install -e .[test] によって実行できます。
pytest を使用したテスト¶
テストを実行する前に、静的ファイルの収集が必要です。テストによっては、静的ファイルの存在に依存しているためです。静的ファイルの収集方法:
DJANGO_SETTINGS_MODULE=weblate.settings_test ./manage.py collectstatic
pytest を使用してテストスイートをローカルで実行するコマンド:
pytest weblate
個々のテストファイルの実行:
pytest weblate/utils/tests/test_search.py
ヒント
テストには、使用するデータベース(PostgreSQL)サーバーが必要です。デフォルトでは、Django はテストを実行するために、接頭辞 test_ を付けた別のデータベースを作成します。そのため、weblate を使用するように設定している場合、テストには test_weblate データベースを使用します。設定方法については、Weblate のデータベース設定 を確認してください。
weblate/settings_test.py は CI 環境でも使用されます(参照: 継続的な連携)。環境変数を用いた設定方法:
export CI_DATABASE=postgresql
export CI_DB_USER=weblate
export CI_DB_PASSWORD=weblate
export CI_DB_HOST=127.0.0.1
export CI_DB_PORT=60000
export DJANGO_SETTINGS_MODULE=weblate.settings_test
ヒント
テストは、開発者の Docker コンテナ内でも実行できます。参照: Docker上でローカルに Weblate の実行。
参考
Django の実行と書き込みテストの詳細については、Django におけるテスト を確認してください。
Local testing of Weblate modules¶
テストは、py.test を使用して実行します。まず、テストに必要なパッケージをインストール:
uv pip install -e '.[dev]'
そのあと、チェックアウトしたリポジトリでテストスイートを実行:
py.test
Testing repository¶
Many of the tests in the Weblate test suite use the test repository. The test
suite repository is maintained at https://github.com/WeblateOrg/test. The
script scripts/pack-test-data.sh is then used to generate a tarball
with a repository for each of the supported version control systems. These are
stored as weblate/trans/tests/data/test-base-repo.git.tar,
weblate/trans/tests/data/test-base-repo.hg.tar, and
weblate/trans/tests/data/test-base-repo.svn.tar in the Weblate
repository.
The https://github.com/WeblateOrg/test repository is tagged at the release time, which ensures that the release tags can be used to access test data used at the release time. The script tries to create reproducible tarballs as much as possible.