Package logilab :: Package common :: Package test :: Module unittest_html
[frames] | no frames]

Source Code for Module logilab.common.test.unittest_html

 1  # -*- coding: utf-8 -*- 
 2  """unittests for logilab.common.html 
 3   
 4  :organization: Logilab 
 5  :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. 
 6  :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr 
 7  :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses 
 8  """ 
 9   
10  __docformat__ = "restructuredtext en" 
11   
12  from logilab.common.testlib import TestCase, unittest_main 
13  from logilab.common.tree import Node 
14   
15  from logilab.common import html 
16   
17  tree = ('root', ( 
18      ('child_1_1', ( 
19      ('child_2_1', ()), ('child_2_2', ( 
20      ('child_3_1', ()), 
21      ('child_3_2', ()), 
22      ('child_3_3', ()), 
23      )))), 
24      ('child_1_2', (('child_2_3', ()),)))) 
25   
26  generated_html = """\ 
27  <table class="tree"> 
28  <tr><td class="tree_cell" rowspan="2"><div class="tree_cell">root</div></td><td class="tree_cell_1_1">&nbsp;</td><td class="tree_cell_1_2">&nbsp;</td><td class="tree_cell" rowspan="2"><div class="tree_cell">child_1_1</div></td><td class="tree_cell_1_1">&nbsp;</td><td class="tree_cell_1_2">&nbsp;</td><td class="tree_cell" rowspan="2"><div class="tree_cell">child_2_1</div></td><td class="tree_cell_0_1">&nbsp;</td><td class="tree_cell_0_2">&nbsp;</td><td rowspan="2">&nbsp;</td></tr> 
29  <tr><td class="tree_cell_1_3">&nbsp;</td><td class="tree_cell_1_4">&nbsp;</td><td class="tree_cell_1_3">&nbsp;</td><td class="tree_cell_1_4">&nbsp;</td><td class="tree_cell_0_3">&nbsp;</td><td class="tree_cell_0_4">&nbsp;</td></tr> 
30  <tr><td rowspan="2">&nbsp;</td><td class="tree_cell_2_1">&nbsp;</td><td class="tree_cell_2_2">&nbsp;</td><td rowspan="2">&nbsp;</td><td class="tree_cell_4_1">&nbsp;</td><td class="tree_cell_4_2">&nbsp;</td><td class="tree_cell" rowspan="2"><div class="selected tree_cell">child_2_2</div></td><td class="tree_cell_1_1">&nbsp;</td><td class="tree_cell_1_2">&nbsp;</td><td class="tree_cell" rowspan="2"><div class="tree_cell">child_3_1</div></td></tr> 
31  <tr><td class="tree_cell_2_3">&nbsp;</td><td class="tree_cell_2_4">&nbsp;</td><td class="tree_cell_4_3">&nbsp;</td><td class="tree_cell_4_4">&nbsp;</td><td class="tree_cell_1_3">&nbsp;</td><td class="tree_cell_1_4">&nbsp;</td></tr> 
32  <tr><td rowspan="2">&nbsp;</td><td class="tree_cell_2_1">&nbsp;</td><td class="tree_cell_2_2">&nbsp;</td><td rowspan="2">&nbsp;</td><td class="tree_cell_0_1">&nbsp;</td><td class="tree_cell_0_2">&nbsp;</td><td rowspan="2">&nbsp;</td><td class="tree_cell_3_1">&nbsp;</td><td class="tree_cell_3_2">&nbsp;</td><td class="tree_cell" rowspan="2"><div class="tree_cell">child_3_2</div></td></tr> 
33  <tr><td class="tree_cell_2_3">&nbsp;</td><td class="tree_cell_2_4">&nbsp;</td><td class="tree_cell_0_3">&nbsp;</td><td class="tree_cell_0_4">&nbsp;</td><td class="tree_cell_3_3">&nbsp;</td><td class="tree_cell_3_4">&nbsp;</td></tr> 
34  <tr><td rowspan="2">&nbsp;</td><td class="tree_cell_2_1">&nbsp;</td><td class="tree_cell_2_2">&nbsp;</td><td rowspan="2">&nbsp;</td><td class="tree_cell_0_1">&nbsp;</td><td class="tree_cell_0_2">&nbsp;</td><td rowspan="2">&nbsp;</td><td class="tree_cell_4_1">&nbsp;</td><td class="tree_cell_4_2">&nbsp;</td><td class="tree_cell" rowspan="2"><div class="tree_cell">child_3_3</div></td></tr> 
35  <tr><td class="tree_cell_2_3">&nbsp;</td><td class="tree_cell_2_4">&nbsp;</td><td class="tree_cell_0_3">&nbsp;</td><td class="tree_cell_0_4">&nbsp;</td><td class="tree_cell_4_3">&nbsp;</td><td class="tree_cell_4_4">&nbsp;</td></tr> 
36  <tr><td rowspan="2">&nbsp;</td><td class="tree_cell_4_1">&nbsp;</td><td class="tree_cell_4_2">&nbsp;</td><td class="tree_cell" rowspan="2"><div class="tree_cell">child_1_2</div></td><td class="tree_cell_5_1">&nbsp;</td><td class="tree_cell_5_2">&nbsp;</td><td class="tree_cell" rowspan="2"><div class="tree_cell">child_2_3</div></td><td class="tree_cell_0_1">&nbsp;</td><td class="tree_cell_0_2">&nbsp;</td><td rowspan="2">&nbsp;</td></tr> 
37  <tr><td class="tree_cell_4_3">&nbsp;</td><td class="tree_cell_4_4">&nbsp;</td><td class="tree_cell_5_3">&nbsp;</td><td class="tree_cell_5_4">&nbsp;</td><td class="tree_cell_0_3">&nbsp;</td><td class="tree_cell_0_4">&nbsp;</td></tr> 
38  </table>\ 
39  """ 
40   
41 -def make_tree(tupletree):
42 n = Node(tupletree[0]) 43 for child in tupletree[1]: 44 n.append(make_tree(child)) 45 return n
46
47 -class UIlibHTMLGenerationTC(TestCase):
48 """ a basic tree node, caracterised by an id"""
49 - def setUp(self):
50 """ called before each test from this class """ 51 self.o = make_tree(tree)
52
53 - def test_generated_html(self):
54 s = html.render_HTML_tree(self.o, selected_node="child_2_2") 55 self.assertTextEqual(s, generated_html)
56 57 58 if __name__ == '__main__': 59 unittest_main() 60