예제 #1
0
 def test_insert_element_last_child(self):
     element = Element.from_tag(
         '<office:text><text:p/><text:p/></office:text>')
     child = Element.from_tag('<text:h/>')
     element.append(child)
     self.assertEqual(
         element.serialize(),
         '<office:text><text:p/><text:p/><text:h/></office:text>')
예제 #2
0
 def test_insert_element_first_child(self):
     element = Element.from_tag(
         '<office:text><text:p/><text:p/></office:text>')
     child = Element.from_tag('<text:h/>')
     element.insert(child, FIRST_CHILD)
     self.assertEqual(
         element.serialize(),
         '<office:text><text:h/><text:p/><text:p/></office:text>')
예제 #3
0
 def test_insert_element_prev_sibling(self):
     root = Element.from_tag(
         '<office:text><text:p/><text:p/></office:text>')
     element = root.get_elements('//text:p')[0]
     sibling = Element.from_tag('<text:h/>')
     element.insert(sibling, PREV_SIBLING)
     self.assertEqual(
         root.serialize(),
         '<office:text><text:h/><text:p/><text:p/></office:text>')
예제 #4
0
 def test_append_element(self):
     element = Element.from_tag("text:p")
     element.append("f")
     element.append("oo1")
     element.append(Element.from_tag("text:line-break"))
     element.append("f")
     element.append("oo2")
     self.assertEqual(element.serialize(),
                      "<text:p>foo1<text:line-break/>foo2</text:p>")
예제 #5
0
파일: test_element.py 프로젝트: jdum/odfdo
 def test_insert_element_next_sibling(self):
     root = Element.from_tag(
         "<office:text><text:p/><text:p/></office:text>")
     element = root.get_elements("//text:p")[0]
     sibling = Element.from_tag("<text:h/>")
     element.insert(sibling, NEXT_SIBLING)
     self.assertEqual(
         root.serialize(),
         "<office:text><text:p/><text:h/><text:p/></office:text>")
예제 #6
0
 def test_delete_self_5(self):
     element = Element.from_tag(
         '<text:p><tag>x</tag><text:span/>keep</text:p>')
     child = element.get_element('//text:span')
     child.delete()
     self.assertEqual(element.serialize(),
                      '<text:p><tag>x</tag>keep</text:p>')
예제 #7
0
 def test_insert_link_simple(self):
     paragraph = Element.from_tag('<text:p>toto tata titi</text:p>')
     paragraph.insert_link("http://", from_="tata", to="tata")
     expected = ('<text:p>toto '
                 '<text:a xlink:href="http://">tata</text:a> '
                 'titi</text:p>')
     self.assertEqual(paragraph.serialize(), expected)
예제 #8
0
파일: test_element.py 프로젝트: jdum/odfdo
 def test_delete_self_4(self):
     element = Element.from_tag(
         "<text:p><tag>x</tag>before<text:span/>keep</text:p>")
     child = element.get_element("//text:span")
     child.delete()
     self.assertEqual(element.serialize(),
                      "<text:p><tag>x</tag>beforekeep</text:p>")
예제 #9
0
 def test_tail(self):
     data = ("<text:p>Le Père Noël a une "
             "<text:span>moustache</text:span> rouge.</text:p>")
     paragraph = Element.from_tag(data)
     paragraph.set_span("highlight", regex="rouge")
     expected = ("<text:p>Le Père Noël a une "
                 "<text:span>moustache</text:span> "
                 "<text:span "
                 'text:style-name="highlight">rouge</text:span>.'
                 "</text:p>")
     self.assertEqual(paragraph.serialize(), expected)
예제 #10
0
파일: test_link.py 프로젝트: jdum/odfdo
 def test_insert_link_medium(self):
     paragraph = Element.from_tag(
         "<text:p><text:span>toto</text:span> " "tata titi</text:p>"
     )
     paragraph.insert_link("http://", from_="tata", to="tata")
     expected = (
         "<text:p><text:span>toto</text:span> "
         '<text:a xlink:href="http://">tata</text:a> '
         "titi</text:p>"
     )
     self.assertEqual(paragraph.serialize(), expected)
예제 #11
0
 def test_insert_link_horrible(self):
     paragraph = Element.from_tag('<text:p>toto '
                                  '<text:span>tata titi</text:span>'
                                  ' tutu </text:p>')
     paragraph.insert_link("http://", from_="titi", to="tutu")
     expected = ('<text:p>toto <text:span>tata </text:span>'
                 '<text:a xlink:href="http://">'
                 '<text:span>titi</text:span> tutu'
                 '</text:a> '
                 '</text:p>')
     self.assertEqual(paragraph.serialize(), expected)
예제 #12
0
 def test_tail_several(self):
     data = ("<text:p>Le <text:span>Père</text:span> rouge a une "
             "moustache rouge.</text:p>")
     paragraph = Element.from_tag(data)
     paragraph.set_span("highlight", regex="rouge")
     expected = ('<text:p>Le <text:span>Père</text:span> '
                 '<text:span '
                 'text:style-name="highlight">rouge</text:span> '
                 'a une moustache '
                 '<text:span '
                 'text:style-name="highlight">rouge</text:span>.'
                 '</text:p>')
     self.assertEqual(paragraph.serialize(), expected)
