4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
8 Tests for misc.py "include" directive.
13 from __init__
import DocutilsTestSupport
14 from docutils
.parsers
.rst
import states
15 from docutils
._compat
import b
16 from docutils
.utils
.code_analyzer
import with_pygments
19 s
= DocutilsTestSupport
.ParserTestSuite()
21 del(totest
['include-code'])
22 s
.generateTests(totest
)
25 # prepend this directory (relative to the test root):
27 return os
.path
.join('test_parsers/test_rst/test_directives/', path
)
28 # make `path` relative with utils.relative_path():
30 return DocutilsTestSupport
.utils
.relative_path(None, path
)
32 include1
= mydir('include1.txt')
33 include2
= mydir('include2.txt')
34 include3
= mydir('include3.txt')
35 include8
= mydir('include8.txt')
36 include10
= mydir('include10.txt')
37 include11
= mydir('include 11.txt')
38 include12
= mydir('include12.txt')
39 include13
= mydir('include13.txt')
40 include_literal
= mydir('include_literal.txt')
41 utf_16_file
= mydir('utf-16.csv')
42 utf_16_error_str
= ("UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe "
43 "in position 0: ordinal not in range(128)")
44 if sys
.version_info
< (3,0):
45 utf_16_error_str
= ("UnicodeError: Unable to decode input data. "
46 "Tried the following encodings: 'ascii'.\n"
47 " (%s)" % utf_16_error_str
)
48 nonexistent
= os
.path
.join(os
.path
.dirname(states
.__file
__),
49 'include', 'nonexistent')
50 nonexistent_rel
= DocutilsTestSupport
.utils
.relative_path(
51 os
.path
.join(DocutilsTestSupport
.testroot
, 'dummy'), nonexistent
)
65 <document source="test data">
66 <section ids="include-test" names="include\ test">
69 <section ids="inclusion-1" names="inclusion\ 1">
73 This file is used by \n\
92 <document source="test data">
93 <section ids="include-test" names="include\ test">
96 <literal_block classes="test" ids="my-name" names="my\ name" source="%s" xml:space="preserve">
100 This file is used by ``test_include.py``.
103 """ % reldir(include1
)],
105 Literal include, add line numbers
112 <document source="test data">
114 Literal include, add line numbers
115 <literal_block source="%s" xml:space="preserve">
116 <inline classes="ln">
119 <inline classes="ln">
122 <inline classes="ln">
125 <inline classes="ln">
127 This file is used by ``test_include.py``.
128 """ % reldir(include1
)],
138 <document source="test data">
141 <literal_block classes="code test" ids="my-name" names="my\ name" source="%s" xml:space="preserve">
145 This file is used by ``test_include.py``.
146 """ % reldir(include1
)],
148 Include code, add line numbers
155 <document source="test data">
157 Include code, add line numbers
158 <literal_block classes="code" source="%s" xml:space="preserve">
159 <inline classes="ln">
162 <inline classes="ln">
165 <inline classes="ln">
168 <inline classes="ln">
170 This file is used by ``test_include.py``.
171 """ % reldir(include1
)],
173 Let's test the parse context.
175 This paragraph is in a block quote.
179 The included paragraphs should also be in the block quote.
182 <document source="test data">
184 Let's test the parse context.
187 This paragraph is in a block quote.
189 Here are some paragraphs
190 that can appear at any level.
192 This file (include2.txt) is used by
197 The included paragraphs should also be in the block quote.
203 .. include:: nonexistent.txt
208 <document source="test data">
209 <section ids="include-test" names="include\ test">
212 <system_message level="4" line="4" source="test data" type="SEVERE">
214 Problems with "include" directive path:
215 InputError: [Errno 2] No such file or directory: 'nonexistent.txt'.
216 <literal_block xml:space="preserve">
217 .. include:: nonexistent.txt
230 """ % (include1
, include1
),
232 <document source="test data">
233 <section ids="include-test" names="include\ test">
236 <section dupnames="inclusion\ 1" ids="inclusion-1">
244 <section dupnames="inclusion\ 1" ids="id1">
247 <system_message backrefs="id1" level="1" line="2" source="%s" type="INFO">
249 Duplicate implicit target name: "inclusion 1".
257 """ % reldir(include1
)],
269 """ % (include1
, include1
),
271 <document source="test data">
272 <section ids="include-test" names="include\ test">
275 <section dupnames="inclusion\ 1" ids="inclusion-1">
279 This file is used by \n\
284 <section dupnames="inclusion\ 1" ids="id1">
287 <system_message backrefs="id1" level="1" line="2" source="%s" type="INFO">
289 Duplicate implicit target name: "inclusion 1".
291 This file is used by \n\
297 """ % reldir(include1
)],
304 <document source="test data">
310 In includes/include4.txt
312 In includes/include5.txt
314 In includes/more/include6.txt
316 In includes/sibling/include7.txt
324 (Section contents in nested parse; slice of input_lines ViewList.)
329 <document source="test data">
332 <section ids="section" names="section">
336 (Section contents in nested parse; slice of input_lines ViewList.)
340 In includes/include4.txt
342 In includes/include5.txt
344 In includes/more/include6.txt
346 In includes/sibling/include7.txt
349 Testing relative includes:
354 <document source="test data">
356 Testing relative includes:
360 In ../includes/include9.txt.
362 Here are some paragraphs
363 that can appear at any level.
365 This file (include2.txt) is used by
375 """ % reldir(utf_16_file
),
377 <document source="test data">
381 "Treat", "Quantity", "Description"
382 "Albatr\xb0\xdf", 2.99, "\xa1On a \\u03c3\\u03c4\\u03b9\\u03ba!"
383 "Crunchy Frog", 1.49, "If we took the b\xf6nes out, it wouldn\\u2019t be
384 crunchy, now would it?"
385 "Gannet Ripple", 1.99, "\xbfOn a \\u03c3\\u03c4\\u03b9\\u03ba?"
386 """).decode('raw_unicode_escape')],
388 Include file is UTF-16-encoded, and is not valid ASCII.
392 """ % reldir(utf_16_file
),
394 <document source="test data">
396 Include file is UTF-16-encoded, and is not valid ASCII.
397 <system_message level="4" line="3" source="test data" type="SEVERE">
399 Problem with "include" directive:
401 <literal_block xml:space="preserve">
404 """ % (utf_16_error_str
, reldir(utf_16_file
))],
408 .. include:: \u043c\u0438\u0440.txt
411 <document source="test data">
414 <system_message level="4" line="3" source="test data" type="SEVERE">
416 Problems with "include" directive path:
417 InputError: [Errno 2] No such file or directory: '\u043c\u0438\u0440.txt'.
418 <literal_block xml:space="preserve">
419 .. include:: \u043c\u0438\u0440.txt
422 Testing errors in included file:
427 <document source="test data">
429 Testing errors in included file:
430 <system_message level="3" line="1" source="%(source)s" type="ERROR">
432 Invalid character code: 0x11111111
434 <literal_block xml:space="preserve">
436 <system_message level="2" line="1" source="%(source)s" type="WARNING">
438 Substitution definition "bad" empty or invalid.
439 <literal_block xml:space="preserve">
440 .. |bad| unicode:: 0x11111111
441 <section dupnames="hi" ids="hi">
447 <system_message level="2" line="7" source="%(source)s" type="WARNING">
449 Block quote ends without a blank line; unexpected unindent.
452 <section dupnames="hi" ids="id1">
455 <system_message backrefs="id1" level="1" line="10" source="%(source)s" type="INFO">
457 Duplicate implicit target name: "hi".
458 <system_message level="4" line="12" source="%(source)s" type="SEVERE">
460 Problems with "include" directive path:
461 InputError: [Errno 2] No such file or directory: '%(nonexistent)s'.
462 <literal_block xml:space="preserve">
463 .. include:: <nonexistent>
464 <system_message level="3" line="14" source="%(source)s" type="ERROR">
466 Content block expected for the "note" directive; none found.
467 <literal_block xml:space="preserve">
469 <system_message level="3" line="16" source="%(source)s" type="ERROR">
471 Content block expected for the "admonition" directive; none found.
472 <literal_block xml:space="preserve">
475 <system_message level="3" line="19" source="%(source)s" type="ERROR">
477 Content block expected for the "epigraph" directive; none found.
478 <literal_block xml:space="preserve">
480 <system_message level="3" line="21" source="%(source)s" type="ERROR">
482 Content block expected for the "highlights" directive; none found.
483 <literal_block xml:space="preserve">
485 <system_message level="3" line="23" source="%(source)s" type="ERROR">
487 Content block expected for the "pull-quote" directive; none found.
488 <literal_block xml:space="preserve">
490 <system_message level="3" line="25" source="%(source)s" type="ERROR">
492 Invalid context: the "date" directive can only be used within a substitution definition.
493 <literal_block xml:space="preserve">
498 <system_message level="3" line="29" source="%(source)s" type="ERROR">
500 Unexpected indentation.
503 as a term may only be one line long.
504 <system_message level="3" line="31" source="%(source)s" type="ERROR">
506 Error in "admonition" directive:
507 1 argument(s) required, 0 supplied.
508 <literal_block xml:space="preserve">
511 without title and content following a blank line
512 <section ids="section-underline-too-short" names="section\ underline\ too\ short">
514 section underline too short
515 <system_message level="2" line="36" source="%(source)s" type="WARNING">
517 Title underline too short.
518 <literal_block xml:space="preserve">
519 section underline too short
523 <colspec colwidth="14">
524 <colspec colwidth="6">
541 <system_message level="2" line="43" source="%(source)s" type="WARNING">
543 Blank line required after table.
545 No blank line after table.
546 <system_message level="3" line="45" source="%(source)s" type="ERROR">
548 Error in "unicode" directive:
549 1 argument(s) required, 0 supplied.
550 <literal_block xml:space="preserve">
552 <system_message level="2" line="45" source="%(source)s" type="WARNING">
554 Substitution definition "empty" empty or invalid.
555 <literal_block xml:space="preserve">
557 <system_message level="3" line="47" source="%(source)s" type="ERROR">
559 Error in "topic" directive:
560 1 argument(s) required, 0 supplied.
561 <literal_block xml:space="preserve">
563 <system_message level="3" line="49" source="%(source)s" type="ERROR">
565 Error in "rubric" directive:
566 1 argument(s) required, 0 supplied.
567 <literal_block xml:space="preserve">
570 A rubric has no content
571 <comment xml:space="preserve">
572 _`target: No matching backquote.
573 <system_message level="2" line="52" source="%(source)s" type="WARNING">
575 malformed hyperlink target.
576 <comment xml:space="preserve">
578 <system_message level="2" line="53" source="%(source)s" type="WARNING">
580 malformed hyperlink target.
582 <definition_list_item>
586 <system_message level="1" line="57" source="%(source)s" type="INFO">
588 Blank line missing before literal block (after the "::")? Interpreted as a definition list item.
590 with no blank line above.
591 <literal_block xml:space="preserve">
593 <system_message level="3" line="61" source="%(source)s" type="ERROR">
595 Inconsistent literal block quoting.
597 $ with inconsistent quoting.
599 <problematic ids="id3" refid="id2">
603 <problematic ids="id5" refid="id4">
606 <problematic ids="id7" refid="id6">
609 <problematic ids="id9" refid="id8">
612 <system_message level="1" line="63" source="%(source)s" type="INFO">
614 No role entry for "unknown-role" in module "docutils.parsers.rst.languages.en".
615 Trying "unknown-role" as canonical role name.
616 <system_message backrefs="id3" ids="id2" level="3" line="63" source="%(source)s" type="ERROR">
618 Unknown interpreted text role "unknown-role".
619 <system_message backrefs="id5" ids="id4" level="2" line="63" source="%(source)s" type="WARNING">
621 Inline emphasis start-string without end-string.
622 <system_message backrefs="id7" ids="id6" level="2" line="63" source="%(source)s" type="WARNING">
624 Inline interpreted text or phrase reference start-string without end-string.
625 <system_message backrefs="id9" ids="id8" level="2" line="63" source="%(source)s" type="WARNING">
627 Inline strong start-string without end-string.
629 <problematic ids="id11" refid="id10">
631 <system_message backrefs="id11" ids="id10" level="3" line="68" source="%(source)s" type="ERROR">
633 PEP number must be a number from 0 to 9999; "-1" is invalid.
634 <system_message level="1" line="66" source="%(source)s" type="INFO">
636 No directive entry for "unknown" in module "docutils.parsers.rst.languages.en".
637 Trying "unknown" as canonical directive name.
638 <system_message level="3" line="70" source="%(source)s" type="ERROR">
640 Unknown directive type "unknown".
641 <literal_block xml:space="preserve">
642 .. unknown:: directive (info still reported with wrong line)
643 <system_message level="3" line="72" source="%(source)s" type="ERROR">
646 No bottom table border found.
647 <literal_block xml:space="preserve">
648 ============== ======
651 """ % {'source': reldir(include10
), 'nonexistent': reldir(nonexistent
),
653 DocutilsTestSupport
.exception_data(unichr, int("11111111", 16))[2]
656 Include file with whitespace in the path:
659 """ % reldir(include11
),
661 <document source="test data">
663 Include file with whitespace in the path:
668 Standard include data file:
670 .. include:: <isogrk4.txt>
673 <document source="test data">
675 Standard include data file:
676 <comment xml:space="preserve">
677 This data file has been placed in the public domain.
678 <comment xml:space="preserve">
679 Derived from the Unicode character mappings available from
680 <http://www.w3.org/2003/entities/xml/>.
681 Processed by unicode2rstsubs.py, part of Docutils:
682 <http://docutils.sourceforge.net>.
683 <substitution_definition names="b.Gammad">
685 <substitution_definition names="b.gammad">
687 """).decode('raw_unicode_escape')],
689 Nonexistent standard include data file:
691 .. include:: <nonexistent>
694 <document source="test data">
696 Nonexistent standard include data file:
697 <system_message level="4" line="3" source="test data" type="SEVERE">
699 Problems with "include" directive path:
700 InputError: [Errno 2] No such file or directory: '%s'.
701 <literal_block xml:space="preserve">
702 .. include:: <nonexistent>
703 """ % nonexistent_rel
],
705 Include start-line/end-line Test
712 <document source="test data">
714 Include start-line/end-line Test
716 This file (include2.txt) is used by
719 Include start-line/end-line + start-after Test
726 Text search is limited to the specified lines.
729 <document source="test data">
731 Include start-line/end-line + start-after Test
733 In include12.txt (after "start here", before "stop here")
735 Text search is limited to the specified lines.
738 Include start-after/end-before Test
741 :start-after: .. start here
742 :end-before: .. stop here
747 <document source="test data">
749 Include start-after/end-before Test
751 In include12.txt (after "start here", before "stop here")
756 Include start-after/end-before Test, single option variant
759 :end-before: .. start here
762 :start-after: .. stop here
765 """ % (include12
, include12
),
767 <document source="test data">
769 Include start-after/end-before Test, single option variant
771 In include12.txt (but before "start here")
773 In include12.txt (after "stop here")
778 Include start-after/end-before multi-line test.
781 :start-after: From: me
787 :start-after: From: me
794 """ % (include13
, include13
),
796 <document source="test data">
798 Include start-after/end-before multi-line test.
799 <system_message level="4" line="3" source="test data" type="SEVERE">
801 Problem with "end-before" option of "include" directive:
803 <literal_block xml:space="preserve">
805 :start-after: From: me
810 In include13.txt (between header and signature)
815 Error handling test; "end-before" error handling tested in previous test.
818 :start-after: bad string
819 :end-before: mork of ork
822 <document source="test data">
824 Error handling test; "end-before" error handling tested in previous test.
825 <system_message level="4" line="3" source="test data" type="SEVERE">
827 Problem with "start-after" option of "include" directive:
829 <literal_block xml:space="preserve">
831 :start-after: bad string
832 :end-before: mork of ork
835 TAB expansion with literal include:
839 """ % include_literal
,
841 <document source="test data">
843 TAB expansion with literal include:
844 <literal_block source="%s" xml:space="preserve">
845 Literal included this should **not** be *marked* `up`.
851 """ % include_literal
],
853 Custom TAB expansion with literal include:
858 """ % include_literal
,
860 <document source="test data">
862 Custom TAB expansion with literal include:
863 <literal_block source="%s" xml:space="preserve">
864 Literal included this should **not** be *marked* `up`.
870 """ % include_literal
],
872 No TAB expansion with literal include:
877 """ % include_literal
,
879 <document source="test data">
881 No TAB expansion with literal include:
882 <literal_block source="%s" xml:space="preserve">
883 Literal included this should **not** be *marked* `up`.
884 \t<- leading raw tab.
889 """ % include_literal
],
892 totest
['include-code'] = [
900 <document source="test data">
903 <literal_block classes="code rst" source="%s" xml:space="preserve">
904 <inline classes="gh">
907 <inline classes="gh">
911 This file is used by \n\
915 """ % reldir(include1
)],
924 <document source="test data">
927 <literal_block classes="code rst" source="%s" xml:space="preserve">
928 <inline classes="ln">
930 <inline classes="gh">
933 <inline classes="ln">
935 <inline classes="gh">
938 <inline classes="ln">
941 <inline classes="ln">
943 This file is used by \n\
947 """ % reldir(include1
)],
950 if __name__
== '__main__':
952 unittest
.main(defaultTest
='suite')