##// END OF EJS Templates
tests: stop direct symbol import of pprint.pprint in tests-minirst
Yuya Nishihara -
r28840:8717d460 default
parent child Browse files
Show More
@@ -1,262 +1,260 b''
1 from __future__ import absolute_import, print_function
1 from __future__ import absolute_import, print_function
2 from pprint import (
2 import pprint
3 pprint,
4 )
5 from mercurial import (
3 from mercurial import (
6 minirst,
4 minirst,
7 )
5 )
8
6
9 def debugformat(text, form, **kwargs):
7 def debugformat(text, form, **kwargs):
10 if form == 'html':
8 if form == 'html':
11 print("html format:")
9 print("html format:")
12 out = minirst.format(text, style=form, **kwargs)
10 out = minirst.format(text, style=form, **kwargs)
13 else:
11 else:
14 print("%d column format:" % form)
12 print("%d column format:" % form)
15 out = minirst.format(text, width=form, **kwargs)
13 out = minirst.format(text, width=form, **kwargs)
16
14
17 print("-" * 70)
15 print("-" * 70)
18 if type(out) == tuple:
16 if type(out) == tuple:
19 print(out[0][:-1])
17 print(out[0][:-1])
20 print("-" * 70)
18 print("-" * 70)
21 pprint(out[1])
19 pprint.pprint(out[1])
22 else:
20 else:
23 print(out[:-1])
21 print(out[:-1])
24 print("-" * 70)
22 print("-" * 70)
25 print()
23 print()
26
24
27 def debugformats(title, text, **kwargs):
25 def debugformats(title, text, **kwargs):
28 print("== %s ==" % title)
26 print("== %s ==" % title)
29 debugformat(text, 60, **kwargs)
27 debugformat(text, 60, **kwargs)
30 debugformat(text, 30, **kwargs)
28 debugformat(text, 30, **kwargs)
31 debugformat(text, 'html', **kwargs)
29 debugformat(text, 'html', **kwargs)
32
30
33 paragraphs = """
31 paragraphs = """
34 This is some text in the first paragraph.
32 This is some text in the first paragraph.
35
33
36 A small indented paragraph.
34 A small indented paragraph.
37 It is followed by some lines
35 It is followed by some lines
38 containing random whitespace.
36 containing random whitespace.
39 \n \n \nThe third and final paragraph.
37 \n \n \nThe third and final paragraph.
40 """
38 """
41
39
42 debugformats('paragraphs', paragraphs)
40 debugformats('paragraphs', paragraphs)
43
41
44 definitions = """
42 definitions = """
45 A Term
43 A Term
46 Definition. The indented
44 Definition. The indented
47 lines make up the definition.
45 lines make up the definition.
48 Another Term
46 Another Term
49 Another definition. The final line in the
47 Another definition. The final line in the
50 definition determines the indentation, so
48 definition determines the indentation, so
51 this will be indented with four spaces.
49 this will be indented with four spaces.
52
50
53 A Nested/Indented Term
51 A Nested/Indented Term
54 Definition.
52 Definition.
55 """
53 """
56
54
57 debugformats('definitions', definitions)
55 debugformats('definitions', definitions)
58
56
59 literals = r"""
57 literals = r"""
60 The fully minimized form is the most
58 The fully minimized form is the most
61 convenient form::
59 convenient form::
62
60
63 Hello
61 Hello
64 literal
62 literal
65 world
63 world
66
64
67 In the partially minimized form a paragraph
65 In the partially minimized form a paragraph
68 simply ends with space-double-colon. ::
66 simply ends with space-double-colon. ::
69
67
70 ////////////////////////////////////////
68 ////////////////////////////////////////
71 long un-wrapped line in a literal block
69 long un-wrapped line in a literal block
72 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
70 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
73
71
74 ::
72 ::
75
73
76 This literal block is started with '::',
74 This literal block is started with '::',
77 the so-called expanded form. The paragraph
75 the so-called expanded form. The paragraph
78 with '::' disappears in the final output.
76 with '::' disappears in the final output.
79 """
77 """
80
78
81 debugformats('literals', literals)
79 debugformats('literals', literals)
82
80
83 lists = """
81 lists = """
84 - This is the first list item.
82 - This is the first list item.
85
83
86 Second paragraph in the first list item.
84 Second paragraph in the first list item.
87
85
88 - List items need not be separated
86 - List items need not be separated
89 by a blank line.
87 by a blank line.
90 - And will be rendered without
88 - And will be rendered without
91 one in any case.
89 one in any case.
92
90
93 We can have indented lists:
91 We can have indented lists:
94
92
95 - This is an indented list item
93 - This is an indented list item
96
94
97 - Another indented list item::
95 - Another indented list item::
98
96
99 - A literal block in the middle
97 - A literal block in the middle
100 of an indented list.
98 of an indented list.
101
99
102 (The above is not a list item since we are in the literal block.)
100 (The above is not a list item since we are in the literal block.)
103
101
104 ::
102 ::
105
103
106 Literal block with no indentation (apart from
104 Literal block with no indentation (apart from
107 the two spaces added to all literal blocks).
105 the two spaces added to all literal blocks).
108
106
109 1. This is an enumerated list (first item).
107 1. This is an enumerated list (first item).
110 2. Continuing with the second item.
108 2. Continuing with the second item.
111
109
112 (1) foo
110 (1) foo
113 (2) bar
111 (2) bar
114
112
115 1) Another
113 1) Another
116 2) List
114 2) List
117
115
118 Line blocks are also a form of list:
116 Line blocks are also a form of list:
119
117
120 | This is the first line.
118 | This is the first line.
121 The line continues here.
119 The line continues here.
122 | This is the second line.
120 | This is the second line.
123 """
121 """
124
122
125 debugformats('lists', lists)
123 debugformats('lists', lists)
126
124
127 options = """
125 options = """
128 There is support for simple option lists,
126 There is support for simple option lists,
129 but only with long options:
127 but only with long options:
130
128
131 -X, --exclude filter an option with a short and long option with an argument
129 -X, --exclude filter an option with a short and long option with an argument
132 -I, --include an option with both a short option and a long option
130 -I, --include an option with both a short option and a long option
133 --all Output all.
131 --all Output all.
134 --both Output both (this description is
132 --both Output both (this description is
135 quite long).
133 quite long).
136 --long Output all day long.
134 --long Output all day long.
137
135
138 --par This option has two paragraphs in its description.
136 --par This option has two paragraphs in its description.
139 This is the first.
137 This is the first.
140
138
141 This is the second. Blank lines may be omitted between
139 This is the second. Blank lines may be omitted between
142 options (as above) or left in (as here).
140 options (as above) or left in (as here).
143
141
144
142
145 The next paragraph looks like an option list, but lacks the two-space
143 The next paragraph looks like an option list, but lacks the two-space
146 marker after the option. It is treated as a normal paragraph:
144 marker after the option. It is treated as a normal paragraph:
147
145
148 --foo bar baz
146 --foo bar baz
149 """
147 """
150
148
151 debugformats('options', options)
149 debugformats('options', options)
152
150
153 fields = """
151 fields = """
154 :a: First item.
152 :a: First item.
155 :ab: Second item. Indentation and wrapping
153 :ab: Second item. Indentation and wrapping
156 is handled automatically.
154 is handled automatically.
157
155
158 Next list:
156 Next list:
159
157
160 :small: The larger key below triggers full indentation here.
158 :small: The larger key below triggers full indentation here.
161 :much too large: This key is big enough to get its own line.
159 :much too large: This key is big enough to get its own line.
162 """
160 """
163
161
164 debugformats('fields', fields)
162 debugformats('fields', fields)
165
163
166 containers = """
164 containers = """
167 Normal output.
165 Normal output.
168
166
169 .. container:: debug
167 .. container:: debug
170
168
171 Initial debug output.
169 Initial debug output.
172
170
173 .. container:: verbose
171 .. container:: verbose
174
172
175 Verbose output.
173 Verbose output.
176
174
177 .. container:: debug
175 .. container:: debug
178
176
179 Debug output.
177 Debug output.
180 """
178 """
181
179
182 debugformats('containers (normal)', containers)
180 debugformats('containers (normal)', containers)
183 debugformats('containers (verbose)', containers, keep=['verbose'])
181 debugformats('containers (verbose)', containers, keep=['verbose'])
184 debugformats('containers (debug)', containers, keep=['debug'])
182 debugformats('containers (debug)', containers, keep=['debug'])
185 debugformats('containers (verbose debug)', containers,
183 debugformats('containers (verbose debug)', containers,
186 keep=['verbose', 'debug'])
184 keep=['verbose', 'debug'])
187
185
188 roles = """Please see :hg:`add`."""
186 roles = """Please see :hg:`add`."""
189 debugformats('roles', roles)
187 debugformats('roles', roles)
190
188
191
189
192 sections = """
190 sections = """
193 Title
191 Title
194 =====
192 =====
195
193
196 Section
194 Section
197 -------
195 -------
198
196
199 Subsection
197 Subsection
200 ''''''''''
198 ''''''''''
201
199
202 Markup: ``foo`` and :hg:`help`
200 Markup: ``foo`` and :hg:`help`
203 ------------------------------
201 ------------------------------
204 """
202 """
205 debugformats('sections', sections)
203 debugformats('sections', sections)
206
204
207
205
208 admonitions = """
206 admonitions = """
209 .. note::
207 .. note::
210
208
211 This is a note
209 This is a note
212
210
213 - Bullet 1
211 - Bullet 1
214 - Bullet 2
212 - Bullet 2
215
213
216 .. warning:: This is a warning Second
214 .. warning:: This is a warning Second
217 input line of warning
215 input line of warning
218
216
219 .. danger::
217 .. danger::
220 This is danger
218 This is danger
221 """
219 """
222
220
223 debugformats('admonitions', admonitions)
221 debugformats('admonitions', admonitions)
224
222
225 comments = """
223 comments = """
226 Some text.
224 Some text.
227
225
228 .. A comment
226 .. A comment
229
227
230 .. An indented comment
228 .. An indented comment
231
229
232 Some indented text.
230 Some indented text.
233
231
234 ..
232 ..
235
233
236 Empty comment above
234 Empty comment above
237 """
235 """
238
236
239 debugformats('comments', comments)
237 debugformats('comments', comments)
240
238
241
239
242 data = [['a', 'b', 'c'],
240 data = [['a', 'b', 'c'],
243 ['1', '2', '3'],
241 ['1', '2', '3'],
244 ['foo', 'bar', 'baz this list is very very very long man']]
242 ['foo', 'bar', 'baz this list is very very very long man']]
245
243
246 rst = minirst.maketable(data, 2, True)
244 rst = minirst.maketable(data, 2, True)
247 table = ''.join(rst)
245 table = ''.join(rst)
248
246
249 print(table)
247 print(table)
250
248
251 debugformats('table', table)
249 debugformats('table', table)
252
250
253 data = [['s', 'long', 'line\ngoes on here'],
251 data = [['s', 'long', 'line\ngoes on here'],
254 ['', 'xy', 'tried to fix here\n by indenting']]
252 ['', 'xy', 'tried to fix here\n by indenting']]
255
253
256 rst = minirst.maketable(data, 1, False)
254 rst = minirst.maketable(data, 1, False)
257 table = ''.join(rst)
255 table = ''.join(rst)
258
256
259 print(table)
257 print(table)
260
258
261 debugformats('table+nl', table)
259 debugformats('table+nl', table)
262
260
General Comments 0
You need to be logged in to leave comments. Login now