Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_include.py

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