1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for L{twisted.lore.slides}.
"""
from xml.dom.minidom import Element, Text
from twisted.trial.unittest import TestCase
from twisted.lore.slides import HTMLSlide, splitIntoSlides, insertPrevNextLinks
class SlidesTests(TestCase):
"""
Tests for functions in L{twisted.lore.slides}.
"""
def test_splitIntoSlides(self):
"""
L{splitIntoSlides} accepts a document and returns a list of two-tuples,
each element of which contains the title of a slide taken from an I{h2}
element and the body of that slide.
"""
parent = Element('html')
body = Element('body')
parent.appendChild(body)
first = Element('h2')
text = Text()
text.data = 'first slide'
first.appendChild(text)
body.appendChild(first)
body.appendChild(Element('div'))
body.appendChild(Element('span'))
second = Element('h2')
text = Text()
text.data = 'second slide'
second.appendChild(text)
body.appendChild(second)
body.appendChild(Element('p'))
body.appendChild(Element('br'))
slides = splitIntoSlides(parent)
self.assertEqual(slides[0][0], 'first slide')
firstContent = slides[0][1]
self.assertEqual(firstContent[0].tagName, 'div')
self.assertEqual(firstContent[1].tagName, 'span')
self.assertEqual(len(firstContent), 2)
self.assertEqual(slides[1][0], 'second slide')
secondContent = slides[1][1]
self.assertEqual(secondContent[0].tagName, 'p')
self.assertEqual(secondContent[1].tagName, 'br')
self.assertEqual(len(secondContent), 2)
self.assertEqual(len(slides), 2)
def test_insertPrevNextText(self):
"""
L{insertPrevNextLinks} appends a text node with the title of the
previous slide to each node with a I{previous} class and the title of
the next slide to each node with a I{next} class.
"""
next = Element('span')
next.setAttribute('class', 'next')
container = Element('div')
container.appendChild(next)
slideWithNext = HTMLSlide(container, 'first', 0)
previous = Element('span')
previous.setAttribute('class', 'previous')
container = Element('div')
container.appendChild(previous)
slideWithPrevious = HTMLSlide(container, 'second', 1)
insertPrevNextLinks(
[slideWithNext, slideWithPrevious], None, None)
self.assertEqual(
next.toxml(), '<span class="next">second</span>')
self.assertEqual(
previous.toxml(), '<span class="previous">first</span>')
|