style
[librarian.git] / tests / test_pyhtml.py
1 # -*- coding: utf-8 -*-
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
9 def test_traversal():
10     xml = etree.fromstring("<a><b>BBBB</b><c>CCCC</c></a>")
11     hg = xmlutils.Xmill()
12     assert_equals(hg.next(xml), xml[0])
13     assert_equals(hg.next(xml[0]), xml[1])
14     assert_equals(hg.next(xml[1]), None)
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 def test_xml_generation():
34     xml = u"""<root>
35         <songs>
36         <song>
37         <title>Oursoul</title>
38         <artist>Hindi Zahra</artist>
39         </song>
40         <song>
41         <title>Visitor</title>
42         <artist>Portico Quartet</artist>
43         </song>
44         </songs>
45         </root>
46     """
47     txt = Foo().generate(etree.fromstring(xml))
48     print txt
49
50
51 def test_edumodule():
52     xml = open(get_fixture('edumed', 'gim-wizerunek-w-sieci.xml')).read()
53     em = EduModule()
54     out = em.generate(etree.fromstring(xml))
55     print out.encode('utf-8')