Weblate テストスイートと継続的なインテグレーション

現在、ほぼすべてのコードにテストスイートがあります。新しい機能のテストケースを追加し、検査対象を増やして動作を検証します。

継続的なインテグレーション

Weblate はテストの実行、ドキュメントのビルド、コードの lint、その他の品質保証タスクを行うために GitHub Actions を利用しています。

Codecov は実行されたテストからコードカバレッジ情報を収集します。

さまざまな側面を検証するためのジョブ:

  • 単体テストおよび機能テストには pytest が使用されています。

  • ドキュメントのビルドおよび外部リンクの検証には Sphinx が使用されています。

  • コードの lint と品質保証には ruff と pylint が使用されています。

  • コードのセキュリティスキャンには CodeQL が使用されています。

  • Visual changes testing is utilizing Argos CI.

  • Code formatting using prek, a faster third-party reimplementation of the pre-commit framework.

  • 対応しているすべてのリリースからの移行テスト

  • 設定の検証(生成された dist ファイルに間違いがなく、テスト済みを保証する)

CI の設定は、.github/workflows ディレクトリにあります。 ci ディレクトリに格納されているヘルパー スクリプトを頻繁に使用します。このスクリプトは手動でも実行できますが、使用する Django 設定ファイルとデータベース接続を設定するなど、環境変数の設定が必要です。確認すべき scripts/test-database.sh に記述された設定例:

The Selenium screenshot tests in weblate/trans/tests/test_selenium.py serve two purposes. They generate images for visual change testing in CI, and the same images are converted into documentation screenshots by make -C docs update-screenshots. Keep screenshot fixtures close to real rendered pages so CI catches UI regressions. When a screenshot includes volatile runtime data, prefer deterministic server-side test inputs over post-render DOM changes.

# 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 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

Weblate のローカル テスト

For an isolated environment with dependencies and test services already configured, use the development container. Its CLI can run the same pytest and lint commands documented below in each Git worktree.

Before running tests, please ensure development dependencies are installed:

uv sync --all-extras --dev

pytest を使用したテスト

テストを実行する前に、静的ファイルの収集が必要です。テストによっては、静的ファイルの存在に依存しているためです。静的ファイルの収集方法:

DJANGO_SETTINGS_MODULE=weblate.settings_test uv run ./manage.py collectstatic --noinput

You can use pytest to run the test suite locally:

uv run pytest

個々のテストファイルの実行:

uv run pytest weblate/utils/tests/test_search.py

ヒント

テストには、使用するデータベース(PostgreSQL)サーバーが必要です。デフォルトでは、Django はテストを実行するために、接頭辞 test_ を付けた別のデータベースを作成します。そのため、weblate を使用するように設定している場合、テストには test_weblate データベースを使用します。設定方法については、Weblate のデータベース設定 を確認してください。

weblate/settings_test.py は CI 環境でも使用されます(参照: 継続的なインテグレーション)。環境変数を用いた設定方法:

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 におけるテスト を確認してください。

Weblate モジュールのローカル テスト

The tests are executed using pytest. First you need to install development dependencies:

uv sync --all-extras --dev

そのあと、チェックアウトしたリポジトリでテストスイートを実行:

uv run pytest

テスト用リポジトリ

Weblate のテストスイートの多くは、テスト用リポジトリを使用します。テストスイート用のリポジトリは https://github.com/WeblateOrg/test で管理されています。scripts/pack-test-data.sh スクリプトを使用して、サポートされている各バージョン管理システム向けのリポジトリを含む tarball を生成します。この tarball は Weblate リポジトリ内に weblate/trans/tests/data/test-base-repo.git.tar、weblate/trans/tests/data/test-base-repo.hg.tar、weblate/trans/tests/data/test-base-repo.svn.tar として保存されます。

https://github.com/WeblateOrg/test リポジトリはリリース時にタグ付けされ、リリース時点で使用されたテストデータにアクセスできるようになっています。このスクリプトは、可能な限り再現性のある tarball を作成するように設計されています。