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
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
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
33 layout = VerbatimText('blablabla')
34 self._test_output('verbatim_base', layout)
35
36
38 layout = List(children=('item1', 'item2', 'item3', 'item4'))
39 self._test_output('list_base', layout)
40
42 layout = List(children=(Paragraph(("blabla", List(children=('1', "2", "3")))),
43 "an other point"))
44 self._test_output('nested_list', layout)
45
46
48 layout = Table(cols=2, children=('head1', 'head2', 'cell1', 'cell2'))
49 self._test_output('table_base', layout)
50
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
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
69
70
71