"""Unit Tests for expression substition in attributes.""" __revision__ = "$Rev: 428 $" __author__ = "Christoph Zwerschke " __copyright__ = "Copyright 2006, Christoph Zwerschke" import kid def test_simple_interpolation(): """Simple variable substitution.""" s = kid.Template('
', a='hello', b=123, c=0.5).serialize() assert s.endswith('
') def test_expression_interpolation(): """Expression substitution.""" s = kid.Template('
', a=1, b=2, c=3).serialize() assert s.endswith('
') def test_remove_null_attributes(): """Expressions evaluating to None should remove the attribute.""" source = '
' s = kid.Template(source, a=0, b=False, c=None).serialize() assert s.endswith('
') source = '
' s = kid.Template(source, a=0, b=False, c=None).serialize() assert s.endswith('
') def test_interpolated_xml(): """Harmless XML expressions should be allowed here (ticket #27).""" sources = ('', """""") from kid.template_util import TemplateAttrsError for source in sources: xml = kid.XML("") try: kid.Template(source, xml=xml).serialize() except TemplateAttrsError, e: e = str(e) else: e = 'tag accepted in attribute' assert e == 'Illegal value for attribute "content"' text = "Résultat de la requête" xml = kid.XML(text) s = kid.Template(source, xml=xml).serialize(encoding='ascii') assert s.endswith('' % text)