~ubuntu-branches/ubuntu/vivid/python-docutils/vivid

« back to all changes in this revision

Viewing changes to test/test_transforms/test_smartquotes.py

  • Committer: Package Import Robot
  • Author(s): Dmitry Shachnev
  • Date: 2012-12-18 15:06:21 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20121218150621-htq5khi7gvpex9yp
Tags: 0.10-0ubuntu1
* New upstream stable release.
* debian/patches/disable_py33_failing_tests.diff: add DEP-3 headers.
* Merged 0.9.1-2 changes from Debian.
* Bumped Standards-Version to 3.9.4, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
# -*- coding: utf8 -*-
3
 
 
4
 
# $Id$
5
 
 
 
3
# $Id: test_smartquotes.py 7540 2012-11-26 14:06:19Z milde $
 
4
#
6
5
# :Copyright: © 2011 Günter Milde.
 
6
# :Maintainer: docutils-develop@lists.sourceforge.net
7
7
# :License: Released under the terms of the `2-Clause BSD license`_, in short:
8
8
#
9
9
#    Copying and distribution of this file, with or without modification,
24
24
 
25
25
def suite():
26
26
    parser = Parser()
 
27
    settings = {'smart_quotes': True}
27
28
    s = DocutilsTestSupport.TransformTestSuite(
28
 
        parser, suite_settings={'smart_quotes': True})
 
29
        parser, suite_settings=settings)
29
30
    s.generateTests(totest)
 
31
    settings['language_code'] = 'de'
 
32
    s.generateTests(totest_de)
 
33
    settings['smart_quotes'] = 'alternative'
 
34
    s.generateTests(totest_de_alt)
30
35
    return s
31
36
 
32
37
 
33
38
totest = {}
 
39
totest_de = {}
 
40
totest_de_alt = {}
34
41
 
35
42
totest['transitions'] = ((SmartQuotes,), [
36
43
["""\
37
 
Test "smart quotes", 'single smart quotes'
 
44
Test "smart quotes", 'single smart quotes',
 
45
"'nested' smart" quotes
38
46
-- and ---also long--- dashes.
39
47
""",
40
48
u"""\
41
49
<document source="test data">
42
50
    <paragraph>
43
 
        Test “smart quotes”, ‘single smart quotes’
 
51
        Test “smart quotes”, ‘single smart quotes’,
 
52
        “‘nested’ smart” quotes
44
53
        – and —also long— dashes.
45
54
"""],
46
 
])
47
 
 
 
55
["""\
 
56
Do not "educate" quotes ``inside "literal" text`` and ::
 
57
 
 
58
  "literal" blocks.
 
59
 
 
60
Keep quotes straight in code and math: 
 
61
:code:`print "hello"` :math:`1' 12"`.
 
62
 
 
63
.. code::
 
64
 
 
65
   print "hello"
 
66
  
 
67
.. math::
 
68
 
 
69
   f'(x) = df(x)/dx
 
70
 
 
71
""",
 
72
u"""\
 
73
<document source="test data">
 
74
    <paragraph>
 
75
        Do not “educate” quotes 
 
76
        <literal>
 
77
            inside "literal" text
 
78
         and
 
79
    <literal_block xml:space="preserve">
 
80
        "literal" blocks.
 
81
    <paragraph>
 
82
        Keep quotes straight in code and math:
 
83
        <literal classes="code">
 
84
            print "hello"
 
85
         
 
86
        <math>
 
87
            1' 12"
 
88
        .
 
89
    <literal_block classes="code" xml:space="preserve">
 
90
        print "hello"
 
91
    <math_block xml:space="preserve">
 
92
        f'(x) = df(x)/dx
 
93
"""],
 
94
["""\
 
95
Quotes and inline-elements:
 
96
 
 
97
* Around "_`targets`", "*emphasized*" or "``literal``" text
 
98
  and links to "targets_".                                          
 
99
 
 
100
* Inside *"emphasized"* or other `inline "roles"`
 
101
""",
 
102
u"""\
 
103
<document source="test data">
 
104
    <paragraph>
 
105
        Quotes and inline-elements:
 
106
    <bullet_list bullet="*">
 
107
        <list_item>
 
108
            <paragraph>
 
109
                Around “
 
110
                <target ids="targets" names="targets">
 
111
                    targets
 
112
                ”, “
 
113
                <emphasis>
 
114
                    emphasized
 
115
                ” or “
 
116
                <literal>
 
117
                    literal
 
118
                ” text
 
119
                and links to “
 
120
                <reference name="targets" refname="targets">
 
121
                    targets
 
122
                ”.
 
123
        <list_item>
 
124
            <paragraph>
 
125
                Inside \n\
 
126
                <emphasis>
 
127
                    “emphasized”
 
128
                 or other \n\
 
129
                <title_reference>
 
130
                    inline “roles”\
 
131
"""],
 
132
["""\
 
133
.. class:: language-de
 
134
 
 
135
German "smart quotes" and 'single smart quotes'.
 
136
 
 
137
.. class:: language-foo
 
138
 
 
139
"Quoting style" for unknown languages is 'ASCII'.
 
140
 
 
141
.. class:: language-de-x-altquot
 
142
 
 
143
Alternative German "smart quotes" and 'single smart quotes'.
 
144
""",
 
145
u"""\
 
146
<document source="test data">
 
147
    <paragraph classes="language-de">
 
148
        German „smart quotes“ and ‚single smart quotes‘.
 
149
    <paragraph classes="language-foo">
 
150
        "Quoting style" for unknown languages is 'ASCII'.
 
151
    <paragraph classes="language-de-x-altquot">
 
152
        Alternative German »smart quotes« and ›single smart quotes‹.
 
153
    <system_message level="2" line="7" source="test data" type="WARNING">
 
154
        <paragraph>
 
155
            No smart quotes defined for language "foo".
 
156
"""],
 
157
])
 
158
 
 
159
totest_de['transitions'] = ((SmartQuotes,), [
 
160
["""\
 
161
German "smart quotes" and 'single smart quotes'.
 
162
 
 
163
.. class:: language-en-UK
 
164
 
 
165
English "smart quotes" and 'single smart quotes'.
 
166
""",
 
167
u"""\
 
168
<document source="test data">
 
169
    <paragraph>
 
170
        German „smart quotes“ and ‚single smart quotes‘.
 
171
    <paragraph classes="language-en-uk">
 
172
        English “smart quotes” and ‘single smart quotes’.
 
173
"""],
 
174
])
 
175
 
 
176
totest_de_alt['transitions'] = ((SmartQuotes,), [
 
177
["""\
 
178
Alternative German "smart quotes" and 'single smart quotes'.
 
179
 
 
180
.. class:: language-en-UK
 
181
 
 
182
English "smart quotes" and 'single smart quotes' have no alternative.
 
183
 
 
184
.. class:: language-ro
 
185
 
 
186
Alternative Romanian "smart quotes" and 'single' smart quotes.
 
187
""",
 
188
u"""\
 
189
<document source="test data">
 
190
    <paragraph>
 
191
        Alternative German »smart quotes« and ›single smart quotes‹.
 
192
    <paragraph classes="language-en-uk">
 
193
        English “smart quotes” and ‘single smart quotes’ have no alternative.
 
194
    <paragraph classes="language-ro">
 
195
        Alternative Romanian «smart quotes» and „single” smart quotes.
 
196
"""],
 
197
])
48
198
 
49
199
if __name__ == '__main__':
50
200
    import unittest