Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧪 TESTS: Add for gettext_additional_targets #459

Merged
merged 9 commits into from
Dec 11, 2021
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ coverage.xml
# Translations
*.mo
*.pot
!tests/**/*.pot

# Django stuff:
*.log
Expand Down
127 changes: 127 additions & 0 deletions tests/test_sphinx/sourcedirs/gettext/fr/LC_MESSAGES/index.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) XXXX, Executable Book Project
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
"PO-Revision-Date: 2000-01-01 00:00+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "**bold** text 1"
msgstr "texte 1 en **gras**"

msgid "**bold** text 2"
msgstr "texte 2 en **gras**"

msgid "**bold** text 3"
msgstr "texte 3 en **gras**"

msgid "**bold** text 4"
msgstr "texte 4 en **gras**"

msgid "**bold** text 5"
msgstr "texte 5 en **gras**"

msgid "**bold** text 6"
msgstr "texte 6 en **gras**"

msgid "**bold** text 7"
msgstr "texte 7 en **gras**"

msgid "**bold** text 8"
msgstr "texte 8 en **gras**"

msgid "**bold** text 9"
msgstr "texte 9 en **gras**"

msgid "**bold** text 10"
msgstr "texte 10 en **gras**"

msgid "<div markdown=1>\n"
""
msgstr "<span markdown=1>\n"
""

msgid "**bold** text 11"
msgstr "texte 11 en **gras**"

msgid "Extra ```backticks```"
msgstr "\"```Backtick```\" supplémentaire"

msgid "</div>\n"
""
msgstr "</span>\n"
""

msgid "**additional** text 12\n"
""
msgstr "texte 12 **supplémentaire**\n"
""

msgid "**additional** text 13\n"
""
msgstr "texte 13 **supplémentaire**\n"
""

msgid "{\n"
" \"additional\": \"text 14\"\n"
"}\n"
""
msgstr "{\n"
" \"supplémentaire\": \"texte 14\"\n"
"}\n"
""

msgid "<h3>**additional** text 15</h3>\n"
""
msgstr "<h3>texte 15 **supplémentaire**</h3>\n"
""

msgid ">>> print('doctest block')\n"
"doctest block\n"
""
msgstr ">>> print('bloque doctest')\n"
"'bloque doctest\n"
""

msgid "<iframe src=\"http://sphinx-doc.org\"></iframe>"
msgstr "<iframe src=\"http://sphinx-doc.org/fr/master/\"></iframe>"

msgid "![Fun Fish 1](fun-fish.png)"
msgstr "![Poisson amusant 1](poisson-amusant.png)"

msgid "Fun Fish 1"
msgstr "Poisson amusant 1"

msgid ".. image:: fun-fish.png"
msgstr ".. image:: poisson-amusant.png"

msgid "Fun Fish 2"
msgstr "Poisson amusant 2"

msgid "Fun Fish 3"
msgstr "Poisson amusant 3"

msgid ".. image:: fun-fish.png\n"
" :alt: Fun Fish 1"
msgstr ".. image:: poisson-amusant.png\n"
" :alt: Poisson amusant 1"

msgid ".. image:: fun-fish.png\n"
" :alt: Fun Fish 2"
msgstr ".. image:: poisson-amusant.png\n"
" :alt: Poisson amusant 2"

msgid ".. image:: fun-fish.png\n"
" :alt: Fun Fish 3"
msgstr ".. image:: poisson-amusant.png\n"
" :alt: Poisson amusant 3"
Binary file added tests/test_sphinx/sourcedirs/gettext/fun-fish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 23 additions & 4 deletions tests/test_sphinx/sourcedirs/gettext/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,35 @@ Extra ```backticks```

</div>

**skip** text
**additional** text 12

```
**skip** text
**additional** text 13
```

```json
{
"skip": "text"
"additional": "text 14"
}
```

<h3>**skip** text</h3>
<h3>**additional** text 15</h3>

```python
>>> print('doctest block')
doctest block
```

```{raw} html
<iframe src="http://sphinx-doc.org"></iframe>
```

![Fun Fish 1](fun-fish.png)

```{image} fun-fish.png
:alt: Fun Fish 2
```

