Mercurial > genshi > mirror
view markup/tests/core.py @ 143:3d4c214c979a trunk
CDATA sections in XML input now appear as CDATA sections in the output. This should address the problem with escaping the contents of `<style>` and `<script>` elements, which would only get interpreted correctly if the output was served as `application/xhtml+xml`. Closes #24.
author | cmlenz |
---|---|
date | Fri, 11 Aug 2006 14:08:13 +0000 |
parents | c77c113846d6 |
children | a4a0ca41b6ad |
line wrap: on
line source
# -*- coding: utf-8 -*- # # Copyright (C) 2006 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://markup.edgewall.org/wiki/License. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://markup.edgewall.org/log/. import doctest import unittest from markup.core import * from markup.input import ParseError class MarkupTestCase(unittest.TestCase): def test_repr(self): markup = Markup('foo') self.assertEquals('<Markup "foo">', repr(markup)) def test_escape(self): markup = escape('<b>"&"</b>') assert isinstance(markup, Markup) self.assertEquals('<b>"&"</b>', markup) def test_escape_noquotes(self): markup = escape('<b>"&"</b>', quotes=False) assert isinstance(markup, Markup) self.assertEquals('<b>"&"</b>', markup) def test_unescape_markup(self): string = '<b>"&"</b>' markup = Markup.escape(string) assert isinstance(markup, Markup) self.assertEquals(string, unescape(markup)) def test_add_str(self): markup = Markup('<b>foo</b>') + '<br/>' assert isinstance(markup, Markup) self.assertEquals('<b>foo</b><br/>', markup) def test_add_markup(self): markup = Markup('<b>foo</b>') + Markup('<br/>') assert isinstance(markup, Markup) self.assertEquals('<b>foo</b><br/>', markup) def test_add_reverse(self): markup = 'foo' + Markup('<b>bar</b>') assert isinstance(markup, unicode) self.assertEquals('foo<b>bar</b>', markup) def test_mod(self): markup = Markup('<b>%s</b>') % '&' assert isinstance(markup, Markup) self.assertEquals('<b>&</b>', markup) def test_mod_multi(self): markup = Markup('<b>%s</b> %s') % ('&', 'boo') assert isinstance(markup, Markup) self.assertEquals('<b>&</b> boo', markup) def test_mul(self): markup = Markup('<b>foo</b>') * 2 assert isinstance(markup, Markup) self.assertEquals('<b>foo</b><b>foo</b>', markup) def test_join(self): markup = Markup('<br />').join(['foo', '<bar />', Markup('<baz />')]) assert isinstance(markup, Markup) self.assertEquals('foo<br /><bar /><br /><baz />', markup) def test_stripentities_all(self): markup = Markup('& j').stripentities() assert isinstance(markup, Markup) self.assertEquals('& j', markup) def test_stripentities_keepxml(self): markup = Markup('& j').stripentities(keepxmlentities=True) assert isinstance(markup, Markup) self.assertEquals('& j', markup) def test_striptags_empty(self): markup = Markup('<br />').striptags() assert isinstance(markup, Markup) self.assertEquals('', markup) def test_striptags_mid(self): markup = Markup('<a href="#">fo<br />o</a>').striptags() assert isinstance(markup, Markup) self.assertEquals('foo', markup) def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(MarkupTestCase, 'test')) suite.addTest(doctest.DocTestSuite(Markup.__module__)) return suite if __name__ == '__main__': unittest.main(defaultTest='suite')