Clean up parser code.
[docutils.git] / docutils / test / test_parsers / test_rst / test_directives / test_include.py
blobda673347f6abfad019fd106552a49aee0c578025
1 #! /usr/bin/env python
3 # $Id$
4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Tests for misc.py "include" directive.
9 """
10 from __future__ import absolute_import
12 import os.path
13 import sys
14 if __name__ == '__main__':
15 import __init__
16 from test_parsers import DocutilsTestSupport
17 from docutils.parsers.rst import states
18 from docutils.parsers import recommonmark_wrapper
19 from docutils.utils.code_analyzer import with_pygments
21 if sys.version_info >= (3, 0):
22 unichr = chr # noqa
25 def suite():
26 s = DocutilsTestSupport.ParserTestSuite()
27 if not with_pygments:
28 del(totest['include-code'])
29 s.generateTests(totest)
30 return s
32 # prepend this directory (relative to the test root):
33 def mydir(path):
34 return os.path.join('test_parsers/test_rst/test_directives/', path)
35 # make `path` relative with utils.relative_path():
36 def reldir(path):
37 return DocutilsTestSupport.utils.relative_path(None, path)
39 include1 = mydir('include1.txt')
40 include2 = mydir('include2.txt')
41 include3 = mydir('include3.txt')
42 include6 = mydir('includes/more/include6.txt')
43 include8 = mydir('include8.txt')
44 include10 = mydir('include10.txt')
45 include11 = mydir('include 11.txt')
46 include12 = mydir('include12.txt')
47 include13 = mydir('include13.txt')
48 include14 = mydir('includes/include14.txt')
49 include15 = mydir('includes/include15.txt')
50 include16 = mydir('includes/include16.txt')
51 include_literal = mydir('include_literal.txt')
52 include_md = mydir('include.md')
53 utf_16_file = mydir('utf-16.csv')
54 utf_16_error_str = ("UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe "
55 "in position 0: ordinal not in range(128)")
56 if sys.version_info < (3, 0):
57 utf_16_error_str = ("UnicodeError: Unable to decode input data. "
58 "Tried the following encodings: 'ascii'.\n"
59 " (%s)" % utf_16_error_str)
60 nonexistent = os.path.join(os.path.dirname(states.__file__),
61 'include', 'nonexistent')
62 nonexistent_rel = DocutilsTestSupport.utils.relative_path(
63 os.path.join(DocutilsTestSupport.testroot, 'dummy'), nonexistent)
65 # Different error for path with 8bit chars with locale == C or None:
66 try:
67 open(u'\u043c\u0438\u0440.txt')
68 except UnicodeEncodeError:
69 errstr_8bit_path = u"""\
70 Cannot encode input file path "\u043c\u0438\u0440.txt" (wrong locale?).\
71 """
72 except:
73 errstr_8bit_path = u"""\
74 InputError: [Errno 2] No such file or directory: '\u043c\u0438\u0440.txt'.\
75 """
77 # Parsing with Markdown (recommonmark) is an optional feature depending
78 # on 3rd-party modules:
79 if recommonmark_wrapper.CommonMarkParser:
80 markdown_parsing_result = """\
81 <section ids="title-1" names="title\\ 1">
82 <title>
83 Title 1
84 <paragraph>
85 <emphasis>
86 emphasis
87 and \n\
88 <emphasis>
89 also emphasis
90 <paragraph>
91 No whitespace required around a
92 <reference name="phrase reference" refuri="/uri">
93 phrase reference
94 ."""
95 else:
96 markdown_parsing_result = """\
97 <system_message level="2" source="test_parsers/test_rst/test_directives/include.md" type="WARNING">
98 <paragraph>
99 Missing dependency: MarkDown input is processed by a 3rd party parser but Python did not find the required module "recommonmark" (https://pypi.org/project/recommonmark/).\
103 totest = {}
105 totest['include'] = [
106 ["""\
107 Include Test
108 ============
110 .. include:: %s
112 A paragraph.
113 """ % include1,
114 """\
115 <document source="test data">
116 <section ids="include-test" names="include\\ test">
117 <title>
118 Include Test
119 <section ids="inclusion-1" names="inclusion\\ 1">
120 <title>
121 Inclusion 1
122 <paragraph>
123 This file is used by \n\
124 <literal>
125 test_include.py
127 <paragraph>
128 A paragraph.
129 """],
130 ["""\
131 Include Test
132 ============
134 .. include:: %s
135 :literal:
136 :class: test
137 :name: my name
139 A paragraph.
140 """ % include1,
141 """\
142 <document source="test data">
143 <section ids="include-test" names="include\\ test">
144 <title>
145 Include Test
146 <literal_block classes="test" ids="my-name" names="my\\ name" source="%s" xml:space="preserve">
147 Inclusion 1
148 -----------
150 This file is used by ``test_include.py``.
151 <paragraph>
152 A paragraph.
153 """ % reldir(include1)],
154 ["""\
155 Literal include, add line numbers
157 .. include:: %s
158 :literal:
159 :number-lines:
160 """ % include1,
161 """\
162 <document source="test data">
163 <paragraph>
164 Literal include, add line numbers
165 <literal_block source="%s" xml:space="preserve">
166 <inline classes="ln">
167 1 \n\
168 Inclusion 1
169 <inline classes="ln">
170 2 \n\
171 -----------
172 <inline classes="ln">
173 3 \n\
175 <inline classes="ln">
176 4 \n\
177 This file is used by ``test_include.py``.
178 """ % reldir(include1)],
179 ["""\
180 Include code
182 .. include:: %s
183 :code:
184 :class: test
185 :name: my name
186 """ % include1,
187 """\
188 <document source="test data">
189 <paragraph>
190 Include code
191 <literal_block classes="code test" ids="my-name" names="my\\ name" source="%s" xml:space="preserve">
192 Inclusion 1
193 -----------
195 This file is used by ``test_include.py``.
196 """ % reldir(include1)],
197 ["""\
198 Include code, add line numbers
200 .. include:: %s
201 :code:
202 :number-lines:
203 """ % include1,
204 """\
205 <document source="test data">
206 <paragraph>
207 Include code, add line numbers
208 <literal_block classes="code" source="%s" xml:space="preserve">
209 <inline classes="ln">
210 1 \n\
211 Inclusion 1
212 <inline classes="ln">
213 2 \n\
214 -----------
215 <inline classes="ln">
216 3 \n\
218 <inline classes="ln">
219 4 \n\
220 This file is used by ``test_include.py``.
221 """ % reldir(include1)],
222 ["""\
223 Include markdown (recommonmark).
225 .. include:: %s
226 :parser: markdown
228 A paragraph.
229 """ % include_md,
230 """\
231 <document source="test data">
232 <paragraph>
233 Include markdown (recommonmark).
235 <paragraph>
236 A paragraph.
237 """ % markdown_parsing_result],
238 ["""\
239 Let's test the parse context.
241 This paragraph is in a block quote.
243 .. include:: %s
245 The included paragraphs should also be in the block quote.
246 """ % include2,
247 """\
248 <document source="test data">
249 <paragraph>
250 Let's test the parse context.
251 <block_quote>
252 <paragraph>
253 This paragraph is in a block quote.
254 <paragraph>
255 Here are some paragraphs
256 that can appear at any level.
257 <paragraph>
258 This file (include2.txt) is used by
259 <literal>
260 test_include.py
262 <paragraph>
263 The included paragraphs should also be in the block quote.
264 """],
265 ["""\
266 Include Test
267 ============
269 .. include:: nonexistent.txt
271 A paragraph.
272 """,
273 """\
274 <document source="test data">
275 <section ids="include-test" names="include\\ test">
276 <title>
277 Include Test
278 <system_message level="4" line="4" source="test data" type="SEVERE">
279 <paragraph>
280 Problems with "include" directive path:
281 InputError: [Errno 2] No such file or directory: 'nonexistent.txt'.
282 <literal_block xml:space="preserve">
283 .. include:: nonexistent.txt
284 <paragraph>
285 A paragraph.
286 """],
287 ["""\
288 Include Test
289 ============
291 .. include:: %s
293 .. include:: %s
295 A paragraph.
296 """ % (include1, include1),
297 """\
298 <document source="test data">
299 <section ids="include-test" names="include\\ test">
300 <title>
301 Include Test
302 <section dupnames="inclusion\\ 1" ids="inclusion-1">
303 <title>
304 Inclusion 1
305 <paragraph>
306 This file is used by
307 <literal>
308 test_include.py
310 <section dupnames="inclusion\\ 1" ids="id1">
311 <title>
312 Inclusion 1
313 <system_message backrefs="id1" level="1" line="2" source="%s" type="INFO">
314 <paragraph>
315 Duplicate implicit target name: "inclusion 1".
316 <paragraph>
317 This file is used by
318 <literal>
319 test_include.py
321 <paragraph>
322 A paragraph.
323 """ % reldir(include1)],
324 ["""\
325 Include Test
326 ============
328 .. include:: %s
330 ----------
332 .. include:: %s
334 A paragraph.
335 """ % (include1, include1),
336 """\
337 <document source="test data">
338 <section ids="include-test" names="include\\ test">
339 <title>
340 Include Test
341 <section dupnames="inclusion\\ 1" ids="inclusion-1">
342 <title>
343 Inclusion 1
344 <paragraph>
345 This file is used by \n\
346 <literal>
347 test_include.py
349 <transition>
350 <section dupnames="inclusion\\ 1" ids="id1">
351 <title>
352 Inclusion 1
353 <system_message backrefs="id1" level="1" line="2" source="%s" type="INFO">
354 <paragraph>
355 Duplicate implicit target name: "inclusion 1".
356 <paragraph>
357 This file is used by \n\
358 <literal>
359 test_include.py
361 <paragraph>
362 A paragraph.
363 """ % reldir(include1)],
364 ["""\
365 Recursive inclusions: adapt paths.
367 In test data
369 .. include:: %s
370 """ % include3,
371 """\
372 <document source="test data">
373 <paragraph>
374 Recursive inclusions: adapt paths.
375 <paragraph>
376 In test data
377 <paragraph>
378 In include3.txt
379 <paragraph>
380 In includes/include4.txt
381 <paragraph>
382 In includes/include5.txt
383 <paragraph>
384 In includes/more/include6.txt
385 <paragraph>
386 In includes/sibling/include7.txt
387 <literal_block source="test_parsers/test_rst/test_directives/includes/include5.txt" xml:space="preserve">
388 In includes/include5.txt
390 .. include:: more/include6.txt
391 <table>
392 <tgroup cols="2">
393 <colspec colwidth="50">
394 <colspec colwidth="50">
395 <tbody>
396 <row>
397 <entry>
398 <paragraph>
400 <entry>
401 <paragraph>
402 includes/sibling/include7.txt
403 """],
404 ["""\
405 In test data
407 Section
408 =======
410 (Section contents in nested parse; slice of input_lines ViewList.)
412 .. include:: %s
413 """ % include3,
414 """\
415 <document source="test data">
416 <paragraph>
417 In test data
418 <section ids="section" names="section">
419 <title>
420 Section
421 <paragraph>
422 (Section contents in nested parse; slice of input_lines ViewList.)
423 <paragraph>
424 In include3.txt
425 <paragraph>
426 In includes/include4.txt
427 <paragraph>
428 In includes/include5.txt
429 <paragraph>
430 In includes/more/include6.txt
431 <paragraph>
432 In includes/sibling/include7.txt
433 <literal_block source="test_parsers/test_rst/test_directives/includes/include5.txt" xml:space="preserve">
434 In includes/include5.txt
436 .. include:: more/include6.txt
437 <table>
438 <tgroup cols="2">
439 <colspec colwidth="50">
440 <colspec colwidth="50">
441 <tbody>
442 <row>
443 <entry>
444 <paragraph>
446 <entry>
447 <paragraph>
448 includes/sibling/include7.txt
449 """],
450 ["""\
451 Testing relative includes:
453 .. include:: %s
454 """ % include8,
455 """\
456 <document source="test data">
457 <paragraph>
458 Testing relative includes:
459 <paragraph>
460 In include8.txt
461 <paragraph>
462 In ../includes/include9.txt.
463 <paragraph>
464 Here are some paragraphs
465 that can appear at any level.
466 <paragraph>
467 This file (include2.txt) is used by
468 <literal>
469 test_include.py
471 """],
472 ["""\
473 Encoding:
475 .. include:: %s
476 :encoding: utf-16
477 """ % reldir(utf_16_file),
478 b"""\
479 <document source="test data">
480 <paragraph>
481 Encoding:
482 <paragraph>
483 "Treat", "Quantity", "Description"
484 "Albatr\xb0\xdf", 2.99, "\xa1On a \\u03c3\\u03c4\\u03b9\\u03ba!"
485 "Crunchy Frog", 1.49, "If we took the b\xf6nes out, it wouldn\\u2019t be
486 crunchy, now would it?"
487 "Gannet Ripple", 1.99, "\xbfOn a \\u03c3\\u03c4\\u03b9\\u03ba?"
488 """.decode('raw_unicode_escape')],
489 ["""\
490 Include file is UTF-16-encoded, and is not valid ASCII.
492 .. include:: %s
493 :encoding: ascii
494 """ % reldir(utf_16_file),
495 """\
496 <document source="test data">
497 <paragraph>
498 Include file is UTF-16-encoded, and is not valid ASCII.
499 <system_message level="4" line="3" source="test data" type="SEVERE">
500 <paragraph>
501 Problem with "include" directive:
503 <literal_block xml:space="preserve">
504 .. include:: %s
505 :encoding: ascii
506 """ % (utf_16_error_str, reldir(utf_16_file))],
507 [u"""\
508 cyrillic filename:
510 .. include:: \u043c\u0438\u0440.txt
511 """,
512 u"""\
513 <document source="test data">
514 <paragraph>
515 cyrillic filename:
516 <system_message level="4" line="3" source="test data" type="SEVERE">
517 <paragraph>
518 Problems with "include" directive path:
520 <literal_block xml:space="preserve">
521 .. include:: \u043c\u0438\u0440.txt
522 """ % errstr_8bit_path],
523 ["""\
524 Testing errors in included file:
526 .. include:: %s
527 """ % include10,
528 """\
529 <document source="test data">
530 <paragraph>
531 Testing errors in included file:
532 <system_message level="3" line="1" source="%(source)s" type="ERROR">
533 <paragraph>
534 Invalid character code: 0x11111111
535 %(unichr_exception)s
536 <literal_block xml:space="preserve">
537 unicode:: 0x11111111
538 <system_message level="2" line="1" source="%(source)s" type="WARNING">
539 <paragraph>
540 Substitution definition "bad" empty or invalid.
541 <literal_block xml:space="preserve">
542 .. |bad| unicode:: 0x11111111
543 <section dupnames="hi" ids="hi">
544 <title>
546 <block_quote>
547 <paragraph>
548 indent
549 <system_message level="2" line="7" source="%(source)s" type="WARNING">
550 <paragraph>
551 Block quote ends without a blank line; unexpected unindent.
552 <paragraph>
553 error
554 <section dupnames="hi" ids="id1">
555 <title>
557 <system_message backrefs="id1" level="1" line="10" source="%(source)s" type="INFO">
558 <paragraph>
559 Duplicate implicit target name: "hi".
560 <system_message level="4" line="12" source="%(source)s" type="SEVERE">
561 <paragraph>
562 Problems with "include" directive path:
563 InputError: [Errno 2] No such file or directory: '%(nonexistent)s'.
564 <literal_block xml:space="preserve">
565 .. include:: <nonexistent>
566 <system_message level="3" line="14" source="%(source)s" type="ERROR">
567 <paragraph>
568 Content block expected for the "note" directive; none found.
569 <literal_block xml:space="preserve">
570 .. note::
571 <system_message level="3" line="16" source="%(source)s" type="ERROR">
572 <paragraph>
573 Content block expected for the "admonition" directive; none found.
574 <literal_block xml:space="preserve">
575 .. admonition::
576 without title
577 <system_message level="3" line="19" source="%(source)s" type="ERROR">
578 <paragraph>
579 Content block expected for the "epigraph" directive; none found.
580 <literal_block xml:space="preserve">
581 .. epigraph::
582 <system_message level="3" line="21" source="%(source)s" type="ERROR">
583 <paragraph>
584 Content block expected for the "highlights" directive; none found.
585 <literal_block xml:space="preserve">
586 .. highlights::
587 <system_message level="3" line="23" source="%(source)s" type="ERROR">
588 <paragraph>
589 Content block expected for the "pull-quote" directive; none found.
590 <literal_block xml:space="preserve">
591 .. pull-quote::
592 <system_message level="3" line="25" source="%(source)s" type="ERROR">
593 <paragraph>
594 Invalid context: the "date" directive can only be used within a substitution definition.
595 <literal_block xml:space="preserve">
596 .. date::
597 <paragraph>
598 not a
599 definition list:
600 <system_message level="3" line="29" source="%(source)s" type="ERROR">
601 <paragraph>
602 Unexpected indentation.
603 <block_quote>
604 <paragraph>
605 as a term may only be one line long.
606 <system_message level="3" line="31" source="%(source)s" type="ERROR">
607 <paragraph>
608 Error in "admonition" directive:
609 1 argument(s) required, 0 supplied.
610 <literal_block xml:space="preserve">
611 .. admonition::
613 without title and content following a blank line
614 <section ids="section-underline-too-short" names="section\\ underline\\ too\\ short">
615 <title>
616 section underline too short
617 <system_message level="2" line="36" source="%(source)s" type="WARNING">
618 <paragraph>
619 Title underline too short.
620 <literal_block xml:space="preserve">
621 section underline too short
622 -----
623 <table>
624 <tgroup cols="2">
625 <colspec colwidth="14">
626 <colspec colwidth="6">
627 <thead>
628 <row>
629 <entry>
630 <paragraph>
631 A simple table
632 <entry>
633 <paragraph>
634 cell 2
635 <tbody>
636 <row>
637 <entry>
638 <paragraph>
639 cell 3
640 <entry>
641 <paragraph>
642 cell 4
643 <system_message level="2" line="43" source="%(source)s" type="WARNING">
644 <paragraph>
645 Blank line required after table.
646 <paragraph>
647 No blank line after table.
648 <system_message level="3" line="45" source="%(source)s" type="ERROR">
649 <paragraph>
650 Error in "unicode" directive:
651 1 argument(s) required, 0 supplied.
652 <literal_block xml:space="preserve">
653 unicode::
654 <system_message level="2" line="45" source="%(source)s" type="WARNING">
655 <paragraph>
656 Substitution definition "empty" empty or invalid.
657 <literal_block xml:space="preserve">
658 .. |empty| unicode::
659 <system_message level="3" line="47" source="%(source)s" type="ERROR">
660 <paragraph>
661 Error in "topic" directive:
662 1 argument(s) required, 0 supplied.
663 <literal_block xml:space="preserve">
664 .. topic::
665 <system_message level="3" line="49" source="%(source)s" type="ERROR">
666 <paragraph>
667 Error in "rubric" directive:
668 1 argument(s) required, 0 supplied.
669 <literal_block xml:space="preserve">
670 .. rubric::
671 <rubric>
672 A rubric has no content
673 <comment xml:space="preserve">
674 _`target: No matching backquote.
675 <system_message level="2" line="52" source="%(source)s" type="WARNING">
676 <paragraph>
677 malformed hyperlink target.
678 <comment xml:space="preserve">
679 __malformed: no good
680 <system_message level="2" line="53" source="%(source)s" type="WARNING">
681 <paragraph>
682 malformed hyperlink target.
683 <definition_list>
684 <definition_list_item>
685 <term>
686 A literal block::
687 <definition>
688 <system_message level="1" line="57" source="%(source)s" type="INFO">
689 <paragraph>
690 Blank line missing before literal block (after the "::")? Interpreted as a definition list item.
691 <paragraph>
692 with no blank line above.
693 <literal_block xml:space="preserve">
694 > A literal block.
695 <system_message level="3" line="61" source="%(source)s" type="ERROR">
696 <paragraph>
697 Inconsistent literal block quoting.
698 <paragraph>
699 $ with inconsistent quoting.
700 <paragraph>
701 <problematic ids="id3" refid="id2">
702 :unknown-role:`role`
704 and
705 <problematic ids="id5" refid="id4">
707 unbalanced
708 <problematic ids="id7" refid="id6">
710 inline
711 <problematic ids="id9" refid="id8">
713 markup
714 <system_message level="1" line="63" source="%(source)s" type="INFO">
715 <paragraph>
716 No role entry for "unknown-role" in module "docutils.parsers.rst.languages.en".
717 Trying "unknown-role" as canonical role name.
718 <system_message backrefs="id3" ids="id2" level="3" line="63" source="%(source)s" type="ERROR">
719 <paragraph>
720 Unknown interpreted text role "unknown-role".
721 <system_message backrefs="id5" ids="id4" level="2" line="63" source="%(source)s" type="WARNING">
722 <paragraph>
723 Inline emphasis start-string without end-string.
724 <system_message backrefs="id7" ids="id6" level="2" line="63" source="%(source)s" type="WARNING">
725 <paragraph>
726 Inline interpreted text or phrase reference start-string without end-string.
727 <system_message backrefs="id9" ids="id8" level="2" line="63" source="%(source)s" type="WARNING">
728 <paragraph>
729 Inline strong start-string without end-string.
730 <paragraph>
731 <problematic ids="id11" refid="id10">
732 :PEP:`-1`
733 <system_message backrefs="id11" ids="id10" level="3" line="68" source="%(source)s" type="ERROR">
734 <paragraph>
735 PEP number must be a number from 0 to 9999; "-1" is invalid.
736 <system_message level="1" line="66" source="%(source)s" type="INFO">
737 <paragraph>
738 No directive entry for "unknown" in module "docutils.parsers.rst.languages.en".
739 Trying "unknown" as canonical directive name.
740 <system_message level="3" line="70" source="%(source)s" type="ERROR">
741 <paragraph>
742 Unknown directive type "unknown".
743 <literal_block xml:space="preserve">
744 .. unknown:: directive (info still reported with wrong line)
745 <system_message level="3" line="72" source="%(source)s" type="ERROR">
746 <paragraph>
747 Malformed table.
748 No bottom table border found.
749 <literal_block xml:space="preserve">
750 ============== ======
751 A simple table with
752 no bottom border
753 """ % {'source': reldir(include10), 'nonexistent': reldir(nonexistent),
754 'unichr_exception':
755 DocutilsTestSupport.exception_data(unichr, int("11111111", 16))[2]
757 ["""\
758 Include file with whitespace in the path:
760 .. include:: %s
761 """ % reldir(include11),
762 """\
763 <document source="test data">
764 <paragraph>
765 Include file with whitespace in the path:
766 <paragraph>
767 some text
768 """],
769 ["""\
770 Standard include data file:
772 .. include:: <isogrk4.txt>
773 """,
774 b"""\
775 <document source="test data">
776 <paragraph>
777 Standard include data file:
778 <comment xml:space="preserve">
779 This data file has been placed in the public domain.
780 <comment xml:space="preserve">
781 Derived from the Unicode character mappings available from
782 <http://www.w3.org/2003/entities/xml/>.
783 Processed by unicode2rstsubs.py, part of Docutils:
784 <http://docutils.sourceforge.net>.
785 <substitution_definition names="b.Gammad">
786 \\u03dc
787 <substitution_definition names="b.gammad">
788 \\u03dd
789 """.decode('raw_unicode_escape')],
790 ["""\
791 Nonexistent standard include data file:
793 .. include:: <nonexistent>
794 """,
795 """\
796 <document source="test data">
797 <paragraph>
798 Nonexistent standard include data file:
799 <system_message level="4" line="3" source="test data" type="SEVERE">
800 <paragraph>
801 Problems with "include" directive path:
802 InputError: [Errno 2] No such file or directory: '%s'.
803 <literal_block xml:space="preserve">
804 .. include:: <nonexistent>
805 """ % nonexistent_rel],
806 ["""\
807 Include start-line/end-line Test
809 .. include:: %s
810 :start-line: 3
811 :end-line: 4
812 """ % include2,
813 """\
814 <document source="test data">
815 <paragraph>
816 Include start-line/end-line Test
817 <paragraph>
818 This file (include2.txt) is used by
819 """],
820 ["""\
821 Include start-line/end-line + start-after Test
823 .. include:: %s
824 :start-line: 2
825 :end-line: 5
826 :start-after: here
828 Text search is limited to the specified lines.
829 """ % include12,
830 """\
831 <document source="test data">
832 <paragraph>
833 Include start-line/end-line + start-after Test
834 <paragraph>
835 In include12.txt (after "start here", before "stop here")
836 <paragraph>
837 Text search is limited to the specified lines.
838 """],
839 ["""\
840 Include start-after/end-before Test
842 .. include:: %s
843 :start-after: .. start here
844 :end-before: .. stop here
846 A paragraph.
847 """ % include12,
848 """\
849 <document source="test data">
850 <paragraph>
851 Include start-after/end-before Test
852 <paragraph>
853 In include12.txt (after "start here", before "stop here")
854 <paragraph>
855 A paragraph.
856 """],
857 ["""\
858 Include start-after/end-before Test, single option variant
860 .. include:: %s
861 :end-before: .. start here
863 .. include:: %s
864 :start-after: .. stop here
866 A paragraph.
867 """ % (include12, include12),
868 """\
869 <document source="test data">
870 <paragraph>
871 Include start-after/end-before Test, single option variant
872 <paragraph>
873 In include12.txt (but before "start here")
874 <paragraph>
875 In include12.txt (after "stop here")
876 <paragraph>
877 A paragraph.
878 """],
879 ["""\
880 Include start-after/end-before multi-line test.
882 .. include:: %s
883 :start-after: From: me
884 To: you
885 :end-before: -------
886 -- mork of ork
888 .. include:: %s
889 :start-after: From: me
890 To: you
891 :end-before:
892 -------
893 -- mork of ork
895 A paragraph.
896 """ % (include13, include13),
897 """\
898 <document source="test data">
899 <paragraph>
900 Include start-after/end-before multi-line test.
901 <system_message level="4" line="3" source="test data" type="SEVERE">
902 <paragraph>
903 Problem with "end-before" option of "include" directive:
904 Text not found.
905 <literal_block xml:space="preserve">
906 .. include:: %s
907 :start-after: From: me
908 To: you
909 :end-before: -------
910 -- mork of ork
911 <paragraph>
912 In include13.txt (between header and signature)
913 <paragraph>
914 A paragraph.
915 """ % include13],
916 ["""\
917 Error handling test; "end-before" error handling tested in previous test.
919 .. include:: %s
920 :start-after: bad string
921 :end-before: mork of ork
922 """ % include13,
923 """\
924 <document source="test data">
925 <paragraph>
926 Error handling test; "end-before" error handling tested in previous test.
927 <system_message level="4" line="3" source="test data" type="SEVERE">
928 <paragraph>
929 Problem with "start-after" option of "include" directive:
930 Text not found.
931 <literal_block xml:space="preserve">
932 .. include:: %s
933 :start-after: bad string
934 :end-before: mork of ork
935 """ % include13],
936 ["""\
937 TAB expansion with literal include:
939 .. include:: %s
940 :literal:
941 """ % include_literal,
942 """\
943 <document source="test data">
944 <paragraph>
945 TAB expansion with literal include:
946 <literal_block source="%s" xml:space="preserve">
947 Literal included this should **not** be *marked* `up`.
948 <- leading raw tab.
950 Newlines
952 normalized.
953 """ % include_literal],
954 ["""\
955 Custom TAB expansion with literal include:
957 .. include:: %s
958 :literal:
959 :tab-width: 2
960 """ % include_literal,
961 """\
962 <document source="test data">
963 <paragraph>
964 Custom TAB expansion with literal include:
965 <literal_block source="%s" xml:space="preserve">
966 Literal included this should **not** be *marked* `up`.
967 <- leading raw tab.
969 Newlines
971 normalized.
972 """ % include_literal],
973 ["""\
974 No TAB expansion with literal include:
976 .. include:: %s
977 :literal:
978 :tab-width: -1
979 """ % include_literal,
980 """\
981 <document source="test data">
982 <paragraph>
983 No TAB expansion with literal include:
984 <literal_block source="%s" xml:space="preserve">
985 Literal included this should **not** be *marked* `up`.
986 \t<- leading raw tab.
988 Newlines
990 normalized.
991 """ % include_literal],
994 totest['include-code'] = [
995 ["""\
996 Included code
998 .. include:: %s
999 :code: rst
1000 """ % include1,
1001 """\
1002 <document source="test data">
1003 <paragraph>
1004 Included code
1005 <literal_block classes="code rst" source="%s" xml:space="preserve">
1006 <inline classes="generic heading">
1007 Inclusion 1
1009 <inline classes="generic heading">
1010 -----------
1013 This file is used by \n\
1014 <inline classes="literal string">
1015 ``test_include.py``
1017 """ % reldir(include1)],
1018 ["""\
1019 Included code
1021 .. include:: %s
1022 :code: rst
1023 :number-lines:
1024 """ % include1,
1025 """\
1026 <document source="test data">
1027 <paragraph>
1028 Included code
1029 <literal_block classes="code rst" source="%s" xml:space="preserve">
1030 <inline classes="ln">
1031 1 \n\
1032 <inline classes="generic heading">
1033 Inclusion 1
1035 <inline classes="ln">
1036 2 \n\
1037 <inline classes="generic heading">
1038 -----------
1040 <inline classes="ln">
1041 3 \n\
1043 <inline classes="ln">
1044 4 \n\
1045 This file is used by \n\
1046 <inline classes="literal string">
1047 ``test_include.py``
1049 """ % reldir(include1)],
1050 ["""\
1051 TAB expansion with included code:
1053 .. include:: %s
1054 :code: rst
1055 """ % include_literal,
1056 """\
1057 <document source="test data">
1058 <paragraph>
1059 TAB expansion with included code:
1060 <literal_block classes="code rst" source="%s" xml:space="preserve">
1061 Literal included this should \n\
1062 <inline classes="generic strong">
1063 **not**
1064 be \n\
1065 <inline classes="generic emph">
1066 *marked*
1068 <inline classes="name variable">
1069 `up`
1071 <- leading raw tab.
1073 Newlines
1075 normalized.
1076 """ % include_literal],
1077 ["""\
1078 Custom TAB expansion with included code:
1080 .. include:: %s
1081 :code: rst
1082 :tab-width: 2
1083 """ % include_literal,
1084 """\
1085 <document source="test data">
1086 <paragraph>
1087 Custom TAB expansion with included code:
1088 <literal_block classes="code rst" source="%s" xml:space="preserve">
1089 Literal included this should \n\
1090 <inline classes="generic strong">
1091 **not**
1092 be \n\
1093 <inline classes="generic emph">
1094 *marked*
1096 <inline classes="name variable">
1097 `up`
1099 <- leading raw tab.
1101 Newlines
1103 normalized.
1104 """ % include_literal],
1105 ["""\
1106 Custom TAB expansion with included code:
1108 .. include:: %s
1109 :code: rst
1110 :tab-width: -1
1111 """ % include_literal,
1112 """\
1113 <document source="test data">
1114 <paragraph>
1115 Custom TAB expansion with included code:
1116 <literal_block classes="code rst" source="%s" xml:space="preserve">
1117 Literal included this should \n\
1118 <inline classes="generic strong">
1119 **not**
1120 be \n\
1121 <inline classes="generic emph">
1122 *marked*
1124 <inline classes="name variable">
1125 `up`
1127 \t<- leading raw tab.
1129 Newlines
1131 normalized.
1132 """ % include_literal],
1133 ["""\
1134 Including includes/include14.txt
1136 .. include:: %s
1137 """ % include14,
1138 """\
1139 <document source="test data">
1140 <paragraph>
1141 Including includes/include14.txt
1142 <paragraph>
1143 Including more/include6.txt as rst-code from includes/include14.txt:
1144 <literal_block classes="code rst" source="%s" xml:space="preserve">
1145 In includes/more/include6.txt
1147 <inline classes="punctuation">
1150 <inline classes="operator word">
1151 include
1152 <inline classes="punctuation">
1154 ../sibling/include7.txt
1155 """ % reldir(include6)],
1156 ["""\
1157 Circular inclusion
1159 .. include:: %s
1160 """ % include15,
1161 """\
1162 <document source="test data">
1163 <paragraph>
1164 Circular inclusion
1165 <paragraph>
1166 File "include15.txt": example of rekursive inclusion.
1167 <paragraph>
1168 File "include16.txt": example of rekursive inclusion.
1169 <system_message level="2" line="3" source="%s" type="WARNING">
1170 <paragraph>
1171 circular inclusion in "include" directive: %s < %s < %s < test data
1172 <literal_block xml:space="preserve">
1173 .. include:: include15.txt
1174 <paragraph>
1175 No loop when clipping before the "include" directive:
1176 <paragraph>
1177 File "include15.txt": example of rekursive inclusion.
1178 """ % (reldir(include16), reldir(include15),
1179 reldir(include16), reldir(include15))],
1180 ["""\
1181 Circular inclusion with clipping.
1183 .. include:: %s
1184 :start-line: 2
1185 """ % include16,
1186 """\
1187 <document source="test data">
1188 <paragraph>
1189 Circular inclusion with clipping.
1190 <paragraph>
1191 File "include15.txt": example of rekursive inclusion.
1192 <paragraph>
1193 File "include16.txt": example of rekursive inclusion.
1194 <system_message level="2" line="3" source="%s" type="WARNING">
1195 <paragraph>
1196 circular inclusion in "include" directive: %s < %s < %s < %s < test data
1197 <literal_block xml:space="preserve">
1198 .. include:: include15.txt
1199 <paragraph>
1200 No loop when clipping before the "include" directive:
1201 <paragraph>
1202 File "include15.txt": example of rekursive inclusion.
1203 <paragraph>
1204 No loop when clipping before the "include" directive:
1205 <paragraph>
1206 File "include15.txt": example of rekursive inclusion.
1207 """ % (reldir(include16), reldir(include15), reldir(include16),
1208 reldir(include15), reldir(include16))],
1211 if __name__ == '__main__':
1212 import unittest
1213 unittest.main(defaultTest='suite')