def test_comment_data_unb(self): comment = tree.comment(u'Begin spam') self.assertEqual(comment.xml_value, u'Begin spam') self.assertEqual(len(comment.xml_value), 10) self.assertEqual(comment.xml_value[:5], u'Begin') comment.xml_value += u' more spam' self.assertEqual(comment.xml_value, u'Begin spam more spam')
def test_create_new_doc_comment(self): EXPECTED = '<A a="b">One</A><!--This is easy-->' doc = tree.entity() A = tree.element(None, u'A') A.xml_attributes[u'a'] = u'b' A.xml_append(tree.text(u'One')) doc.xml_append(A) doc.xml_append(tree.comment(u"This is easy")) self.compare_output(doc, XMLDECL+EXPECTED) return
def test_create_new_doc_comment(self): EXPECTED = '<A a="b">One</A><!--This is easy-->' doc = tree.entity() A = tree.element(None, u'A') A.xml_attributes[u'a'] = u'b' A.xml_append(tree.text(u'One')) doc.xml_append(A) doc.xml_append(tree.comment(u"This is easy")) self.compare_output(doc, XMLDECL + EXPECTED) return
def test_create_new_doc_attr_dict(self): EXPECTED = '<?xml-stylesheet href="classic.xsl" type="text/xml"?><A a="b">One</A><!--This is easy-->' doc = tree.entity() doc.xml_append(tree.processing_instruction(u'xml-stylesheet', u'href="classic.xsl" type="text/xml"')) A = tree.element(None, u'A') A.xml_attributes[u'a'] = u'b' A.xml_append(tree.text(u'One')) doc.xml_append(A) doc.xml_append(tree.comment(u"This is easy")) self.compare_output(doc, XMLDECL+EXPECTED) return
def test_create_new_doc_attr_dict(self): EXPECTED = '<?xml-stylesheet href="classic.xsl" type="text/xml"?><A a="b">One</A><!--This is easy-->' doc = tree.entity() doc.xml_append( tree.processing_instruction(u'xml-stylesheet', u'href="classic.xsl" type="text/xml"')) A = tree.element(None, u'A') A.xml_attributes[u'a'] = u'b' A.xml_append(tree.text(u'One')) doc.xml_append(A) doc.xml_append(tree.comment(u"This is easy")) self.compare_output(doc, XMLDECL + EXPECTED) return
def test_reading_building(self): doc = tree.entity() doc.xml_append(tree.processing_instruction(u'xml-stylesheet', u'href="classic.xsl" type="text/xml"')) A = tree.element(None, u'A') A.xml_attributes[u'a'] = u'b' A.xml_append(tree.text(u'One')) doc.xml_append(A) doc.xml_append(tree.comment(u"This is easy")) doc2 = amara.parse('docs/whatsnew_doc1.xml') output1 = cStringIO.StringIO() output2 = cStringIO.StringIO() xml_print(doc, stream=output1) xml_print(doc2, stream=output2) self.assertEqual(output1.getvalue(), output2.getvalue()) return
def test_reading_building(self): doc = tree.entity() doc.xml_append( tree.processing_instruction(u'xml-stylesheet', u'href="classic.xsl" type="text/xml"')) A = tree.element(None, u'A') A.xml_attributes[u'a'] = u'b' A.xml_append(tree.text(u'One')) doc.xml_append(A) doc.xml_append(tree.comment(u"This is easy")) doc2 = amara.parse('docs/whatsnew_doc1.xml') output1 = cStringIO.StringIO() output2 = cStringIO.StringIO() xml_print(doc, stream=output1) xml_print(doc2, stream=output2) self.assertEqual(output1.getvalue(), output2.getvalue()) return
def _emitComment(self, text): text = text.replace(u"--", u"- -") # There cannot be "--" in XML comment self.cur.xml_append(tree.comment(text))