3 from info_translator
import InfoTranslator
4 from docutils
.transforms
import frontmatter
6 def strip_comments(body
):
7 return filter(lambda x
: not x
.startswith('@c '), body
)
9 class T(rst_test_utils
.TestCase
):
11 def given_input(self
, input, transforms
=[], settings_overrides
={}):
12 super(T
, self
).given_input(input, settings_overrides
)
13 self
.visitor
= InfoTranslator(self
.document
)
16 self
.document
.transformer
.add_transform(t
)
17 self
.document
.transformer
.apply_transforms()
19 self
.document
.walkabout(self
.visitor
)
21 def test_strip_comments(self
):
22 self
.visitor
.body
= ['Hello', '@c blah', 'World!']
23 self
.assertEqual(['Hello', '@c blah', 'World!'], self
.visitor
.body
)
24 self
.assertEqual(['Hello', 'World!'], strip_comments(self
.visitor
.body
))
29 def test_adds_info_header(self
):
30 self
.assertTrue(self
.visitor
.astext().startswith('\\input texinfo'))
36 ''', transforms
= [frontmatter
.DocTitle
])
37 self
.assertEqual(['@node Top', '@top Hello, world!'], self
.visitor
.body
)
39 def test_subtitle(self
):
48 ''', transforms
= [frontmatter
.DocTitle
])
49 self
.assertEqual(['@node Top', '@top Title!',
50 '@majorheading Subtitle'],
53 def test_subsection(self
):
64 self
.assertEqual(['@chapter Chapter 1',
66 '@subsection Subsection 1'],
69 def test_section_layering(self
):
86 self
.assertEqual(['@chapter The Problem',
88 '@subsection Lunar mold',
90 '@chapter A Modest Solution'],
93 def test_beyond_subsections(self
):
114 self
.assertEqual(['@chapter Chapter 1',
115 '@section Section 1',
116 '@subsection Subsection 1',
117 '@subsection Something else',
118 '@subsection Subsection 2',
119 '@section Section 2'],
122 def test_comments_are_comments(self
):
126 self
.assertEqual(['@c hello-world:'], self
.visitor
.body
)
128 def test_paragraph_text_is_normal_text(self
):
130 Someone left the cake out in the rain.
131 I don't think that I can take it.
133 self
.assertEqual(["Someone left the cake out in the rain.\nI don't think that I can take it.", ''], self
.visitor
.body
)
135 def test_two_paragraphs(self
):
137 MacArthur's park is melting in the dark.
139 Someone left the cake out in the rain.
140 I don't think that I can take it.
142 self
.assertEqual(["MacArthur's park is melting in the dark.", '',
143 "Someone left the cake out in the rain.\nI don't think that I can take it.", ''], self
.visitor
.body
)
146 def test_single_bullet_list(self
):
150 self
.assertEqual(["@itemize @bullet",
152 "@end @itemize", ""], self
.visitor
.body
)
154 def test_three_bullet_list(self
):
160 self
.assertEqual(["@itemize @bullet",
163 "@item", "bread", "",
164 "@end @itemize", ""], self
.visitor
.body
)
166 def test_single_enumerated_list(self
):
168 (1) I was transferred to the moon.
170 self
.assertEqual(["@enumerate 1",
171 "@item", "I was transferred to the moon.", "",
172 "@end enumerate", ""], self
.visitor
.body
)
174 def test_three_item_enumerated_list(self
):
176 (1) I was transferred to the moon.
177 (2) Worse pay, better hours.
178 (3) Worse pay, better fellow workers.
180 self
.assertEqual(["@enumerate 1",
181 "@item", "I was transferred to the moon.", "",
182 "@item", "Worse pay, better hours.", "",
183 "@item", "Worse pay, better fellow workers.", "",
184 "@end enumerate", ""], self
.visitor
.body
)
186 def test_single_enumerated_sub_list(self
):
188 a. lower-case letters
193 self
.assertEqual(["@enumerate a",
194 "@item", "lower-case letters", "",
196 "@item", "with a sub-list", "",
197 "@item", "with two items", "",
198 "@end enumerate", "",
199 "@end enumerate", ""], self
.visitor
.body
)
201 def test_sub_lists_from_rst_quickstart(self
):
205 A. upper-case letters
206 and it goes over many lines
208 with two paragraphs and all!
210 a. lower-case letters
212 3. with a sub-list starting at a different number
213 4. make sure the numbers are in the correct sequence though!
215 I. upper-case roman numerals
217 i. lower-case roman numerals
223 self
.assertEqual(["@enumerate 1",
224 "@item", "numbers", "",
225 "@end enumerate", "",
228 "@item", "upper-case letters\nand it goes over many lines", "",
229 "with two paragraphs and all!", "",
230 "@end enumerate", "",
233 "@item", "lower-case letters", "",
235 "@item", "with a sub-list starting at a different number", "",
236 "@item", "make sure the numbers are in the correct sequence though!", "",
237 "@end enumerate", "",
238 "@end enumerate", "",
241 "@item", "upper-case roman numerals", "",
242 "@end enumerate", "",
245 "@item", "lower-case roman numerals", "",
246 "@end enumerate", "",
249 "@item", "numbers again", "",
250 "@end enumerate", "",
253 "@item", "and again", "",
254 "@end enumerate", ""], strip_comments(self
.visitor
.body
))
256 def test_system_message(self
):
258 3. Lists generally don't start at 3
259 """, settings_overrides
={'report_level':1})
260 self
.assertEqual(["@enumerate 3",
261 "@item", "Lists generally don't start at 3", "",
262 "@end enumerate", "",
263 "@c System Message: INFO/1 (rst_test_utils:, line 2)",
264 "@c Enumerated list start value not ordinal-1: \"3\" (ordinal 3)",
265 "@c --end system message--"], self
.visitor
.body
)
267 def test_system_message_below_report_level(self
):
269 3. Lists generally don't start at 3
271 self
.assertEqual(["@enumerate 3",
272 "@item", "Lists generally don't start at 3", "",
274 ], self
.visitor
.body
)
276 def test_quotation(self
):
278 Never precede any action with the words "Watch this!"
279 -- the second constant Law of Frisbee
282 self
.assertEqual(["@quotation",
283 '''Never precede any action with the words "Watch this!"
284 -- the second constant Law of Frisbee''', '',
285 "@end quotation", ""], self
.visitor
.body
)
287 def test_formatted_code(self
):
289 Frisbeetarianism is the belief that, when you die, your soul goes up
290 onto the roof and gets stuck.
292 Never precede any action with the words "Watch this!"
293 -- the second constant Law of Frisbee
296 '''Frisbeetarianism is the belief that, when you die, your soul goes up
297 onto the roof and gets stuck.''', '',
299 '''Never precede any action with the words "Watch this!"
300 -- the second constant Law of Frisbee''', '',
301 "@end quotation", ""], self
.visitor
.body
)
303 def test_literal_block(self
):
307 "Just the place for a Snark!" the Bellman cried,
308 As he landed his crew with care;
309 Supporting each man on the top of the tide
310 By a finger entwined in his hair.
313 self
.assertEqual(["THE LANDING:", '',
314 """"Just the place for a Snark!" the Bellman cried,
315 As he landed his crew with care;
316 Supporting each man on the top of the tide
317 By a finger entwined in his hair."""], self
.visitor
.body
)
319 def test_definition_list(self
):
322 Definition lists associate a term with a definition.
325 The term is a one-line phrase, and the definition is one or more
326 paragraphs or body elements, indented relative to the term.
327 Blank lines are not allowed between term and definition.
329 self
.assertEqual(["what",
331 "Definition lists associate a term with a definition.",
333 "@end quotation", "",
336 "The term is a one-line phrase, and the definition is one or more\n"
337 "paragraphs or body elements, indented relative to the term.\n"
338 "Blank lines are not allowed between term and definition.",
340 "@end quotation", ""], self
.visitor
.body
)