~ubuntu-branches/ubuntu/jaunty/python-docutils/jaunty

« back to all changes in this revision

Viewing changes to test/test_parsers/test_rst/test_directives/test_raw.py

  • Committer: Bazaar Package Importer
  • Author(s): martin f. krafft
  • Date: 2006-07-10 11:45:05 UTC
  • mfrom: (2.1.4 edgy)
  • Revision ID: james.westby@ubuntu.com-20060710114505-otkhqcslevewxmz5
Tags: 0.4-3
Added build dependency on python-central (closes: #377580).

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
# Author: David Goodger
4
4
# Contact: goodger@users.sourceforge.net
5
 
# Revision: $Revision: 1.2 $
6
 
# Date: $Date: 2002/10/18 04:55:21 $
 
5
# Revision: $Revision: 4213 $
 
6
# Date: $Date: 2005-12-14 15:51:59 +0100 (Wed, 14 Dec 2005) $
7
7
# Copyright: This module has been placed in the public domain.
8
8
 
9
9
"""
11
11
"""
12
12
 
13
13
import os.path
 
14
import sys
14
15
from __init__ import DocutilsTestSupport
15
16
 
16
17
 
19
20
    s.generateTests(totest)
20
21
    return s
21
22
 
22
 
mydir = os.path.dirname(suite.func_code.co_filename)
 
23
mydir = 'test_parsers/test_rst/test_directives/'
23
24
raw1 = os.path.join(mydir, 'raw1.txt')
 
25
utf_16_file = os.path.join(mydir, 'utf-16.csv')
 
26
utf_16_file_rel = DocutilsTestSupport.utils.relative_path(None, utf_16_file)
24
27
 
25
28
totest = {}
26
29
 
76
79
            
77
80
               <p>Can't have both content and file attribute.</p>
78
81
"""],
 
82
[r"""
 
83
.. raw:: latex html
 
84
 
 
85
   \[ \sum_{n=1}^\infty \frac{1}{n} \text{ etc.} \]
 
86
""",
 
87
"""\
 
88
<document source="test data">
 
89
    <raw format="latex html" xml:space="preserve">
 
90
        \\[ \\sum_{n=1}^\\infty \\frac{1}{n} \\text{ etc.} \\]
 
91
"""],
 
92
["""\
 
93
.. raw:: html
 
94
   :file: %s
 
95
   :encoding: utf-16
 
96
""" % utf_16_file_rel,
 
97
"""\
 
98
<document source="test data">
 
99
    <raw format="html" source="%s" xml:space="preserve">
 
100
        "Treat", "Quantity", "Description"
 
101
        "Albatr\xb0\xdf", 2.99, "\xa1On a \\u03c3\\u03c4\\u03b9\\u03ba!"
 
102
        "Crunchy Frog", 1.49, "If we took the b\xf6nes out, it wouldn\\u2019t be
 
103
        crunchy, now would it?"
 
104
        "Gannet Ripple", 1.99, "\xbfOn a \\u03c3\\u03c4\\u03b9\\u03ba?"
 
105
""" % utf_16_file_rel],
 
106
["""\
 
107
Raw input file is UTF-16-encoded, and is not valid ASCII.
 
108
 
 
109
.. raw:: html
 
110
   :file: %s
 
111
   :encoding: ascii
 
112
""" % utf_16_file_rel,
 
113
"""\
 
114
<document source="test data">
 
115
    <paragraph>
 
116
        Raw input file is UTF-16-encoded, and is not valid ASCII.
 
117
    <system_message level="4" line="3" source="test data" type="SEVERE">
 
118
        <paragraph>
 
119
            Problem with "raw" directive:
 
120
            UnicodeError: Unable to decode input data.  Tried the following encodings: \'ascii\'.
 
121
            (UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe in position 0: ordinal not in range(128))
 
122
        <literal_block xml:space="preserve">
 
123
            .. raw:: html
 
124
               :file: %s
 
125
               :encoding: ascii
 
126
""" % utf_16_file_rel],
 
127
["""\
 
128
.. raw:: html
 
129
   :encoding: utf-8
 
130
 
 
131
   Should the parser complain becau\xdfe there is no :file:?  BUG?
 
132
""",
 
133
"""\
 
134
<document source="test data">
 
135
    <raw format="html" xml:space="preserve">
 
136
        Should the parser complain becau\xdfe there is no :file:?  BUG?
 
137
"""],
79
138
]
80
139
 
 
140
# Skip tests whose output contains "UnicodeDecodeError" if we are not
 
141
# using Python 2.3 or higher.
 
142
if sys.version_info < (2, 3):
 
143
    for i in range(len(totest['raw'])):
 
144
        if totest['raw'][i][1].find('UnicodeDecodeError') != -1:
 
145
            del totest['raw'][i]
 
146
            print ("Test totest['raw'][%s] skipped; "
 
147
                   "Python 2.3+ required for expected output." % i)
 
148
            # Assume we have only one of these tests.
 
149
            break
 
150
 
81
151
 
82
152
if __name__ == '__main__':
83
153
    import unittest