4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
8 Tests for misc.py "raw" directive.
13 from __init__
import DocutilsTestSupport
14 from docutils
._compat
import b
17 s
= DocutilsTestSupport
.ParserTestSuite()
18 s
.generateTests(totest
)
21 mydir
= 'test_parsers/test_rst/test_directives/'
22 raw1
= os
.path
.join(mydir
, 'raw1.txt')
23 utf_16_file
= os
.path
.join(mydir
, 'utf-16.csv')
24 utf_16_file_rel
= DocutilsTestSupport
.utils
.relative_path(None, utf_16_file
)
25 utf_16_error_str
= ("UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe "
26 "in position 0: ordinal not in range(128)")
27 if sys
.version_info
< (3,0):
28 utf_16_error_str
= ("UnicodeError: Unable to decode input data. "
29 "Tried the following encodings: 'ascii'.\n"
30 " (%s)" % utf_16_error_str
)
38 <span>This is some plain old raw text.</span>
41 <document source="test data">
42 <raw format="html" xml:space="preserve">
43 <span>This is some plain old raw text.</span>
50 <document source="test data">
51 <raw format="html" source="%s" xml:space="preserve">
52 <p>This file is used by <tt>test_raw.py</tt>.</p>
53 """ % DocutilsTestSupport
.utils
.relative_path(None, raw1
)],
57 :url: http://example.org/
60 <document source="test data">
61 <system_message level="3" line="1" source="test data" type="ERROR">
63 The "file" and "url" options may not be simultaneously specified for the "raw" directive.
64 <literal_block xml:space="preserve">
67 :url: http://example.org/
73 <p>Can't have both content and file attribute.</p>
76 <document source="test data">
77 <system_message level="3" line="1" source="test data" type="ERROR">
79 "raw" directive may not both specify an external file and have content.
80 <literal_block xml:space="preserve">
84 <p>Can't have both content and file attribute.</p>
89 \[ \sum_{n=1}^\infty \frac{1}{n} \text{ etc.} \]
92 <document source="test data">
93 <raw format="latex html" xml:space="preserve">
94 \\[ \\sum_{n=1}^\\infty \\frac{1}{n} \\text{ etc.} \\]
100 """ % utf_16_file_rel
,
102 <document source="test data">
103 <raw format="html" source="%s" xml:space="preserve">
104 "Treat", "Quantity", "Description"
105 "Albatr\xb0\xdf", 2.99, "\xa1On a \\u03c3\\u03c4\\u03b9\\u03ba!"
106 "Crunchy Frog", 1.49, "If we took the b\xf6nes out, it wouldn\\u2019t be
107 crunchy, now would it?"
108 "Gannet Ripple", 1.99, "\xbfOn a \\u03c3\\u03c4\\u03b9\\u03ba?"
109 """ % utf_16_file_rel
).decode('raw_unicode_escape')],
111 Raw input file is UTF-16-encoded, and is not valid ASCII.
116 """ % utf_16_file_rel
,
118 <document source="test data">
120 Raw input file is UTF-16-encoded, and is not valid ASCII.
121 <system_message level="4" line="3" source="test data" type="SEVERE">
123 Problem with "raw" directive:
125 <literal_block xml:space="preserve">
129 """ % (utf_16_error_str
, utf_16_file_rel
)],
134 Should the parser complain becau\xdfe there is no :file:? BUG?
137 <document source="test data">
138 <raw format="html" xml:space="preserve">
139 Should the parser complain becau\xdfe there is no :file:? BUG?
145 <document source="test data">
146 <system_message level="3" line="1" source="test data" type="ERROR">
148 Content block expected for the "raw" directive; none found.
149 <literal_block xml:space="preserve">
154 :file: non-existent.file
157 <document source="test data">
158 <system_message level="4" line="1" source="test data" type="SEVERE">
160 Problems with "raw" directive path:
161 InputError: [Errno 2] No such file or directory: 'non-existent.file'.
162 <literal_block xml:space="preserve">
164 :file: non-existent.file
166 # note that this output is rewritten below for certain python versions
169 if __name__
== '__main__':
171 unittest
.main(defaultTest
='suite')