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

Source Code for Module logilab.common.test.utils

 1  '''unit tests utilities for ureports 
 2  ''' 
 3   
 4  __revision__ = "$Id: utils.py,v 1.3 2005-05-27 12:27:08 syt Exp $" 
 5   
 6  from cStringIO import StringIO 
 7  from logilab.common.ureports.nodes import * 
 8   
9 -class WriterTC:
10 - def _test_output(self, test_id, layout, msg=None):
11 buffer = StringIO() 12 self.writer.format(layout, buffer) 13 got = buffer.getvalue() 14 expected = getattr(self, test_id) 15 try: 16 self.assertLinesEquals(got, expected) 17 except: 18 print '**** got for %s' % test_id 19 print got 20 print '**** while expected' 21 print expected 22 print '****' 23 raise
24
25 - def test_section(self):
26 layout = Section('Section title', 27 'Section\'s description.\nBlabla bla') 28 self._test_output('section_base', layout) 29 layout.append(Section('Subsection', 'Sub section description')) 30 self._test_output('section_nested', layout)
31
32 - def test_verbatim(self):
33 layout = VerbatimText('blablabla') 34 self._test_output('verbatim_base', layout)
35 36
37 - def test_list(self):
38 layout = List(children=('item1', 'item2', 'item3', 'item4')) 39 self._test_output('list_base', layout)
40
41 - def test_nested_list(self):
42 layout = List(children=(Paragraph(("blabla", List(children=('1', "2", "3")))), 43 "an other point")) 44 self._test_output('nested_list', layout)
45 46
47 - def test_table(self):
48 layout = Table(cols=2, children=('head1', 'head2', 'cell1', 'cell2')) 49 self._test_output('table_base', layout)
50
51 - def test_field_table(self):
52 table = Table(cols=2, klass='field', id='mytable') 53 for field, value in (('f1', 'v1'), ('f22', 'v22'), ('f333', 'v333')): 54 table.append(Text(field)) 55 table.append(Text(value)) 56 self._test_output('field_table', table)
57
58 - def test_advanced_table(self):
59 table = Table(cols=2, klass='whatever', id='mytable', rheaders=1) 60 for field, value in (('field', 'value') ,('f1', 'v1'), ('f22', 'v22'), ('f333', 'v333')): 61 table.append(Text(field)) 62 table.append(Text(value)) 63 table.append(Link('http://www.perdu.com', 'toi perdu ?')) 64 table.append(Text('')) 65 self._test_output('advanced_table', table)
66 67 68 ## def test_image(self): 69 ## layout = Verbatim('blablabla') 70 ## self._test_output('verbatim_base', layout) 71