Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_include.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 #! /usr/bin/env python3
2 # $Id: test_include.py 10308 2026-03-28 18:54:25Z milde $
3 # Author: David Goodger <[email protected]>
4 # Copyright: This module has been placed in the public domain.
5
6 """
7 Tests for misc.py "include" directive.
8 """
9
10 from pathlib import Path
11 import os.path
12 import unittest
13 import sys
14
15 if __name__ == '__main__':
16 # prepend the "docutils root" to the Python library path
17 # so we import the local `docutils` package.
18 sys.path.insert(0, str(Path(__file__).resolve().parents[4]))
19
•20 import docutils
21 from docutils import core, parsers, utils
22 from docutils.frontend import get_default_settings
23 from docutils.parsers.rst import Parser
24 from docutils.utils import new_document
25 from docutils.utils.code_analyzer import with_pygments
26 from test.test_parsers.test_rst.test_directives.test_code \
27 import PYGMENTS_2_14_PLUS
28
29 FILE_DIR = Path(__file__).resolve().parent
30 TEST_ROOT = FILE_DIR.parents[2]
31
32 # optional 3rd-party markdown parser
33 md_parser_name = 'pycmark'
34 try: # check availability
35 md_parser_class = parsers.get_parser_class(md_parser_name)
36 except ImportError:
37 md_parser_class = None
38
39
40 class ParserTestCase(unittest.TestCase):
41 maxDiff = None
42
43 def test_parser(self):
44 parser = Parser()
45 settings = get_default_settings(Parser)
46 settings.warning_stream = ''
47 settings.halt_level = 5
48 settings.legacy_ids = False
49 for name, cases in totest.items():
50 if name == 'with transforms':
51 continue # see test_publish() below
52 for casenum, (case_input, case_expected) in enumerate(cases):
53 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
54 # eventually skip optional parts:
55 if name == 'include_markdown' and not md_parser_class:
56 self.skipTest('no markdown parser available')
57 if name == 'include_parsed_code' and not with_pygments:
58 self.skipTest('syntax highlight requires pygments')
59 document = new_document('test data', settings.copy())
60 parser.parse(case_input, document)
61 output = document.pformat()
62 self.assertEqual(case_expected, output)
63
64 def test_publish(self):
65 # Special case for tests of issue reporting.
66 # To see the system message from the duplicate id, we need transforms.
67 settings = {'_disable_config': True,
68 'output_encoding': 'unicode',
69 'warning_stream': '',
70 }
71 name = 'with transforms'
72 for casenum, (sample, expected) in enumerate(totest[name]):
73 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
74 output = core.publish_string(sample,
75 source_path='test data',
76 parser=Parser(),
77 settings_overrides=settings)
78 self.assertEqual(expected, output)
79
80
81 try:
82 chr(0x11111111)
83 except ValueError as detail:
84 unichr_exception = f'{detail.__class__.__name__}: {detail}'
85 else:
86 unichr_exception = ''
87
88
89 # prepend this directory (relative to the cwd):
90 def mydir(path):
91 return os.path.relpath(os.path.join(FILE_DIR, path),
92 os.getcwd()).replace('\\', '/')
93
94
95 include1 = mydir('include1.rst')
96 include2 = mydir('include2.rst')
97 include3 = mydir('include3.rst')
98 include5 = mydir('includes/include5.rst')
99 include6 = mydir('includes/more/include6.rst')
100 include8 = mydir('include8.rst')
101 include10 = mydir('include10.rst')
102 include11 = mydir('include 11.rst')
103 include12 = mydir('include12.rst')
104 include13 = mydir('include13.rst')
105 include14 = mydir('includes/include14.rst')
106 include15 = mydir('includes/include15.rst')
107 include16 = mydir('includes/include16.rst')
108 include_literal = mydir('include_literal.rst')
109 include_md = mydir('include.md')
110 include_xml = mydir('includes/include.xml')
111 include = TEST_ROOT/'data/include.rst'
112 latin2 = TEST_ROOT/'data/latin2.rst'
113 utf_16_file = TEST_ROOT/'data/utf-16-le-sig.rst'
114 utf_16_error_str = ("UnicodeDecodeError: 'ascii' codec can't decode byte 0xff "
115 "in position 0: ordinal not in range(128)")
•116 rst_states_dir = docutils._datadir(parsers.rst.states.__file__)
117 # TODO fix case normalisation bug on Windows in utils.relative_path()
118 # nonexistent = os.path.relpath(
119 # os.path.join(rst_states_dir, 'include', 'nonexistent'),
120 # os.getcwd()).replace('\\', '/')
121 nonexistent = utils.relative_path(
122 os.path.join(os.getcwd(), 'dummy'),
123 os.path.join(rst_states_dir, 'include', 'nonexistent')
124 )
125
126 # Different error for path with 8bit chars with locale == C or None:
127 try:
128 open('\u043c\u0438\u0440.rst')
129 except UnicodeEncodeError:
130 errstr_8bit_path = """\
131 Cannot encode input file path "\u043c\u0438\u0440.rst" (wrong locale?).\
132 """
133 except FileNotFoundError:
134 errstr_8bit_path = """\
135 InputError: [Errno 2] No such file or directory: '\u043c\u0438\u0440.rst'.\
136 """
137
138 totest = {}
139
140 totest['include'] = [
141 [f"""\
142 Include Test
143 ============
144
145 .. include:: {include1}
146
147 A paragraph.
148 """,
149 """\
150 <document source="test data">
151 <section names="include\\ test">
152 <title>
153 Include Test
154 <section names="inclusion\\ 1">
155 <title>
156 Inclusion 1
157 <paragraph>
158 This file is used by \n\
159 <literal>
160 test_include.py
161 .
162 <paragraph>
163 A paragraph.
164 """],
165 [f"""\
166 Include Test
167 ============
168
169 .. include:: {include1}
170 :literal:
171 :class: test
172 :name: my name
173
174 A paragraph.
175 """,
176 f"""\
177 <document source="test data">
178 <section names="include\\ test">
179 <title>
180 Include Test
181 <literal_block classes="test" ids="my-name" names="my\\ name" source="{include1}" xml:space="preserve">
182 Inclusion 1
183 -----------
184 \n\
185 This file is used by ``test_include.py``.
186 <paragraph>
187 A paragraph.
188 """],
189 [f"""\
190 Literal include, add line numbers
191
192 .. include:: {include1}
193 :literal:
194 :number-lines:
195 """,
196 f"""\
197 <document source="test data">
198 <paragraph>
199 Literal include, add line numbers
200 <literal_block source="{include1}" xml:space="preserve">
201 <inline classes="ln">
202 1 \n\
203 Inclusion 1
204 <inline classes="ln">
205 2 \n\
206 -----------
207 <inline classes="ln">
208 3 \n\
209 \n\
210 <inline classes="ln">
211 4 \n\
212 This file is used by ``test_include.py``.
213 """],
214 [f"""\
215 Literal include, add line numbers
216
217 .. include:: {include1}
218 :literal:
219 :start-line: 2
220 :number-lines: 0
221 """,
222 f"""\
223 <document source="test data">
224 <paragraph>
225 Literal include, add line numbers
226 <literal_block source="{include1}" xml:space="preserve">
227 <inline classes="ln">
228 0 \n\
229 \n\
230 <inline classes="ln">
231 1 \n\
232 This file is used by ``test_include.py``.
233 """],
234 [f"""\
235 Include code
236
237 .. include:: {include1}
238 :code:
239 :class: test
240 :name: my name
241 """,
242 f"""\
243 <document source="test data">
244 <paragraph>
245 Include code
246 <literal_block classes="code test" ids="my-name" names="my\\ name" source="{include1}" xml:space="preserve">
247 Inclusion 1
248 -----------
249 \n\
250 This file is used by ``test_include.py``.
251 """],
252 [f"""\
253 Include code, add line numbers
254
255 .. include:: {include1}
256 :code:
257 :number-lines:
258 """,
259 f"""\
260 <document source="test data">
261 <paragraph>
262 Include code, add line numbers
263 <literal_block classes="code" source="{include1}" xml:space="preserve">
264 <inline classes="ln">
265 1 \n\
266 Inclusion 1
267 <inline classes="ln">
268 2 \n\
269 -----------
270 <inline classes="ln">
271 3 \n\
272 \n\
273 <inline classes="ln">
274 4 \n\
275 This file is used by ``test_include.py``.
276 """],
277 [f"""\
278 Include with unknown parser.
279
280 .. include:: {include1}
281 :parser: sillyformat
282
283 A paragraph.
284 """,
285 f"""\
286 <document source="test data">
287 <paragraph>
288 Include with unknown parser.
289 <system_message level="3" line="3" source="test data" type="ERROR">
290 <paragraph>
291 Error in "include" directive:
292 invalid option value: (option: "parser"; value: \'sillyformat\')
293 Parser "sillyformat" not found. No module named 'sillyformat'.
294 <literal_block xml:space="preserve">
295 .. include:: {include1}
296 :parser: sillyformat
297 <paragraph>
298 A paragraph.
299 """],
300 [f"""\
301 Let's test the parse context.
302
303 This paragraph is in a block quote.
304
305 .. include:: {include2}
306
307 The included paragraphs should also be in the block quote.
308 """,
309 """\
310 <document source="test data">
311 <paragraph>
312 Let's test the parse context.
313 <block_quote>
314 <paragraph>
315 This paragraph is in a block quote.
316 <paragraph>
317 Here are some paragraphs
318 that can appear at any level.
319 <paragraph>
320 This file (include2.rst) is used by
321 <literal>
322 test_include.py
323 .
324 <paragraph>
325 The included paragraphs should also be in the block quote.
326 """],
327 ["""\
328 Include Test
329 ============
330
331 .. include:: nonexistent.rst
332
333 A paragraph.
334 """,
335 """\
336 <document source="test data">
337 <section names="include\\ test">
338 <title>
339 Include Test
340 <system_message level="3" line="4" source="test data" type="ERROR">
341 <paragraph>
342 Problems with "include" directive path:
343 InputError: [Errno 2] No such file or directory: 'nonexistent.rst'.
344 <literal_block xml:space="preserve">
345 .. include:: nonexistent.rst
346 <paragraph>
347 A paragraph.
348 """],
349 [f"""\
350 Include Test
351 ============
352
353 .. include:: {include1}
354
355 .. include:: {include1}
356
357 A paragraph.
358 """,
359 f"""\
360 <document source="test data">
361 <section names="include\\ test">
362 <title>
363 Include Test
364 <section dupnames="inclusion\\ 1" ids="inclusion-1-1">
365 <title>
366 Inclusion 1
367 <paragraph>
368 This file is used by \n\
369 <literal>
370 test_include.py
371 .
372 <section dupnames="inclusion\\ 1" ids="inclusion-1-2">
373 <title>
374 Inclusion 1
375 <system_message backrefs="inclusion-1-2" level="1" line="2" source="{include1}" type="INFO">
376 <paragraph>
377 Duplicate implicit target name: "inclusion 1".
378 <paragraph>
379 This file is used by \n\
380 <literal>
381 test_include.py
382 .
383 <paragraph>
384 A paragraph.
385 """],
386 [f"""\
387 Include Test
388 ============
389
390 .. include:: {include1}
391
392 ----------
393
394 .. include:: {include1}
395
396 A paragraph.
397 """,
398 f"""\
399 <document source="test data">
400 <section names="include\\ test">
401 <title>
402 Include Test
403 <section dupnames="inclusion\\ 1" ids="inclusion-1-1">
404 <title>
405 Inclusion 1
406 <paragraph>
407 This file is used by \n\
408 <literal>
409 test_include.py
410 .
411 <transition>
412 <section dupnames="inclusion\\ 1" ids="inclusion-1-2">
413 <title>
414 Inclusion 1
415 <system_message backrefs="inclusion-1-2" level="1" line="2" source="{include1}" type="INFO">
416 <paragraph>
417 Duplicate implicit target name: "inclusion 1".
418 <paragraph>
419 This file is used by \n\
420 <literal>
421 test_include.py
422 .
423 <paragraph>
424 A paragraph.
425 """],
426 [f"""\
427 Recursive inclusions: adapt paths.
428
429 In test data
430
431 .. include:: {include3}
432 """,
433 f"""\
434 <document source="test data">
435 <paragraph>
436 Recursive inclusions: adapt paths.
437 <paragraph>
438 In test data
439 <paragraph>
440 In include3.rst
441 <paragraph>
442 In includes/include4.rst
443 <paragraph>
444 In includes/include5.rst
445 <paragraph>
446 In includes/more/include6.rst
447 <paragraph>
448 In includes/sibling/include7.rst
449 <literal_block source="{include5}" xml:space="preserve">
450 In includes/include5.rst
451 \n\
452 .. include:: more/include6.rst
453 <table>
454 <tgroup cols="2">
455 <colspec colwidth="50">
456 <colspec colwidth="50">
457 <tbody>
458 <row>
459 <entry>
460 <paragraph>
461 In
462 <entry>
463 <paragraph>
464 includes/sibling/include7.rst
465 """],
466 [f"""\
467 Recursive inclusion with specified parser.
468
469 In test data
470
471 .. include:: {include3}
472 :parser: rst
473 """,
474 f"""\
475 <document source="test data">
476 <paragraph>
477 Recursive inclusion with specified parser.
478 <paragraph>
479 In test data
480 <paragraph>
481 In include3.rst
482 <paragraph>
483 In includes/include4.rst
484 <paragraph>
485 In includes/include5.rst
486 <paragraph>
487 In includes/more/include6.rst
488 <paragraph>
489 In includes/sibling/include7.rst
490 <literal_block source="{include5}" xml:space="preserve">
491 In includes/include5.rst
492 \n\
493 .. include:: more/include6.rst
494 <table>
495 <tgroup cols="2">
496 <colspec colwidth="50">
497 <colspec colwidth="50">
498 <tbody>
499 <row>
500 <entry>
501 <paragraph>
502 In
503 <entry>
504 <paragraph>
505 includes/sibling/include7.rst
506 """],
507 [f"""\
508 In test data
509
510 Section
511 =======
512
513 (Section contents in nested parse; slice of input_lines ViewList.)
514
515 .. include:: {include3}
516 """,
517 f"""\
518 <document source="test data">
519 <paragraph>
520 In test data
521 <section names="section">
522 <title>
523 Section
524 <paragraph>
525 (Section contents in nested parse; slice of input_lines ViewList.)
526 <paragraph>
527 In include3.rst
528 <paragraph>
529 In includes/include4.rst
530 <paragraph>
531 In includes/include5.rst
532 <paragraph>
533 In includes/more/include6.rst
534 <paragraph>
535 In includes/sibling/include7.rst
536 <literal_block source="{include5}" xml:space="preserve">
537 In includes/include5.rst
538 \n\
539 .. include:: more/include6.rst
540 <table>
541 <tgroup cols="2">
542 <colspec colwidth="50">
543 <colspec colwidth="50">
544 <tbody>
545 <row>
546 <entry>
547 <paragraph>
548 In
549 <entry>
550 <paragraph>
551 includes/sibling/include7.rst
552 """],
553 [f"""\
554 Testing relative includes:
555
556 .. include:: {include8}
557 """,
558 """\
559 <document source="test data">
560 <paragraph>
561 Testing relative includes:
562 <paragraph>
563 In include8.rst
564 <paragraph>
565 In ../includes/include9.rst.
566 <paragraph>
567 Here are some paragraphs
568 that can appear at any level.
569 <paragraph>
570 This file (include2.rst) is used by
571 <literal>
572 test_include.py
573 .
574 """],
575 [f"""\
576 Encoding:
577
578 .. include:: {utf_16_file}
579 :encoding: utf-16
580 """,
581 """\
582 <document source="test data">
583 <paragraph>
584 Encoding:
585 <paragraph>
586 Grüße
587 """],
588 [f"""\
589 Include file is UTF-16-encoded, and is not valid ASCII.
590
591 .. include:: {utf_16_file}
592 :encoding: ascii
593 """,
594 f"""\
595 <document source="test data">
596 <paragraph>
597 Include file is UTF-16-encoded, and is not valid ASCII.
598 <system_message level="3" line="3" source="test data" type="ERROR">
599 <paragraph>
600 Problem with "include" directive:
601 {utf_16_error_str}
602 <literal_block xml:space="preserve">
603 .. include:: {utf_16_file}
604 :encoding: ascii
605 """],
606 ["""\
607 cyrillic filename:
608
609 .. include:: \u043c\u0438\u0440.rst
610 """,
611 f"""\
612 <document source="test data">
613 <paragraph>
614 cyrillic filename:
615 <system_message level="3" line="3" source="test data" type="ERROR">
616 <paragraph>
617 Problems with "include" directive path:
618 {errstr_8bit_path}
619 <literal_block xml:space="preserve">
620 .. include:: \u043c\u0438\u0440.rst
621 """],
622 [f"""\
623 Testing errors in included file:
624
625 .. include:: {include10}
626 """,
627 f"""\
628 <document source="test data">
629 <paragraph>
630 Testing errors in included file:
631 <system_message level="3" line="1" source="{include10}" type="ERROR">
632 <paragraph>
633 Invalid character code: 0x11111111
634 {unichr_exception}
635 <literal_block xml:space="preserve">
636 unicode:: 0x11111111
637 <system_message level="2" line="1" source="{include10}" type="WARNING">
638 <paragraph>
639 Substitution definition "bad" empty or invalid.
640 <literal_block xml:space="preserve">
641 .. |bad| unicode:: 0x11111111
642 <section dupnames="hi" ids="hi-1">
643 <title>
644 hi
645 <block_quote>
646 <paragraph>
647 indent
648 <system_message level="2" line="7" source="{include10}" type="WARNING">
649 <paragraph>
650 Block quote ends without a blank line; unexpected unindent.
651 <paragraph>
652 error
653 <section dupnames="hi" ids="hi-2">
654 <title>
655 hi
656 <system_message backrefs="hi-2" level="1" line="10" source="{include10}" type="INFO">
657 <paragraph>
658 Duplicate implicit target name: "hi".
659 <system_message level="3" line="12" source="{include10}" type="ERROR">
660 <paragraph>
661 Problems with "include" directive path:
662 InputError: [Errno 2] No such file or directory: '{nonexistent}'.
663 <literal_block xml:space="preserve">
664 .. include:: <nonexistent>
665 <system_message level="3" line="14" source="{include10}" type="ERROR">
666 <paragraph>
667 Content block expected for the "note" directive; none found.
668 <literal_block xml:space="preserve">
669 .. note::
670 <system_message level="3" line="16" source="{include10}" type="ERROR">
671 <paragraph>
672 Content block expected for the "admonition" directive; none found.
673 <literal_block xml:space="preserve">
674 .. admonition::
675 without title
676 <system_message level="3" line="19" source="{include10}" type="ERROR">
677 <paragraph>
678 Content block expected for the "epigraph" directive; none found.
679 <literal_block xml:space="preserve">
680 .. epigraph::
681 <system_message level="3" line="21" source="{include10}" type="ERROR">
682 <paragraph>
683 Content block expected for the "highlights" directive; none found.
684 <literal_block xml:space="preserve">
685 .. highlights::
686 <system_message level="3" line="23" source="{include10}" type="ERROR">
687 <paragraph>
688 Content block expected for the "pull-quote" directive; none found.
689 <literal_block xml:space="preserve">
690 .. pull-quote::
691 <system_message level="3" line="25" source="{include10}" type="ERROR">
692 <paragraph>
693 Invalid context: the "date" directive can only be used within a substitution definition.
694 <literal_block xml:space="preserve">
695 .. date::
696 <paragraph>
697 not a
698 definition list:
699 <system_message level="3" line="29" source="{include10}" type="ERROR">
700 <paragraph>
701 Unexpected indentation.
702 <block_quote>
703 <paragraph>
704 as a term may only be one line long.
705 <system_message level="3" line="31" source="{include10}" type="ERROR">
706 <paragraph>
707 Error in "admonition" directive:
708 1 argument(s) required, 0 supplied.
709 <literal_block xml:space="preserve">
710 .. admonition::
711 \n\
712 without title and content following a blank line
713 <section names="section\\ underline\\ too\\ short">
714 <title>
715 section underline too short
716 <system_message level="2" line="36" source="{include10}" type="WARNING">
717 <paragraph>
718 Title underline too short.
719 <literal_block xml:space="preserve">
720 section underline too short
721 -----
722 <table>
723 <tgroup cols="2">
724 <colspec colwidth="14">
725 <colspec colwidth="6">
726 <thead>
727 <row>
728 <entry>
729 <paragraph>
730 A simple table
731 <entry>
732 <paragraph>
733 cell 2
734 <tbody>
735 <row>
736 <entry>
737 <paragraph>
738 cell 3
739 <entry>
740 <paragraph>
741 cell 4
742 <system_message level="2" line="43" source="{include10}" type="WARNING">
743 <paragraph>
744 Blank line required after table.
745 <paragraph>
746 No blank line after table.
747 <system_message level="3" line="45" source="{include10}" type="ERROR">
748 <paragraph>
749 Error in "unicode" directive:
750 1 argument(s) required, 0 supplied.
751 <literal_block xml:space="preserve">
752 unicode::
753 <system_message level="2" line="45" source="{include10}" type="WARNING">
754 <paragraph>
755 Substitution definition "empty" empty or invalid.
756 <literal_block xml:space="preserve">
757 .. |empty| unicode::
758 <system_message level="3" line="47" source="{include10}" type="ERROR">
759 <paragraph>
760 Error in "topic" directive:
761 1 argument(s) required, 0 supplied.
762 <literal_block xml:space="preserve">
763 .. topic::
764 <system_message level="3" line="49" source="{include10}" type="ERROR">
765 <paragraph>
766 Error in "rubric" directive:
767 1 argument(s) required, 0 supplied.
768 <literal_block xml:space="preserve">
769 .. rubric::
770 <rubric>
771 A rubric has no content
772 <comment xml:space="preserve">
773 _`target: No matching backquote.
774 <system_message level="2" line="52" source="{include10}" type="WARNING">
775 <paragraph>
776 malformed hyperlink target.
777 <comment xml:space="preserve">
778 __malformed: no good
779 <system_message level="2" line="53" source="{include10}" type="WARNING">
780 <paragraph>
781 malformed hyperlink target.
782 <definition_list>
783 <definition_list_item>
784 <term>
785 A literal block::
786 <definition>
787 <system_message level="1" line="56" source="{include10}" type="INFO">
788 <paragraph>
789 Blank line missing before literal block (after the "::")? Interpreted as a definition list item.
790 <paragraph>
791 with no blank line above.
792 <literal_block xml:space="preserve">
793 > A literal block.
794 <system_message level="3" line="61" source="{include10}" type="ERROR">
795 <paragraph>
796 Inconsistent literal block quoting.
797 <paragraph>
798 $ with inconsistent quoting.
799 <paragraph>
800 <problematic ids="problematic-1" refid="system-message-1">
801 :unknown-role:`role`
802 \n\
803 and \n\
804 <problematic ids="problematic-2" refid="system-message-2">
805 *
806 unbalanced
807 <problematic ids="problematic-3" refid="system-message-3">
808 `
809 inline
810 <problematic ids="problematic-4" refid="system-message-4">
811 **
812 markup
813 <system_message level="1" line="63" source="{include10}" type="INFO">
814 <paragraph>
815 No role entry for "unknown-role" in module "docutils.parsers.rst.languages.en".
816 Trying "unknown-role" as canonical role name.
817 <system_message backrefs="problematic-1" ids="system-message-1" level="3" line="63" source="{include10}" type="ERROR">
818 <paragraph>
819 Unknown interpreted text role "unknown-role".
820 <system_message backrefs="problematic-2" ids="system-message-2" level="2" line="63" source="{include10}" type="WARNING">
821 <paragraph>
822 Inline emphasis start-string without end-string.
823 <system_message backrefs="problematic-3" ids="system-message-3" level="2" line="63" source="{include10}" type="WARNING">
824 <paragraph>
825 Inline interpreted text or phrase reference start-string without end-string.
826 <system_message backrefs="problematic-4" ids="system-message-4" level="2" line="63" source="{include10}" type="WARNING">
827 <paragraph>
828 Inline strong start-string without end-string.
829 <block_quote>
830 <paragraph>
831 A block quote with \n\
832 <problematic ids="problematic-5" refid="system-message-5">
833 *
834 inline warning
835 <system_message backrefs="problematic-5" ids="system-message-5" level="2" line="68" source="{include10}" type="WARNING">
836 <paragraph>
837 Inline emphasis start-string without end-string.
838 <attribution>
839 attribution with \n\
840 <problematic ids="problematic-6" refid="system-message-6">
841 *
842 inline warning
843 <system_message backrefs="problematic-6" ids="system-message-6" level="2" line="70" source="{include10}" type="WARNING">
844 <paragraph>
845 Inline emphasis start-string without end-string.
846 <paragraph>
847 <problematic ids="problematic-7" refid="system-message-7">
848 :PEP:`-1`
849 <system_message backrefs="problematic-7" ids="system-message-7" level="3" line="72" source="{include10}" type="ERROR">
850 <paragraph>
851 PEP number must be a number from 0 to 9999; "-1" is invalid.
852 <system_message level="1" line="70" source="{include10}" type="INFO">
853 <paragraph>
854 No directive entry for "unknown" in module "docutils.parsers.rst.languages.en".
855 Trying "unknown" as canonical directive name.
856 <system_message level="3" line="74" source="{include10}" type="ERROR">
857 <paragraph>
858 Unknown directive type "unknown".
859 <literal_block xml:space="preserve">
860 .. unknown:: directive (TODO: info still reported with wrong line)
861 <system_message level="3" line="76" source="{include10}" type="ERROR">
862 <paragraph>
863 Malformed table.
864 No bottom table border found.
865 <literal_block xml:space="preserve">
866 ============== ======
867 A simple table with
868 no bottom border
869 \n\
870 .. end of inclusion from "{include10}"
871 """],
872 [f"""\
873 Inclusion 1
874 ===========
875 Name clash: The included file uses the same section title.
876
877 .. include:: {include1}
878 :parser: rst
879 """,
880 f"""\
881 <document source="test data">
882 <section dupnames="inclusion\\ 1" ids="inclusion-1-1">
883 <title>
884 Inclusion 1
885 <paragraph>
886 Name clash: The included file uses the same section title.
887 <section dupnames="inclusion\\ 1" ids="inclusion-1-2">
888 <title>
889 Inclusion 1
890 <system_message backrefs="inclusion-1-2" level="1" line="2" source="{include1}" type="INFO">
891 <paragraph>
892 Duplicate implicit target name: "inclusion 1".
893 <paragraph>
894 This file is used by \n\
895 <literal>
896 test_include.py
897 .
898 """],
899 [f"""\
900 Include file with whitespace in the path:
901
902 .. include:: {include11}
903 """,
904 """\
905 <document source="test data">
906 <paragraph>
907 Include file with whitespace in the path:
908 <paragraph>
909 some text
910 """],
911 ["""\
912 Standard include data file:
913
914 .. include:: <isogrk4.txt>
915 """,
916 """\
917 <document source="test data">
918 <paragraph>
919 Standard include data file:
920 <comment xml:space="preserve">
921 This data file has been placed in the public domain.
922 <comment xml:space="preserve">
923 Derived from the Unicode character mappings available from
924 <http://www.w3.org/2003/entities/xml/>.
925 Processed by unicode2rstsubs.py, part of Docutils:
926 <https://docutils.sourceforge.io>.
927 <substitution_definition names="b.Gammad">
928 \u03dc
929 <substitution_definition names="b.gammad">
930 \u03dd
931 """],
932 ["""\
933 Nonexistent standard include data file:
934
935 .. include:: <nonexistent>
936 """,
937 f"""\
938 <document source="test data">
939 <paragraph>
940 Nonexistent standard include data file:
941 <system_message level="3" line="3" source="test data" type="ERROR">
942 <paragraph>
943 Problems with "include" directive path:
944 InputError: [Errno 2] No such file or directory: '{nonexistent}'.
945 <literal_block xml:space="preserve">
946 .. include:: <nonexistent>
947 """],
948 [f"""\
949 Include start-line/end-line Test
950
951 .. include:: {include2}
952 :start-line: 3
953 :end-line: 4
954 """,
955 """\
956 <document source="test data">
957 <paragraph>
958 Include start-line/end-line Test
959 <paragraph>
960 This file (include2.rst) is used by
961 """],
962 [f"""\
963 Include start-line/end-line + start-after Test
964
965 .. include:: {include12}
966 :start-line: 2
967 :end-line: 5
968 :start-after: here
969
970 Text search is limited to the specified lines.
971 """,
972 """\
973 <document source="test data">
974 <paragraph>
975 Include start-line/end-line + start-after Test
976 <paragraph>
977 In include12.rst (after "start here", before "stop here")
978 <paragraph>
979 Text search is limited to the specified lines.
980 """],
981 [f"""\
982 Include start-after/end-before Test
983
984 .. include:: {include12}
985 :start-after: .. start here
986 :end-before: .. stop here
987
988 A paragraph.
989 """,
990 """\
991 <document source="test data">
992 <paragraph>
993 Include start-after/end-before Test
994 <paragraph>
995 In include12.rst (after "start here", before "stop here")
996 <paragraph>
997 A paragraph.
998 """],
999 [f"""\
1000 Include start-after/end-before Test, single option variant
1001
1002 .. include:: {include12}
1003 :end-before: .. start here
1004
1005 .. include:: {include12}
1006 :start-after: .. stop here
1007
1008 A paragraph.
1009 """,
1010 """\
1011 <document source="test data">
1012 <paragraph>
1013 Include start-after/end-before Test, single option variant
1014 <paragraph>
1015 In include12.rst (but before "start here")
1016 <paragraph>
1017 In include12.rst (after "stop here")
1018 <paragraph>
1019 A paragraph.
1020 """],
1021 [f"""\
1022 Include start-after/end-before multi-line test.
1023
1024 .. include:: {include13}
1025 :start-after: From: me
1026 To: you
1027 :end-before: -------
1028 -- mork of ork
1029
1030 .. include:: {include13}
1031 :start-after: From: me
1032 To: you
1033 :end-before:
1034 -------
1035 -- mork of ork
1036
1037 A paragraph.
1038 """,
1039 f"""\
1040 <document source="test data">
1041 <paragraph>
1042 Include start-after/end-before multi-line test.
1043 <system_message level="3" line="3" source="test data" type="ERROR">
1044 <paragraph>
1045 Problem with "end-before" option of "include" directive:
1046 Text not found.
1047 <literal_block xml:space="preserve">
1048 .. include:: {include13}
1049 :start-after: From: me
1050 To: you
1051 :end-before: -------
1052 -- mork of ork
1053 <paragraph>
1054 In include13.rst (between header and signature)
1055 <paragraph>
1056 A paragraph.
1057 """],
1058 [f"""\
1059 Error handling test; "end-before" error handling tested in previous test.
1060
1061 .. include:: {include13}
1062 :start-after: bad string
1063 :end-before: mork of ork
1064 """,
1065 f"""\
1066 <document source="test data">
1067 <paragraph>
1068 Error handling test; "end-before" error handling tested in previous test.
1069 <system_message level="3" line="3" source="test data" type="ERROR">
1070 <paragraph>
1071 Problem with "start-after" option of "include" directive:
1072 Text not found.
1073 <literal_block xml:space="preserve">
1074 .. include:: {include13}
1075 :start-after: bad string
1076 :end-before: mork of ork
1077 """],
1078 [f"""\
1079 Default TAB expansion with literal include:
1080
1081 .. include:: {include_literal}
1082 :literal:
1083 """,
1084 f"""\
1085 <document source="test data">
1086 <paragraph>
1087 Default TAB expansion with literal include:
1088 <literal_block source="{include_literal}" xml:space="preserve">
1089 Literal included this should **not** be *marked* `up`.
1090 <- leading raw tab.
1091 \n\
1092 Newlines
1093 are
1094 normalized.
1095 """],
1096 [f"""\
1097 Custom TAB expansion with literal include:
1098
1099 .. include:: {include_literal}
1100 :literal:
1101 :tab-width: 2
1102 """,
1103 f"""\
1104 <document source="test data">
1105 <paragraph>
1106 Custom TAB expansion with literal include:
1107 <literal_block source="{include_literal}" xml:space="preserve">
1108 Literal included this should **not** be *marked* `up`.
1109 <- leading raw tab.
1110 \n\
1111 Newlines
1112 are
1113 normalized.
1114 """],
1115 [f"""\
1116 No TAB expansion with literal include:
1117
1118 .. include:: {include_literal}
1119 :literal:
1120 :tab-width: -1
1121 """,
1122 f"""\
1123 <document source="test data">
1124 <paragraph>
1125 No TAB expansion with literal include:
1126 <literal_block source="{include_literal}" xml:space="preserve">
1127 Literal included this should **not** be *marked* `up`.
1128 \t<- leading raw tab.
1129 \n\
1130 Newlines
1131 are
1132 normalized.
1133 """],
1134 ]
1135
1136 totest['include_parsed_code'] = [
1137 [f"""\
1138 Included code
1139
1140 .. include:: {include1}
1141 :code: rst
1142 """,
1143 f"""\
1144 <document source="test data">
1145 <paragraph>
1146 Included code
1147 <literal_block classes="code rst" source="{include1}" xml:space="preserve">
1148 <inline classes="generic heading">
1149 Inclusion 1
1150 \n\
1151 <inline classes="generic heading">
1152 -----------
1153 \n\
1154 <inline classes="whitespace">
1155 \n\
1156 This file is used by \n\
1157 <inline classes="literal string">
1158 ``test_include.py``
1159 .
1160 """ if PYGMENTS_2_14_PLUS else f"""\
1161 <document source="test data">
1162 <paragraph>
1163 Included code
1164 <literal_block classes="code rst" source="{include1}" xml:space="preserve">
1165 <inline classes="generic heading">
1166 Inclusion 1
1167 \n\
1168 <inline classes="generic heading">
1169 -----------
1170 \n\
1171 \n\
1172 This file is used by \n\
1173 <inline classes="literal string">
1174 ``test_include.py``
1175 .
1176 """],
1177 [f"""\
1178 Included code
1179
1180 .. include:: {include1}
1181 :code: rst
1182 :number-lines: 0
1183 """,
1184 f"""\
1185 <document source="test data">
1186 <paragraph>
1187 Included code
1188 <literal_block classes="code rst" source="{include1}" xml:space="preserve">
1189 <inline classes="ln">
1190 0 \n\
1191 <inline classes="generic heading">
1192 Inclusion 1
1193 \n\
1194 <inline classes="ln">
1195 1 \n\
1196 <inline classes="generic heading">
1197 -----------
1198 \n\
1199 <inline classes="ln">
1200 2 \n\
1201 <inline classes="whitespace">
1202 \n\
1203 <inline classes="ln">
1204 3 \n\
1205 <inline classes="whitespace">
1206 This file is used by \n\
1207 <inline classes="literal string">
1208 ``test_include.py``
1209 .
1210 """ if PYGMENTS_2_14_PLUS else f"""\
1211 <document source="test data">
1212 <paragraph>
1213 Included code
1214 <literal_block classes="code rst" source="{include1}" xml:space="preserve">
1215 <inline classes="ln">
1216 1 \n\
1217 <inline classes="generic heading">
1218 Inclusion 1
1219 \n\
1220 <inline classes="ln">
1221 2 \n\
1222 <inline classes="generic heading">
1223 -----------
1224 \n\
1225 <inline classes="ln">
1226 3 \n\
1227 \n\
1228 <inline classes="ln">
1229 4 \n\
1230 This file is used by \n\
1231 <inline classes="literal string">
1232 ``test_include.py``
1233 .
1234 """],
1235 [f"""\
1236 Default TAB expansion with included code:
1237
1238 .. include:: {include_literal}
1239 :code: rst
1240 """,
1241 f"""\
1242 <document source="test data">
1243 <paragraph>
1244 Default TAB expansion with included code:
1245 <literal_block classes="code rst" source="{include_literal}" xml:space="preserve">
1246 Literal included this should \n\
1247 <inline classes="generic strong">
1248 **not**
1249 be \n\
1250 <inline classes="generic emph">
1251 *marked*
1252 \n\
1253 <inline classes="name variable">
1254 `up`
1255 .
1256 <inline classes="whitespace">
1257 \n\
1258 <- leading raw tab.
1259 <inline classes="whitespace">
1260 \n\
1261 \n\
1262 Newlines
1263 <inline classes="whitespace">
1264 \n\
1265 are
1266 <inline classes="whitespace">
1267 \n\
1268 normalized.
1269 """ if PYGMENTS_2_14_PLUS else f"""\
1270 <document source="test data">
1271 <paragraph>
1272 Default TAB expansion with included code:
1273 <literal_block classes="code rst" source="{include_literal}" xml:space="preserve">
1274 Literal included this should \n\
1275 <inline classes="generic strong">
1276 **not**
1277 be \n\
1278 <inline classes="generic emph">
1279 *marked*
1280 \n\
1281 <inline classes="name variable">
1282 `up`
1283 .
1284 <- leading raw tab.
1285 \n\
1286 Newlines
1287 are
1288 normalized.
1289 """],
1290 [f"""\
1291 Custom TAB expansion with included code:
1292
1293 .. include:: {include_literal}
1294 :code: rst
1295 :tab-width: 2
1296 """,
1297 f"""\
1298 <document source="test data">
1299 <paragraph>
1300 Custom TAB expansion with included code:
1301 <literal_block classes="code rst" source="{include_literal}" xml:space="preserve">
1302 Literal included this should \n\
1303 <inline classes="generic strong">
1304 **not**
1305 be \n\
1306 <inline classes="generic emph">
1307 *marked*
1308 \n\
1309 <inline classes="name variable">
1310 `up`
1311 .
1312 <inline classes="whitespace">
1313 \n\
1314 <- leading raw tab.
1315 <inline classes="whitespace">
1316 \n\
1317 \n\
1318 Newlines
1319 <inline classes="whitespace">
1320 \n\
1321 are
1322 <inline classes="whitespace">
1323 \n\
1324 normalized.
1325 """ if PYGMENTS_2_14_PLUS else f"""\
1326 <document source="test data">
1327 <paragraph>
1328 Custom TAB expansion with included code:
1329 <literal_block classes="code rst" source="{include_literal}" xml:space="preserve">
1330 Literal included this should \n\
1331 <inline classes="generic strong">
1332 **not**
1333 be \n\
1334 <inline classes="generic emph">
1335 *marked*
1336 \n\
1337 <inline classes="name variable">
1338 `up`
1339 .
1340 <- leading raw tab.
1341 \n\
1342 Newlines
1343 are
1344 normalized.
1345 """],
1346 [f"""\
1347 No TAB expansion with included code:
1348
1349 .. include:: {include_literal}
1350 :code: rst
1351 :tab-width: -1
1352 """,
1353 f"""\
1354 <document source="test data">
1355 <paragraph>
1356 No TAB expansion with included code:
1357 <literal_block classes="code rst" source="{include_literal}" xml:space="preserve">
1358 Literal included this should \n\
1359 <inline classes="generic strong">
1360 **not**
1361 be \n\
1362 <inline classes="generic emph">
1363 *marked*
1364 \n\
1365 <inline classes="name variable">
1366 `up`
1367 .
1368 <inline classes="whitespace">
1369 \n\
1370 \t<- leading raw tab.
1371 <inline classes="whitespace">
1372 \n\
1373 \n\
1374 Newlines
1375 <inline classes="whitespace">
1376 \n\
1377 are
1378 <inline classes="whitespace">
1379 \n\
1380 normalized.
1381 """ if PYGMENTS_2_14_PLUS else f"""\
1382 <document source="test data">
1383 <paragraph>
1384 No TAB expansion with included code:
1385 <literal_block classes="code rst" source="{include_literal}" xml:space="preserve">
1386 Literal included this should \n\
1387 <inline classes="generic strong">
1388 **not**
1389 be \n\
1390 <inline classes="generic emph">
1391 *marked*
1392 \n\
1393 <inline classes="name variable">
1394 `up`
1395 .
1396 \t<- leading raw tab.
1397 \n\
1398 Newlines
1399 are
1400 normalized.
1401 """],
1402 [f"""\
1403 Including includes/include14.rst
1404
1405 .. include:: {include14}
1406 """,
1407 f"""\
1408 <document source="test data">
1409 <paragraph>
1410 Including includes/include14.rst
1411 <paragraph>
1412 Including more/include6.rst as rst-code from includes/include14.rst:
1413 <literal_block classes="code rst" source="{include6}" xml:space="preserve">
1414 In includes/more/include6.rst
1415 <inline classes="whitespace">
1416 \n\
1417 \n\
1418 <inline classes="punctuation">
1419 ..
1420 \n\
1421 <inline classes="operator word">
1422 include
1423 <inline classes="punctuation">
1424 ::
1425 ../sibling/include7.rst
1426 """ if PYGMENTS_2_14_PLUS else f"""\
1427 <document source="test data">
1428 <paragraph>
1429 Including includes/include14.rst
1430 <paragraph>
1431 Including more/include6.rst as rst-code from includes/include14.rst:
1432 <literal_block classes="code rst" source="{include6}" xml:space="preserve">
1433 In includes/more/include6.rst
1434 \n\
1435 <inline classes="punctuation">
1436 ..
1437 \n\
1438 <inline classes="operator word">
1439 include
1440 <inline classes="punctuation">
1441 ::
1442 ../sibling/include7.rst
1443 """],
1444 [f"""\
1445 Circular inclusion
1446
1447 .. include:: {include15}
1448 """,
1449 f"""\
1450 <document source="test data">
1451 <paragraph>
1452 Circular inclusion
1453 <paragraph>
1454 File "include15.rst": example of rekursive inclusion.
1455 <paragraph>
1456 File "include16.rst": example of rekursive inclusion.
1457 <system_message level="2" line="3" source="{include16}" type="WARNING">
1458 <paragraph>
1459 circular inclusion in "include" directive:
1460 {include15}
1461 > {include16}
1462 > {include15}
1463 > test data
1464 <literal_block xml:space="preserve">
1465 .. include:: include15.rst
1466 <paragraph>
1467 No loop when clipping before the "include" directive:
1468 <paragraph>
1469 File "include15.rst": example of rekursive inclusion.
1470 """],
1471 [f"""\
1472 Circular inclusion with clipping.
1473
1474 .. include:: {include16}
1475 :start-line: 2
1476 """,
1477 f"""\
1478 <document source="test data">
1479 <paragraph>
1480 Circular inclusion with clipping.
1481 <paragraph>
1482 File "include15.rst": example of rekursive inclusion.
1483 <paragraph>
1484 File "include16.rst": example of rekursive inclusion.
1485 <system_message level="2" line="3" source="{include16}" type="WARNING">
1486 <paragraph>
1487 circular inclusion in "include" directive:
1488 {include15}
1489 > {include16}
1490 > {include15}
1491 > {include16}
1492 > test data
1493 <literal_block xml:space="preserve">
1494 .. include:: include15.rst
1495 <paragraph>
1496 No loop when clipping before the "include" directive:
1497 <paragraph>
1498 File "include15.rst": example of rekursive inclusion.
1499 <paragraph>
1500 No loop when clipping before the "include" directive:
1501 <paragraph>
1502 File "include15.rst": example of rekursive inclusion.
1503 """],
1504 [f"""\
1505 Circular inclusion with specified parser.
1506
1507 .. include:: {include15}
1508 :parser: rst
1509 """,
1510 f"""\
1511 <document source="test data">
1512 <paragraph>
1513 Circular inclusion with specified parser.
1514 <paragraph>
1515 File "include15.rst": example of rekursive inclusion.
1516 <paragraph>
1517 File "include16.rst": example of rekursive inclusion.
1518 <system_message level="2" line="3" source="{include16}" type="WARNING">
1519 <paragraph>
1520 circular inclusion in "include" directive:
1521 {include15}
1522 > {include16}
1523 > {include15}
1524 <literal_block xml:space="preserve">
1525 .. include:: include15.rst
1526 <paragraph>
1527 No loop when clipping before the "include" directive:
1528 <paragraph>
1529 File "include15.rst": example of rekursive inclusion.
1530 """],
1531 [f"""\
1532 No circular inclusion.
1533
1534 .. list-table::
1535
1536 * - .. include:: {include}
1537 - .. include:: {include}
1538 """,
1539 """\
1540 <document source="test data">
1541 <paragraph>
1542 No circular inclusion.
1543 <table>
1544 <tgroup cols="2">
1545 <colspec colwidth="50">
1546 <colspec colwidth="50">
1547 <tbody>
1548 <row>
1549 <entry>
1550 <paragraph>
1551 Some include text.
1552 <entry>
1553 <paragraph>
1554 Some include text.
1555 """],
1556 ]
1557
1558 # Parsing with Markdown is an optional feature depending on 3rd-party modules:
1559 totest['include_markdown'] = [
1560 [f"""\
1561 Include Markdown source.
1562
1563 .. include:: {include_md}
1564 :parser: {md_parser_name}
1565
1566 A paragraph.
1567 """,
1568 """\
1569 <document source="test data">
1570 <paragraph>
1571 Include Markdown source.
1572 <section depth="1">
1573 <title>
1574 Title 1
1575 <paragraph>
1576 <emphasis>
1577 emphasis
1578 and \n\
1579 <emphasis>
1580 also emphasis
1581 <paragraph>
1582 No whitespace required around a
1583 <reference refuri="/uri">
1584 phrase reference
1585 .
1586 <target ids="phrase-reference" names="phrase\\ reference" refuri="/uri">
1587 <paragraph>
1588 A paragraph.
1589 """],
1590 ]
1591
1592 # Transforms are required for these tests: The system_message about
1593 # duplicate name/id is appended by the "universal.Messages" transform.
1594 totest['with transforms'] = [
1595 [f"""\
1596 .. _common id:
1597
1598 Include Docutils XML file:
1599
1600 .. include:: {include_xml}
1601 :parser: xml
1602 """,
1603 f"""\
1604 <document source="test data">
1605 <target refid="common-id">
1606 <paragraph ids="common-id" names="common\\ id">
1607 Include Docutils XML file:
1608 <section>
1609 <title names="nice\\ heading">
1610 nice heading
1611 <paragraph>
1612 Text with \n\
1613 <strong ids="common-id">
1614 strong
1615 statement
1616 and more text.
1617 <section classes="system-messages">
1618 <title>
1619 Docutils System Messages
1620 <system_message level="3" line="3" source="{include_xml}" type="ERROR">
1621 <paragraph>
1622 Duplicate ID: "common-id" used by <target ids="common-id" names="common\\ id"> and <strong ids="common-id">
1623 """],
1624 [f"""\
1625 Inclusion 1
1626 ===========
1627 Name clash: The included file uses the same section title `inclusion 1`_.
1628
1629 .. include:: {include1}
1630 :parser: rst
1631
1632 Inclusion 2
1633 ===========
1634 """,
1635 """\
1636 <document source="test data">
1637 <section dupnames="inclusion\\ 1" ids="inclusion-1">
1638 <title>
1639 Inclusion 1
1640 <paragraph>
1641 Name clash: The included file uses the same section title \n\
1642 <problematic ids="problematic-1" refid="system-message-1">
1643 `inclusion 1`_
1644 .
1645 <section dupnames="inclusion\\ 1" ids="inclusion-1-1">
1646 <title>
1647 Inclusion 1
1648 <paragraph>
1649 This file is used by \n\
1650 <literal>
1651 test_include.py
1652 .
1653 <section ids="inclusion-2" names="inclusion\\ 2">
1654 <title>
1655 Inclusion 2
1656 <section classes="system-messages">
1657 <title>
1658 Docutils System Messages
1659 <system_message backrefs="problematic-1" ids="system-message-1" level="3" line="3" source="test data" type="ERROR">
1660 <paragraph>
1661 Duplicate target name, cannot be used as a unique reference: "inclusion 1".
1662 """],
1663 ]
1664
1665
1666 if __name__ == '__main__':
1667 unittest.main()