# -*- coding: utf-8 -*-
"""kid.serialization tests."""
__revision__ = "$Rev: 492 $"
__date__ = "$Date: 2007-07-06 21:38:45 -0400 (Fri, 06 Jul 2007) $"
__author__ = "Ryan Tomayko (rtomayko@gmail.com)"
__copyright__ = "Copyright 2004-2005, Ryan Tomayko"
__license__ = "MIT Test Test Test Test test test test test test test test test
')
for output in 'html', 'html-strict':
rslt = t.serialize(output=output)
expected = serialize_doctype(doctypes[output]) + \
'\n
'
assert rslt == expected
def test_HTML_output_method():
t = kid.Template('
')
for output in 'HTML', 'HTML-strict':
rslt = t.serialize(output=output)
expected = serialize_doctype(doctypes[output.lower()]) + \
'\n
'
assert rslt == expected
def test_xhtml_output_method():
t = kid.Template(''
'
')
for output in 'xhtml', 'xhtml-strict':
rslt = t.serialize(output=output)
expected = serialize_doctype(doctypes[output]) \
+ '\n' \
+ '
'
assert rslt == expected
def test_html_strict_output_method():
t = kid.Template('
')
rslt = t.serialize(output='HTML-strict')
expected = serialize_doctype(doctypes['html-strict']) + \
'\n
'
assert rslt == expected
def test_html_quirks_output_method():
t = kid.Template('
')
rslt = t.serialize(output='HTML-quirks')
expected = serialize_doctype(doctypes['html-quirks']) + \
'\n
'
assert rslt == expected
def test_xml_output_method():
t = kid.Template('
')
rslt = t.serialize(output='xml')
expected = '\n' + \
'
'
assert rslt == expected
from kid.serialization import HTMLSerializer, XMLSerializer, XHTMLSerializer
serializer = HTMLSerializer()
serializer.doctype = None
serializer.inject_type = False
def HTMLTemplate(text, **kw):
t = kid.Template(text, **kw)
t.serializer = serializer
return t
def test_html_transpose():
t = kid.Template('
" t = kid.Template(source) t.serializer = serializer from kid.format import Format format=Format(no_empty_lines=True) rslt = t.serialize(format=format) rslt = rslt.replace('\n', '') expected = ('' '
' '' '') assert rslt == expected serializer = HTMLSerializer(encoding='ascii', transpose=False) serializer.doctype = None serializer.inject_type = True source = ('
' '' '' '' '
' '