Back to index

moin  1.9.0~rc2
test_html.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - MoinMoin.widget.html Tests
00004 
00005     @copyright: 2003-2004 by Juergen Hermann <jh@web.de>
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 import py
00010 
00011 from MoinMoin.widget import html
00012 
00013 class TestHTMLWidgets:
00014     """widget.html: testing html widgets"""
00015 
00016     def testCreate(self):
00017         """widget.html: creating html widgets
00018 
00019         TO DO: add tests for all elements by HTML 4 spec.
00020         """
00021         tests = (
00022             # description, call, expected
00023             ('Create text', html.Text('<br> &'), '&lt;br&gt; &amp;'),
00024             ('Create raw html', html.Raw('<br> &amp;'), '<br> &amp;'),
00025             ('Create br', html.BR(), '<br>'),
00026             ('Create hr', html.HR(), '<hr>'),
00027             ('Create p', html.P(), '<p></p>'),
00028             )
00029 
00030         for description, obj, expected in tests:
00031             result = unicode(obj)
00032             assert result == expected
00033 
00034     def testInvalidAttributes(self):
00035         """widget.html: invalid attributes raises exception
00036 
00037         TO DO: add tests for all elements by HTML 4 spec.
00038         """
00039         py.test.raises(AttributeError, html.BR, name='foo')
00040 
00041 
00042     def testCompositeElements(self):
00043         """widget.html: append to and extend composite element"""
00044         html._SORT_ATTRS = 1
00045         element = html.P()
00046 
00047         actions = (
00048             # action, data, expected
00049             (element.append,
00050              html.Text('Text & '),
00051              '<p>Text &amp; </p>'),
00052             (element.append,
00053              html.Text('more text. '),
00054              '<p>Text &amp; more text. </p>'),
00055             (element.extend,
00056              (html.Text('And then '), html.Text('some.')),
00057              '<p>Text &amp; more text. And then some.</p>'),
00058             )
00059 
00060         for action, data, expected in actions:
00061             action(data)
00062             result = unicode(element)
00063             assert result == expected
00064 
00065 coverage_modules = ['MoinMoin.widget.html']
00066