Skip to content

Commit 21f1877

Browse files
authored
Merge branch 'master' into TST_fail_on_warnings
2 parents 5069dce + 6ee8d01 commit 21f1877

File tree

6 files changed

+131
-2
lines changed

6 files changed

+131
-2
lines changed

myst_nb/sphinx_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def parse(self, inputstring: str, document: nodes.document) -> None:
8484
# create a reader for the notebook
8585
nb_reader = create_nb_reader(document_path, md_config, nb_config, inputstring)
8686
# If the nb_reader is None, then we default to a standard Markdown parser
87-
if nb_reader is None:
87+
if nb_reader is None or document.current_source.endswith("<translated>"):
8888
return super().parse(inputstring, document)
8989
notebook = nb_reader.read(inputstring)
9090

tests/conftest.py

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44
import re
55
import uuid
6+
import shutil
67

78
import bs4
89
from docutils.nodes import image as image_node
@@ -192,6 +193,8 @@ def sphinx_run(sphinx_params, make_app, tmp_path):
192193
)
193194
+ "\n"
194195
)
196+
if "language" in conf:
197+
shutil.copytree(TEST_FILE_DIR / "locale", srcdir / "locale")
195198

196199
for nb_file in sphinx_params["files"]:
197200
nb_path = TEST_FILE_DIR.joinpath(nb_file)
@@ -293,6 +296,9 @@ class FileRegression:
293296
re.escape(" translation_progress=\"{'total': 0, 'translated': 0}\""),
294297
# TODO: Remove when support for Sphinx<7.2 is dropped,
295298
r"original_uri=\"[^\"]*\"\s",
299+
# TODO: Remove when support for Sphinx<8 is dropped,
300+
re.escape(' translated="True"'),
301+
re.escape(" translation_progress=\"{'total': 4, 'translated': 2}\""),
296302
)
297303

298304
def __init__(self, file_regression):

tests/notebooks/basic_run_intl.ipynb

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# a title\n",
8+
"\n",
9+
"some text\n"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 1,
15+
"metadata": {},
16+
"source": [
17+
"a=1\n",
18+
"print(a)"
19+
],
20+
"outputs": [
21+
{
22+
"name": "stdout",
23+
"output_type": "stream",
24+
"text": [
25+
"1\n"
26+
]
27+
}
28+
]
29+
}
30+
],
31+
"metadata": {
32+
"test_name": "notebook1",
33+
"kernelspec": {
34+
"display_name": "Python 3",
35+
"language": "python",
36+
"name": "python3"
37+
},
38+
"language_info": {
39+
"codemirror_mode": {
40+
"name": "ipython",
41+
"version": 3
42+
},
43+
"file_extension": ".py",
44+
"mimetype": "text/x-python",
45+
"name": "python",
46+
"nbconvert_exporter": "python",
47+
"pygments_lexer": "ipython3",
48+
"version": "3.6.1"
49+
}
50+
},
51+
"nbformat": 4,
52+
"nbformat_minor": 2
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C)
3+
# This file is distributed under the same license as the Project name not set package.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5+
#
6+
#, fuzzy
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version: Project name not set \n"
10+
"Report-Msgid-Bugs-To: \n"
11+
"POT-Creation-Date: 2024-09-21 23:48+0200\n"
12+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14+
"Language-Team: LANGUAGE <[email protected]>\n"
15+
"MIME-Version: 1.0\n"
16+
"Content-Type: text/plain; charset=UTF-8\n"
17+
"Content-Transfer-Encoding: 8bit\n"
18+
19+
#: ../tests/notebooks/basic_run_intl.ipynb:10002
20+
msgid "a title"
21+
msgstr "un título"
22+
23+
#: ../tests/notebooks/basic_run_intl.ipynb:10004
24+
msgid "some text"
25+
msgstr "algo de texto"

tests/test_parser.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
@pytest.mark.sphinx_params("basic_run.ipynb", conf={"nb_execution_mode": "off"})
99
def test_basic_run(sphinx_run, file_regression):
1010
sphinx_run.build()
11-
# print(sphinx_run.status())
1211
assert sphinx_run.warnings() == ""
1312
assert set(sphinx_run.env.metadata["basic_run"].keys()) == {
1413
"test_name",
@@ -36,6 +35,38 @@ def test_basic_run(sphinx_run, file_regression):
3635
assert filenames == {"basic_run.ipynb"}
3736

3837

38+
@pytest.mark.sphinx_params(
39+
"basic_run_intl.ipynb", conf={"language": "es", "locale_dirs": ["locale"]}
40+
)
41+
def test_basic_run_intl(sphinx_run, file_regression):
42+
sphinx_run.build()
43+
assert sphinx_run.warnings() == ""
44+
assert set(sphinx_run.env.metadata["basic_run_intl"].keys()) == {
45+
"test_name",
46+
"wordcount",
47+
"kernelspec",
48+
"language_info",
49+
}
50+
assert set(sphinx_run.env.nb_metadata["basic_run_intl"].keys()) == set()
51+
assert sphinx_run.env.metadata["basic_run_intl"]["test_name"] == "notebook1"
52+
assert sphinx_run.env.metadata["basic_run_intl"]["kernelspec"] == {
53+
"display_name": "Python 3",
54+
"language": "python",
55+
"name": "python3",
56+
}
57+
file_regression.check(
58+
sphinx_run.get_doctree().pformat(), extension=".xml", encoding="utf-8"
59+
)
60+
61+
filenames = {
62+
p.name
63+
for p in Path(
64+
os.fspath(sphinx_run.app.srcdir / "_build" / "jupyter_execute")
65+
).iterdir()
66+
}
67+
assert filenames == {"basic_run_intl.ipynb"}
68+
69+
3970
@pytest.mark.sphinx_params("complex_outputs.ipynb", conf={"nb_execution_mode": "off"})
4071
def test_complex_outputs(sphinx_run, file_regression):
4172
sphinx_run.build()
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<document source="basic_run_intl">
2+
<section ids="a-title" names="a\ title un\ título">
3+
<title>
4+
un título
5+
<paragraph>
6+
algo de texto
7+
<container cell_index="1" cell_metadata="{}" classes="cell" exec_count="1" nb_element="cell_code">
8+
<container classes="cell_input" nb_element="cell_code_source">
9+
<literal_block language="ipython3" xml:space="preserve">
10+
a=1
11+
print(a)
12+
<container classes="cell_output" nb_element="cell_code_output">
13+
<literal_block classes="output stream" language="myst-ansi" xml:space="preserve">
14+
1

0 commit comments

Comments
 (0)