Skip to content

Commit

Permalink
Add a basic interoperability test for Jinja2 extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Jul 18, 2024
1 parent 3de1763 commit 055e115
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
Empty file added tests/interop/__init__.py
Empty file.
1 change: 1 addition & 0 deletions tests/interop/jinja2_data/hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% trans %}Hello, {{ name }}!{% endtrans %}
1 change: 1 addition & 0 deletions tests/interop/jinja2_data/mapping.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[jinja2: *.html]
20 changes: 20 additions & 0 deletions tests/interop/test_jinja2_interop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pathlib

import pytest

from babel.messages import frontend

jinja2 = pytest.importorskip("jinja2")

jinja2_data_path = pathlib.Path(__file__).parent / "jinja2_data"


def test_jinja2_interop(monkeypatch, tmp_path):
"""
Test that babel can extract messages from Jinja2 templates.
"""
monkeypatch.chdir(jinja2_data_path)
cli = frontend.CommandLineInterface()
pot_file = tmp_path / "messages.pot"
cli.run(['pybabel', 'extract', '--mapping', 'mapping.cfg', '-o', str(pot_file), '.'])
assert '"Hello, %(name)s!"' in pot_file.read_text()
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ envlist =
pypy3
py{38}-pytz
py{311,312}-setuptools
py312-jinja

[testenv]
extras =
Expand All @@ -15,6 +16,7 @@ deps =
tzdata;sys_platform == 'win32'
pytz: pytz
setuptools: setuptools
jinja: jinja2>=3.0
allowlist_externals = make
commands = make clean-cldr test
setenv =
Expand Down

0 comments on commit 055e115

Please sign in to comment.