Weblate sınama paketi ve kesintisiz bütünleştirme¶
Sınama paketleri geçerli kodun çoğu için bulunabilir. Herhangi bir yeni özellik için sınama çalışmaları ekleyerek kapsamı artırın ve çalıştığını doğrulayın.
Kesintisiz bütünleştirme¶
Weblate, kod kalitesini sağlamak için sınamaları yürütmek, belgeleri oluşturmak, kodları temizlemek ve diğer görevler için GitHub Actions kullanır.
Codecov yürütülen sınamalardan kod kapsamı bilgilerini toplar.
Farklı yönleri doğrulayacak birkaç görev vardır:
Unit and functional tests using pytest.
Documentation build and external links using Sphinx.
Code security scanning using CodeQL.
Argos kesintisiz bütünleştirme ile görsel değişiklik testi.
Code formatting using prek, a faster third-party reimplementation of the pre-commit framework.
Desteklenen tüm sürümlerden aktarım sınaması
Kurulum doğrulaması (oluşturulan dist dosyalarının hiçbir şeyi kaçırmamasını ve sınanabilmesini sağlar)
Kesintisiz bütünleştirme yapılandırması .github/workflows klasöründe bulunur ve yoğun olarak ci klasöründeki yardımcı betikleri kullanır. Betikler el ile de yürütülebilir, ancak çoğunlukla kullanılacak Django ayarları dosyasını ve veri tabanı bağlantısını denetleyen birkaç ortam değişkeni gereklidir. Bunun örnek tanımını scripts/test-database.sh içinde bulabilirsiniz:
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.
GitHub repository URLs in these screenshots use local Git transport rewrites.
The shared Git fixture archive contains the ordinary test data and a separate,
pinned demo revision, so repository discovery shows only demo content. Regenerate
the archive with scripts/pack-test-data.sh; update its DEMO_REVISION
when intentionally refreshing the demo data. Runtime tests do not fetch GitHub
repositories or resolve their hostname. The TEST_REVISION pin controls the
ordinary Git, Mercurial, and Subversion data independently.
Selenium tests that consume the standard demo can opt in with
@reuse_demo_fixture from weblate/trans/tests/selenium_fixtures.py.
Place it outside other method decorators. It restores committed database rows
and the demo’s working repositories before the test body, so call
create_component() before creating additional components as usual. Create
users and other test-specific data inside the test body; restoration replaces
the database. GitHub transports and browser state remain isolated per test.
Keep creation and empty-state tests undecorated so they continue to exercise
the browser forms and generate their screenshots.
# 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
Basit yürütme şöyle görünebilir:
source scripts/test-database.sh
./ci/run-migrate
./ci/run-test
./ci/run-docs
Weblate kurulumunu yerel olarak sınamak¶
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 kullanarak sınama¶
Sınamaları başlatmadan önce, bazı sınamalar için var olmaları gerektiğinden durağan dosyaları toplamalısınız:
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
Property-based tests using hypothesis run as part of the normal pytest suite. They check Markdown output safety, backup archive member paths, and SSH URL parsing with bounded generated inputs. Each property runs up to 100 generated examples deterministically, alongside explicit regression examples. Unexpected exceptions fail the test, and Hypothesis minimizes failing inputs. Add minimized inputs as explicit regression examples when fixing a failure. Timing deadlines are disabled to avoid failures caused by CI load.
Tekil bir sınama dosyasını çalıştırmak:
uv run pytest weblate/utils/tests/test_search.py
İpucu
Sınamalar için kullanılacak bir veri tabanı (PostgreSQL) sunucusuna gerek duyacaksınız. Django varsayılan olarak, test_ ön eki olan sınamaları çalıştırmak için ayrı bir veri tabanı oluşturur. Bu nedenle ayarlarınızın weblate kullanacak şekilde yapılandırılması durumunda, sınamalar test_weblate veri tabanını kullanır. Kurulum yönergesi için Weblate için veri tabanı kurulumu bölümüne bakabilirsiniz.
weblate/settings_test.py kesintisiz bütünleştirme ortamında da kullanılır (ayrıntılı bilgi almak için: Kesintisiz bütünleştirme) ve ortam değişkenleri kullanılarak ayarlanabilir:
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
İpucu
Sınamalar geliştirici docker kapsayıcısı içinde de yürütülebilir. Ayrıntılı bilgi almak için: Weblate platformunu Docker üzerinde yerel olarak çalıştırma.
Ayrıca bakınız
Django sınamalarını çalıştırmak ve yazmak ile ilgili bilgi almak için Testing in Django bölümüne bakabilirsiniz.
Tests that repeatedly import the same component can inherit from
ReusableComponentTestCase or ReusableViewTestCase in
weblate/trans/tests/test_views.py. These bases build the initial user,
project, component, and translations once per class in setUpTestData().
Override create_component() to select a repository fixture or file format,
as with ComponentTestCase. For additional shared setup, override the
build_fixture(cls, builder) class method, call super().build_fixture(builder),
and use the builder’s repository helpers and model instances.
Each test reloads its model instances and receives a restored copy of the working repositories, upstream repositories used during construction, and test Git configuration. Database changes are rolled back by Django. Clients, authentication, and application caches are initialized per test. Snapshots are temporary and local to each class and worker; extra components created within a test still use the normal component factories.
API tests inheriting APIBaseTest in weblate/api/tests.py use the same
repository restoration. The API user and initial component, including its
automatic glossary, are created once per class. Component construction callbacks
run during this shared setup. API clients, credentials, and subclass setup such
as screenshots and announcements are initialized per test.
Use the existing bases for TransactionTestCase and concurrency tests, or when
component construction itself must run under a method-specific settings override.
The reusable bases do not replay component construction signals or commit
callbacks before each test.
Weblate modüllerini yerel olarak sınamak¶
The tests are executed using pytest. First you need to install development dependencies:
uv sync --all-extras --dev
Daha sonra depo checkout sayfasında sınama paketini yürütebilirsiniz:
uv run pytest
Depoları sınamak¶
Weblate sınama paketindeki sınamaların çoğu sınama deposunu kullanır. Sınama paketi deposu https://github.com/WeblateOrg/test adresinde bulunur. Daha sonra scripts/pack-test-data.sh betiği, desteklenen sürüm denetimi sistemlerinin her biri için bir depo içeren bir tarball oluşturmak için kullanılır. Bunlar Weblate deposunda weblate/trans/tests/data/test-base-repo.git.tar, weblate/trans/tests/data/test-base-repo.hg.tar ve weblate/trans/tests/data/test-base-repo.svn.tar olarak saklanır.
https://github.com/WeblateOrg/test deposu yayınlandığı zaman etiketlenir, bu da yayınlama etiketlerinin yayınlanma zamanında kullanılan sınama verilerine erişmek için kullanılabilmesini sağlar. Betik olabildiğince yinelenebilir tarball paketleri oluşturmaya çalışır.