minor name fix
[librarian.git] / tests / test_pyhtml.py
1
2 from librarian import xmlutils
3 from lxml import etree
4 from librarian.pyhtml import EduModule
5 from nose.tools import *
6 from tests.utils import get_fixture
7
8 def test_traversal():
9     xml = etree.fromstring("<a><b>BBBB</b><c>CCCC</c></a>")
10     hg = xmlutils.Xmill()
11     assert_equals(hg.next(xml), xml[0])
12     assert_equals(hg.next(xml[0]), xml[1])
13     assert_equals(hg.next(xml[1]), None)
14
15
16
17 class Foo(xmlutils.Xmill):
18     def __init__(self):
19         super(Foo, self).__init__()
20         self.mode = 0
21
22     def handle_title(self, ele):
23         return "Title: ``%s''" % ele.text
24
25     def handle_artist(self, ele):
26         return "Artist: %s" % ele.text
27
28     def handle_song(self, ele):
29         if ele.getnext() is not None:
30             return "\n","--------------------\n"
31
32
33
34 def test_xml_generation():
35     xml = u"""<root>
36 <songs>
37 <song>
38 <title>Oursoul</title>
39 <artist>Hindi Zahra</artist>
40 </song>
41 <song>
42 <title>Visitor</title>
43 <artist>Portico Quartet</artist>
44 </song>
45 </songs>
46 </root>
47 """
48     txt = Foo().generate(etree.fromstring(xml))
49     print txt
50
51
52 def test_edumodule():
53     xml = open(get_fixture('edumed', 'gim-wizerunek-w-sieci.xml')).read()
54     em = EduModule()
55     out = em.generate(etree.fromstring(xml))
56     print out.encode('utf-8')