cmlenz@1: # -*- coding: utf-8 -*- cmlenz@1: # cmlenz@66: # Copyright (C) 2006 Edgewall Software cmlenz@1: # All rights reserved. cmlenz@1: # cmlenz@1: # This software is licensed as described in the file COPYING, which cmlenz@1: # you should have received as part of this distribution. The terms cmlenz@66: # are also available at http://markup.edgewall.org/wiki/License. cmlenz@1: # cmlenz@1: # This software consists of voluntary contributions made by many cmlenz@1: # individuals. For the exact contribution history, see the revision cmlenz@66: # history and logs, available at http://markup.edgewall.org/log/. cmlenz@1: cmlenz@1: import doctest cmlenz@1: from HTMLParser import HTMLParseError cmlenz@1: import unittest cmlenz@1: cmlenz@1: from markup.builder import Element, tag cmlenz@1: from markup.core import Stream cmlenz@1: cmlenz@1: cmlenz@1: class ElementFactoryTestCase(unittest.TestCase): cmlenz@1: cmlenz@1: def test_link(self): cmlenz@20: link = tag.a(href='#', title='Foo', accesskey=None)('Bar') cmlenz@1: bits = iter(link.generate()) cmlenz@1: self.assertEqual((Stream.START, ('a', [('href', "#"), ('title', "Foo")]), cmlenz@94: (None, -1, -1)), bits.next()) cmlenz@94: self.assertEqual((Stream.TEXT, u'Bar', (None, -1, -1)), bits.next()) cmlenz@94: self.assertEqual((Stream.END, 'a', (None, -1, -1)), bits.next()) cmlenz@1: cmlenz@98: def test_nonstring_attributes(self): cmlenz@98: """ cmlenz@98: Verify that if an attribute value is given as an int (or some other cmlenz@98: non-string type), it is coverted to a string when the stream is cmlenz@98: generated. cmlenz@98: """ cmlenz@98: event = iter(tag.foo(id=3)).next() cmlenz@98: self.assertEqual((Stream.START, ('foo', [('id', '3')]), (None, -1, -1)), cmlenz@98: event) cmlenz@98: cmlenz@1: cmlenz@1: def suite(): cmlenz@1: suite = unittest.TestSuite() cmlenz@1: suite.addTest(doctest.DocTestSuite(Element.__module__)) cmlenz@1: suite.addTest(unittest.makeSuite(ElementFactoryTestCase, 'test')) cmlenz@1: return suite cmlenz@1: cmlenz@1: if __name__ == '__main__': cmlenz@1: unittest.main(defaultTest='suite')