예제 #13
0
 def test_insert_note_after_span(self):
     note = Note(note_id='note1', citation="1", body="élément pertubateur")
     data = "<text:p>Un <text:span>para</text:span>graphe.</text:p>"
     paragraph = Element.from_tag(data)
     paragraph.insert_note(note, after="graphe")
     expected = ('<text:p>Un <text:span>para</text:span>graphe'
                 '<text:note text:note-class="footnote" '
                 'text:id="note1">'
                 '<text:note-citation>1</text:note-citation>'
                 '<text:note-body>'
                 '<text:p>élément pertubateur</text:p>'
                 '</text:note-body>'
                 '</text:note>'
                 '.</text:p>')
     self.assertEqual(paragraph.serialize(), expected)
예제 #14
0
파일: test_link.py 프로젝트: jdum/odfdo
 def test_insert_link_hideous(self):
     paragraph = Element.from_tag(
         "<text:p>toto "
         "<text:span>tata titi</text:span>"
         " <text:span>tutu tyty</text:span>"
         "</text:p>"
     )
     paragraph.insert_link("http://", from_="titi", to="tutu")
     expected = (
         "<text:p>toto <text:span>tata </text:span>"
         '<text:a xlink:href="http://">'
         "<text:span>titi</text:span> "
         "<text:span>tutu</text:span>"
         "</text:a>"
         "<text:span> tyty</text:span>"
         "</text:p>"
     )
     self.assertEqual(paragraph.serialize(), expected)
예제 #15
0
파일: test_element.py 프로젝트: jdum/odfdo
 def test_qname(self):
     element = Element.from_tag("text:p")
     self.assertEqual(element.serialize(), "<text:p/>")
예제 #16
0
 def test_delete_child(self):
     element = Element.from_tag('<text:p><text:span/></text:p>')
     child = element.get_element('//text:span')
     element.delete(child)
     self.assertEqual(element.serialize(), '<text:p/>')
예제 #17
0
 def test_get_root(self):
     element = Element.from_tag('<text:p><text:span/></text:p>')
     root = element.root
     self.assertTrue(root.parent is None)
예제 #18
0
파일: test_xmlpart.py 프로젝트: jdum/odfdo
 def test_pretty_serialize(self):
     # With pretty = True
     element = Element.from_tag("<root><a>spam</a><b/></root>")
     serialized = element.serialize(pretty=True)
     expected = "<root>\n" "  <a>spam</a>\n" "  <b/>\n" "</root>\n"
     self.assertEqual(serialized, expected)
예제 #19
0
 def test_qname(self):
     element = Element.from_tag('text:p')
     self.assertEqual(element.serialize(), '<text:p/>')
예제 #20
0
파일: test_element.py 프로젝트: jdum/odfdo
 def test_get_parent(self):
     element = Element.from_tag("<text:p><text:span/></text:p>")
     child = element.get_element("//text:span")
     parent = child.parent
     self.assertEqual(parent.tag, "text:p")
예제 #21
0
 def test_simple(self):
     data = '<p>Template Element</p>'
     element = Element.from_tag(data)
     self.assertEqual(element.serialize(), data)
예제 #22
0
파일: test_element.py 프로젝트: jdum/odfdo
 def test_delete_child(self):
     element = Element.from_tag("<text:p><text:span/></text:p>")
     child = element.get_element("//text:span")
     element.delete(child)
     self.assertEqual(element.serialize(), "<text:p/>")
예제 #23
0
 def test_insert_element_bad_position(self):
     element = Element.from_tag('text:p')
     child = Element.from_tag('text:span')
     self.assertRaises(ValueError, element.insert, child, 999)
예제 #24
0
 def test_insert_element_bad_element(self):
     element = Element.from_tag('text:p')
     self.assertRaises(AttributeError, element.insert, '<text:span/>',
                       FIRST_CHILD)
예제 #25
0
파일: test_text.py 프로젝트: jdum/odfdo
 def setUp(self):
     element = Element.from_tag("<text:p>text<text:span/>tail</text:p>")
     self.results = element.xpath("descendant::text()")
예제 #26
0
 def test_register(self):
     register_element_class(self.dummy_element)
     element = Element.from_tag('office:dummy1')
     self.assertTrue(type(element) is self.dummy_element)
예제 #27
0
 def test_unregistered(self):
     element = Element.from_tag('office:dummy2')
     self.assertTrue(type(element) is Element)
     self.assertFalse(isinstance(element, self.dummy_element))
예제 #28
0
 def test_get_parent(self):
     element = Element.from_tag('<text:p><text:span/></text:p>')
     child = element.get_element('//text:span')
     parent = child.parent
     self.assertEqual(parent.tag, 'text:p')
예제 #29
0
 def test_namespace(self):
     data = '<text:p>Template Element</text:p>'
     element = Element.from_tag(data)
     self.assertEqual(element.serialize(), data)
예제 #30
0
 def test_delete_root(self):
     element = Element.from_tag('<text:p><text:span/></text:p>')
     root = element.root
     self.assertRaises(ValueError, root.delete)