Weblate testsuite și integrare continuă¶
Există seturi de teste pentru cea mai mare parte a codului actual, creșteți acoperirea prin adăugarea de cazuri de testare pentru orice nouă funcționalitate și verificați dacă aceasta funcționează.
Integrare continuă¶
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.
Există mai multe locuri de muncă pentru a verifica diferite aspecte:
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.
Testarea migrării de la toate versiunile suportate
Verificarea configurării (se asigură că fișierele dist generate nu ratează nimic și pot fi testate)
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
Execuția simplă poate arăta astfel:
source scripts/test-database.sh
./ci/run-migrate
./ci/run-test
./ci/run-docs
Local testing of Weblate¶
Before running tests, please ensure development dependencies are installed:
uv sync --all-extras --dev
Testing using pytest¶
Înainte de a rula testele, ar trebui să colectați fișierele statice, deoarece unele teste se bazează pe prezența lor:
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
Sugestie
Veți avea nevoie de un server de baze de date (PostgreSQL) care să fie utilizat pentru teste. În mod implicit, Django creează o bază de date separată pentru a rula testele cu prefixul test_, astfel încât, în cazul în care setările dvs. sunt configurate pentru a utiliza weblate, testele vor utiliza baza de date test_weblate. Consultați Configurarea bazei de date pentru Weblate pentru instrucțiuni de configurare.
Fișierul weblate/settings_test.py este utilizat și în mediul CI (a se vedea Integrare continuă) și poate fi reglat cu ajutorul variabilelor de mediu:
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
Sugestie
Testele pot fi, de asemenea, executate în interiorul containerului docker al dezvoltatorului, vezi Rularea Weblate la nivel local în Docker.
Vezi și
Consultați Testing in Django pentru mai multe informații despre rularea și scrierea testelor pentru Django.
Local testing of Weblate modules¶
The tests are executed using pytest. First you need to install development dependencies:
uv sync --all-extras --dev
Apoi puteți executa suita de teste în cadrul verificării depozitului:
uv run pytest
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.