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.
Visual changes testing is utilizing Argos CI.
Code formatting using prek, a faster third-party reimplementation of the pre-commit framework.
來自所有支援的發佈版本的合併測試
設定確認(確保產生的 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 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 本地測試¶
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
Running an individual test file:
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寫測試的更多資訊請參閱 Testing in Django。
Local testing of Weblate modules¶
The tests are executed using pytest. First you need to install development dependencies:
uv sync --all-extras --dev
You can then execute the testsuite in the repository checkout:
uv run pytest
測試儲存庫¶
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.