"""Unit Tests for the XML comments.""" __revision__ = "$Rev: 455 $" __author__ = "David Stanek " __copyright__ = "Copyright 2005, David Stanek" import kid from kid.serialization import serialize_doctype, doctypes def test_comments_inside(): """Comments inside the root element.""" t = kid.Template('') assert (t.serialize(output='HTML') == serialize_doctype(doctypes['html']) + '\n') def test_comments_outside(): """Comments outside the root element (ticket #134).""" t = kid.Template('') assert (t.serialize(output='HTML') == serialize_doctype(doctypes['html']) + '\n') def test_comments_and_python(): """Comments and PI outside the root element evaluated inside.""" t = kid.Template('' '$x') assert (t.serialize(output='HTML') == serialize_doctype(doctypes['html']) + '\n42') def test_nested_comments(): """Nested comments.""" t = kid.Template('
' '

') assert (t.serialize(output='HTML') == serialize_doctype(doctypes['html']) + '\n
' '

') def test_comment_removal(): """Comments that start with '!' should not be output.""" t = kid.Template('') assert t.serialize(output='HTML') == \ serialize_doctype(doctypes['html']) + '\n' assert t.serialize(output='xhtml') == \ serialize_doctype(doctypes['xhtml']) + '\n' assert t.serialize(output='xml') == \ '\n' t = kid.Template('') assert t.serialize(output='HTML') == \ serialize_doctype(doctypes['html']) + '\n' assert t.serialize(output='xhtml') == \ serialize_doctype(doctypes['xhtml']) + '\n' assert t.serialize(output='xml') == \ '\n' def test_comment_interpolation(): """Comments starting with '[' or '' % (b, c, d) if c.startswith('!'): after_comment = '' elif c == '[' or c == '' % (b, c, d) else: after_comment = before_comment before = '%s' % before_comment t = kid.Template(before, before='after') for output in ('HTML', 'xhtml', 'xml'): if output == 'HTML': after = '%s' % after_comment elif output == 'xhtml' or after_comment: after = '%s' % after_comment else: after = '' if output == 'xml': after = '\n' + after else: doctype = serialize_doctype(doctypes[output.lower()]) after = doctype + '\n' + after assert t.serialize(output=output) == after def test_comment_for_loop(): """Commenting out section with py:for and substitution (ticket #149).""" xml = """ """ t = kid.Template(xml, mylist = ['peaches', 'cream']) assert """ """ in t.serialize(output='html') def test_comment_style_sheet(): """Allow variable substitution in style sheet (ticket #124).""" xml = """ """ t = kid.Template(xml, section="support") assert "#menu a#support" in t.serialize(output='html')