def test_must_not_double_escape(self): tag = ('tag', ('tag2', {'a':'<&>"\'\n\r\t'}) ) self.assertEqual(_encode_tag(tag), '<tag>\n' ' <tag2 a="<&>"\' 	"/>\n' '</tag>')
def test_encode_tag_with_multiple_children(self): tag = ('tag', ('tag2', ), ('tag3', 'text'), ) self.assertEqual(_encode_tag(tag), '<tag>\n' ' <tag2/>\n' ' <tag3>text</tag3>\n' '</tag>')
def test_encode_tag_with_two_nested(self): tag = ('tag', ('tag2', ('tag3', ), ), ) self.assertEqual(_encode_tag(tag), '<tag>\n' ' <tag2>\n' ' <tag3/>\n' ' </tag2>\n' '</tag>')
def test_encode_tag_with_one_nested(self): tag = ('tag', ('tag2', )) self.assertEqual(_encode_tag(tag), '<tag>\n' ' <tag2/>\n' '</tag>')
def test_cdata_escaping_in_tag_body(self): self.assertEqual(_encode_tag(('tag', '<&>"\'\n\t\r')), '<tag><&>"\'\n\t\r</tag>')
def test_cdata_escaping_in_tag_attr(self): self.assertEqual(_encode_tag(('tag', {'a':'<&>"\'\n\r\t'})), '<tag a="<&>"\' 	"/>')
def test_encode_a_tag_with_str_data_and_attrs(self): self.assertEqual(_encode_tag(('tag', {'a':1}, 'text')), '<tag a="1">text</tag>')
def test_encode_a_tag_with_unicode_data(self): self.assertEqual(_encode_tag(('tag', u'текст')), u'<tag>текст</tag>'.encode('utf-8'))
def test_encode_a_tag_with_str_data(self): self.assertEqual(_encode_tag(('tag', 'text')), '<tag>text</tag>')
def test_encode_a_tag_with_attrs(self): self.assertEqual(_encode_tag(('tag', {'a':1, 'b':2})), '<tag a="1" b="2"/>')
def test_encode_a_tag(self): self.assertEqual(_encode_tag(('tag',)), '<tag/>')