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
16 s
= DocutilsTestSupport
.ParserTestSuite()
17 s
.generateTests(totest
)
20 mydir
= 'test_parsers/test_rst/test_directives/'
21 raw1
= os
.path
.join(mydir
, 'raw1.txt')
22 utf_16_file
= os
.path
.join(mydir
, 'utf-16.csv')
23 utf_16_file_rel
= DocutilsTestSupport
.utils
.relative_path(None, utf_16_file
)
24 utf_16_error_str
= ("UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe "
25 "in position 0: ordinal not in range(128)")
26 if sys
.version_info
< (3,0):
27 utf_16_error_str
= ("UnicodeError: Unable to decode input data. "
28 "Tried the following encodings: 'ascii'.\n"
29 " (%s)" % utf_16_error_str
)
37 <span>This is some plain old raw text.</span>
40 <document source="test data">
41 <raw format="html" xml:space="preserve">
42 <span>This is some plain old raw text.</span>
49 <document source="test data">
50 <raw format="html" source="%s" xml:space="preserve">
51 <p>This file is used by <tt>test_raw.py</tt>.</p>
52 """ % DocutilsTestSupport
.utils
.relative_path(None, raw1
)],
56 :url: http://example.org/
59 <document source="test data">
60 <system_message level="3" line="1" source="test data" type="ERROR">
62 The "file" and "url" options may not be simultaneously specified for the "raw" directive.
63 <literal_block xml:space="preserve">
66 :url: http://example.org/
72 <p>Can't have both content and file attribute.</p>
75 <document source="test data">
76 <system_message level="3" line="1" source="test data" type="ERROR">
78 "raw" directive may not both specify an external file and have content.
79 <literal_block xml:space="preserve">
83 <p>Can't have both content and file attribute.</p>
88 \[ \sum_{n=1}^\infty \frac{1}{n} \text{ etc.} \]
91 <document source="test data">
92 <raw format="latex html" xml:space="preserve">
93 \\[ \\sum_{n=1}^\\infty \\frac{1}{n} \\text{ etc.} \\]
99 """ % utf_16_file_rel
,
101 <document source="test data">
102 <raw format="html" source="%s" xml:space="preserve">
103 "Treat", "Quantity", "Description"
104 "Albatr\xb0\xdf", 2.99, "\xa1On a \\u03c3\\u03c4\\u03b9\\u03ba!"
105 "Crunchy Frog", 1.49, "If we took the b\xf6nes out, it wouldn\\u2019t be
106 crunchy, now would it?"
107 "Gannet Ripple", 1.99, "\xbfOn a \\u03c3\\u03c4\\u03b9\\u03ba?"
108 """.decode('raw_unicode_escape') % utf_16_file_rel
],
110 Raw input file is UTF-16-encoded, and is not valid ASCII.
115 """ % utf_16_file_rel
,
117 <document source="test data">
119 Raw input file is UTF-16-encoded, and is not valid ASCII.
120 <system_message level="4" line="3" source="test data" type="SEVERE">
122 Problem with "raw" directive:
124 <literal_block xml:space="preserve">
128 """ % (utf_16_error_str
, utf_16_file_rel
)],
133 Should the parser complain becau\xdfe there is no :file:? BUG?
136 <document source="test data">
137 <raw format="html" xml:space="preserve">
138 Should the parser complain becau\xdfe there is no :file:? BUG?
144 <document source="test data">
145 <system_message level="3" line="1" source="test data" type="ERROR">
147 Content block expected for the "raw" directive; none found.
148 <literal_block xml:space="preserve">
153 :file: non-existent.file
156 <document source="test data">
157 <system_message level="4" line="1" source="test data" type="SEVERE">
159 Problems with "raw" directive path:
160 InputError: [Errno 2] No such file or directory: 'non-existent.file'.
161 <literal_block xml:space="preserve">
163 :file: non-existent.file
165 # note that this output is rewritten below for certain python versions
168 if __name__
== '__main__':
170 unittest
.main(defaultTest
='suite')