]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Add a basic interoperability test for Jinja2 extraction
authorAarni Koskela <akx@iki.fi>
Thu, 18 Jul 2024 08:04:23 +0000 (11:04 +0300)
committerAarni Koskela <akx@iki.fi>
Thu, 25 Jul 2024 09:39:08 +0000 (12:39 +0300)
tests/interop/__init__.py [new file with mode: 0644]
tests/interop/jinja2_data/hello.html [new file with mode: 0644]
tests/interop/jinja2_data/mapping.cfg [new file with mode: 0644]
tests/interop/test_jinja2_interop.py [new file with mode: 0644]
tox.ini

diff --git a/tests/interop/__init__.py b/tests/interop/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/interop/jinja2_data/hello.html b/tests/interop/jinja2_data/hello.html
new file mode 100644 (file)
index 0000000..c2bb4eb
--- /dev/null
@@ -0,0 +1 @@
+{% trans %}Hello, {{ name }}!{% endtrans %}
diff --git a/tests/interop/jinja2_data/mapping.cfg b/tests/interop/jinja2_data/mapping.cfg
new file mode 100644 (file)
index 0000000..ae3f8bd
--- /dev/null
@@ -0,0 +1 @@
+[jinja2: *.html]
diff --git a/tests/interop/test_jinja2_interop.py b/tests/interop/test_jinja2_interop.py
new file mode 100644 (file)
index 0000000..ff04df1
--- /dev/null
@@ -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()
diff --git a/tox.ini b/tox.ini
index cdb2514e207fd586b8f9cd366afc3d1c4f824d28..70e5e7ed24905cd4d2b79690ef54929fa849fdb7 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -5,6 +5,7 @@ envlist =
     pypy3
     py{38}-pytz
     py{311,312}-setuptools
+    py312-jinja
 
 [testenv]
 extras =
@@ -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 =