```{figure} fun-fish.png
:alt: Fun Fish 3
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 79 additions & 1 deletion tests/test_sphinx/test_sphinx_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,85 @@ def test_gettext(
output = re.sub(r"POT-Creation-Date: [0-9: +-]+", "POT-Creation-Date: ", output)
output = re.sub(r"Copyright \(C\) [0-9]{4}", "Copyright (C) XXXX", output)

file_regression.check(output, extension=".pot")
file_regression.check(output, extension=f".sphinx{sphinx.version_info[0]}.pot")


@pytest.mark.sphinx(
buildername="html",
srcdir=os.path.join(SOURCE_DIR, "gettext"),
freshenv=True,
confoverrides={"language": "fr", "gettext_compact": False, "locale_dirs": ["."]},
)
def test_gettext_html(
app,
status,
warning,
get_sphinx_app_doctree,
get_sphinx_app_output,
remove_sphinx_builds,
):
"""Test gettext message extraction."""
app.build()
assert "build succeeded" in status.getvalue() # Build succeeded
warnings = warning.getvalue().strip()
assert warnings == ""

try:
get_sphinx_app_doctree(
app,
docname="index",
regress=True,
regress_ext=f".sphinx{sphinx.version_info[0]}.xml",
)
finally:
get_sphinx_app_doctree(
app,
docname="index",
resolve=True,
regress=True,
regress_ext=f".sphinx{sphinx.version_info[0]}.xml",
)
get_sphinx_app_output(
app,
filename="index.html",
regress_html=True,
regress_ext=f".sphinx{sphinx.version_info[0]}.html",
)


@pytest.mark.sphinx(
buildername="gettext",
srcdir=os.path.join(SOURCE_DIR, "gettext"),
freshenv=True,
confoverrides={
"gettext_additional_targets": [
"index",
"literal-block",
"doctest-block",
"raw",
"image",
],
},
)
def test_gettext_additional_targets(
app,
status,
warning,
get_sphinx_app_output,
remove_sphinx_builds,
file_regression,
):
"""Test gettext message extraction."""
app.build()
assert "build succeeded" in status.getvalue() # Build succeeded
warnings = warning.getvalue().strip()
assert warnings == ""

output = get_sphinx_app_output(app, filename="index.pot", buildername="gettext")
output = re.sub(r"POT-Creation-Date: [0-9: +-]+", "POT-Creation-Date: ", output)
output = re.sub(r"Copyright \(C\) [0-9]{4}", "Copyright (C) XXXX", output)

file_regression.check(output, extension=f".sphinx{sphinx.version_info[0]}.pot")


@pytest.mark.sphinx(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ msgstr ""
#: ../../index.md:28
msgid "Extra ```backticks```"
msgstr ""

#: ../../index.md:55
msgid "![Fun Fish 1](fun-fish.png)"
msgstr ""
81 changes: 81 additions & 0 deletions tests/test_sphinx/test_sphinx_builds/test_gettext.sphinx4.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) XXXX, Executable Book Project
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: ../../index.md:1
msgid "**bold** text 1"
msgstr ""

#: ../../index.md:3
msgid "**bold** text 2"
msgstr ""

#: ../../index.md:5
msgid "**bold** text 3"
msgstr ""

#: ../../index.md:10
msgid "**bold** text 4"
msgstr ""

#: ../../index.md:13
msgid "**bold** text 5"
msgstr ""

#: ../../index.md:15
msgid "**bold** text 6"
msgstr ""

#: ../../index.md:17
msgid "**bold** text 7"
msgstr ""

#: ../../index.md:18
msgid "**bold** text 8"
msgstr ""

#: ../../index.md:0
msgid "**bold** text 9"
msgstr ""

#: ../../index.md:0
msgid "**bold** text 10"
msgstr ""

#: ../../index.md:26
msgid "**bold** text 11"
msgstr ""

#: ../../index.md:28
msgid "Extra ```backticks```"
msgstr ""

#: ../../index.md:55
msgid "![Fun Fish 1](fun-fish.png)"
msgstr ""

#: ../../index.md:55
msgid "Fun Fish 1"
msgstr ""

#: ../../index.md:57
msgid "Fun Fish 2"
msgstr ""

#: ../../index.md:61
msgid "Fun Fish 3"
msgstr ""
Loading