Skip to content

Commit

Permalink
Add a test run without Flask-Babel installed
Browse files Browse the repository at this point in the history
Adds a `flask_babel` mark to any tests that explicitly require
`Flask-Babel` to be installed.

Configures tox and GitHub Actions to run a test suite with Flask-Babel
removed. This validates a codepath through `flask_admin.babel`, which
should essentially be passthrough/noop behaviour if Flask-Babel is
unavailable.
  • Loading branch information
samuelhwilliams committed Jul 17, 2024
1 parent 801e632 commit dbca159
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ on:
- '*.rst'
jobs:
tests:
name: ${{ format('py{0}-wtforms{1}', matrix.python, matrix.wtforms) }}
name: ${{ matrix.tox == 'normal' && format('py{0}-flask{1}-wtforms{2}', matrix.python, matrix.flask, matrix.wtforms) || matrix.tox }}
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
strategy:
fail-fast: false
matrix:
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
flask: ['2']
wtforms: ['2']
tox: ['normal']
include:
- python: '3.12'
flask: '2'
wtforms: '2'
tox: 'py312-flask2-wtforms2-no-flask-babel'
services:
# Label used to access the service container
postgres:
Expand Down Expand Up @@ -68,7 +75,7 @@ jobs:
PGPASSWORD: postgres
run: psql -U postgres -h localhost -c 'CREATE EXTENSION hstore;' flask_admin_test
- run: pip install tox
- run: tox run -e ${{ matrix.tox || format('py{0}-wtforms{1}', matrix.python, matrix.wtforms) }}
- run: tox run -e ${{ matrix.tox == 'normal' && format('py{0}-flask{1}-wtforms{2}', matrix.python, matrix.flask, matrix.wtforms) || matrix.tox }}
not_tests:
name: ${{ matrix.tox }}
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions flask_admin/tests/sqla/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,7 @@ def test_extra_field_order(app, db, admin):
('zh_TW', '首頁'),
)
)
@pytest.mark.flask_babel
def test_modelview_localization(request, app, locale, expect_text):
# We need to configure the default Babel locale _before_ the `babel` fixture is
# initialised, so we have to use `request.getfixturevalue` to pull the fixture
Expand Down Expand Up @@ -2210,6 +2211,7 @@ def test_modelview_localization(request, app, locale, expect_text):
assert rv.status_code == 200


@pytest.mark.flask_babel
def test_modelview_named_filter_localization(request, app):
# We need to configure the default Babel locale _before_ the `babel` fixture is
# initialised, so we have to use `request.getfixturevalue` to pull the fixture
Expand Down
3 changes: 3 additions & 0 deletions flask_admin/tests/sqla/test_translation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import pytest

from flask_admin.babel import lazy_gettext

from .test_basic import CustomModelView, create_models


@pytest.mark.flask_babel
def test_column_label_translation(request, app):
# We need to configure the default Babel locale _before_ the `babel` fixture is
# initialised, so we have to use `request.getfixturevalue` to pull the fixture
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ name = "flask_admin"

[tool.pytest.ini_options]
testpaths = ["tests"]
markers = [
"flask_babel: requires Flask-Babel to be installed"
]
filterwarnings = [
"error",
# TODO: remove the ignored deprecation warning when support for WTForms 3 has been added.
Expand Down
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[tox]
envlist =
py3{8,9,10,11,12}-flask{2}-wtforms{2}
py312-flask2-wtforms2-no-flask-babel # only tested against latest of all configurations, sans flask-babel
# style
typing
docs
Expand All @@ -23,6 +24,11 @@ deps =
wtforms2: WTForms>=2.0,<3
commands = pytest -v --tb=short --basetemp={envtmpdir} flask_admin/tests {posargs}

[testenv:py312-flask2-wtforms2-no-flask-babel]
commands =
pip uninstall -y flask-babel
pytest -v --tb=short --basetemp={envtmpdir} flask_admin/tests -m "not flask_babel" {posargs}

[testenv:style]
deps = pre-commit
skip_install = true
Expand Down

0 comments on commit dbca159

Please sign in to comment.