3
3
"""
4
4
5
5
import subprocess
6
+ import sys
6
7
from pathlib import Path
7
8
from textwrap import dedent
8
9
@@ -26,7 +27,9 @@ def test_prompt_specified_late(tmp_path: Path) -> None:
26
27
conf_py .write_text (conf_py_content )
27
28
destination_directory = tmp_path / 'destination'
28
29
args = [
29
- 'sphinx-build' ,
30
+ sys .executable ,
31
+ '-m' ,
32
+ 'sphinx' ,
30
33
'-b' ,
31
34
'html' ,
32
35
'-W' ,
@@ -83,7 +86,58 @@ def test_substitution_prompt(tmp_path: Path) -> None:
83
86
source_file .write_text (source_file_content )
84
87
destination_directory = tmp_path / 'destination'
85
88
args = [
86
- 'sphinx-build' ,
89
+ sys .executable ,
90
+ '-m' ,
91
+ 'sphinx' ,
92
+ '-b' ,
93
+ 'html' ,
94
+ '-W' ,
95
+ # Directory containing source and configuration files.
96
+ str (source_directory ),
97
+ # Directory containing build files.
98
+ str (destination_directory ),
99
+ # Source file to process.
100
+ str (source_file ),
101
+ ]
102
+ subprocess .check_output (args = args )
103
+ expected = 'PRE-example_substitution-POST'
104
+ content_html = Path (str (destination_directory )) / 'index.html'
105
+ assert expected in content_html .read_text ()
106
+
107
+
108
+ def test_substitution_prompt_is_case_preserving (tmp_path : Path ) -> None :
109
+ """
110
+ The ``prompt`` directive respects the original case of replacements.
111
+ """
112
+ source_directory = tmp_path / 'source'
113
+ source_directory .mkdir ()
114
+ source_file = source_directory / 'index.rst'
115
+ conf_py = source_directory / 'conf.py'
116
+ conf_py .touch ()
117
+ source_file .touch ()
118
+ conf_py_content = dedent (
119
+ """\
120
+ extensions = ['sphinx-prompt', 'sphinx_substitution_extensions']
121
+ rst_prolog = '''
122
+ .. |aBcD_eFgH| replace:: example_substitution
123
+ '''
124
+ """ ,
125
+ )
126
+ conf_py .write_text (conf_py_content )
127
+ source_file_content = dedent (
128
+ """\
129
+ .. prompt:: bash $
130
+ :substitutions:
131
+
132
+ $ PRE-|aBcD_eFgH|-POST
133
+ """ ,
134
+ )
135
+ source_file .write_text (source_file_content )
136
+ destination_directory = tmp_path / 'destination'
137
+ args = [
138
+ sys .executable ,
139
+ '-m' ,
140
+ 'sphinx' ,
87
141
'-b' ,
88
142
'html' ,
89
143
'-W' ,
@@ -130,7 +184,9 @@ def test_no_substitution_prompt(tmp_path: Path) -> None:
130
184
source_file .write_text (source_file_content )
131
185
destination_directory = tmp_path / 'destination'
132
186
args = [
133
- 'sphinx-build' ,
187
+ sys .executable ,
188
+ '-m' ,
189
+ 'sphinx' ,
134
190
'-b' ,
135
191
'html' ,
136
192
'-W' ,
@@ -177,7 +233,9 @@ def test_no_substitution_code_block(tmp_path: Path) -> None:
177
233
source_file .write_text (source_file_content )
178
234
destination_directory = tmp_path / 'destination'
179
235
args = [
180
- 'sphinx-build' ,
236
+ sys .executable ,
237
+ '-m' ,
238
+ 'sphinx' ,
181
239
'-b' ,
182
240
'html' ,
183
241
'-W' ,
@@ -225,7 +283,58 @@ def test_substitution_code_block(tmp_path: Path) -> None:
225
283
source_file .write_text (source_file_content )
226
284
destination_directory = tmp_path / 'destination'
227
285
args = [
228
- 'sphinx-build' ,
286
+ sys .executable ,
287
+ '-m' ,
288
+ 'sphinx' ,
289
+ '-b' ,
290
+ 'html' ,
291
+ '-W' ,
292
+ # Directory containing source and configuration files.
293
+ str (source_directory ),
294
+ # Directory containing build files.
295
+ str (destination_directory ),
296
+ # Source file to process.
297
+ str (source_file ),
298
+ ]
299
+ subprocess .check_output (args = args )
300
+ expected = 'PRE-example_substitution-POST'
301
+ content_html = Path (str (destination_directory )) / 'index.html'
302
+ assert expected in content_html .read_text ()
303
+
304
+
305
+ def test_substitution_code_block_case_preserving (tmp_path : Path ) -> None :
306
+ """
307
+ The ``code-block`` directive respects the original case of replacements.
308
+ """
309
+ source_directory = tmp_path / 'source'
310
+ source_directory .mkdir ()
311
+ source_file = source_directory / 'index.rst'
312
+ conf_py = source_directory / 'conf.py'
313
+ conf_py .touch ()
314
+ source_file .touch ()
315
+ conf_py_content = dedent (
316
+ """\
317
+ extensions = ['sphinx-prompt', 'sphinx_substitution_extensions']
318
+ rst_prolog = '''
319
+ .. |aBcD_eFgH| replace:: example_substitution
320
+ '''
321
+ """ ,
322
+ )
323
+ conf_py .write_text (conf_py_content )
324
+ source_file_content = dedent (
325
+ """\
326
+ .. code-block:: bash
327
+ :substitutions:
328
+
329
+ $ PRE-|aBcD_eFgH|-POST
330
+ """ ,
331
+ )
332
+ source_file .write_text (source_file_content )
333
+ destination_directory = tmp_path / 'destination'
334
+ args = [
335
+ sys .executable ,
336
+ '-m' ,
337
+ 'sphinx' ,
229
338
'-b' ,
230
339
'html' ,
231
340
'-W' ,
@@ -270,7 +379,9 @@ def test_substitution_inline(tmp_path: Path) -> None:
270
379
source_file .write_text (source_file_content )
271
380
destination_directory = tmp_path / 'destination'
272
381
args = [
273
- 'sphinx-build' ,
382
+ sys .executable ,
383
+ '-m' ,
384
+ 'sphinx' ,
274
385
'-b' ,
275
386
'html' ,
276
387
'-W' ,
0 commit comments