Esempio n. 1
0
 def test_text(self):
     text = "Le Père Noël a une moustache rouge."
     paragraph = Paragraph(text)
     paragraph.set_span("highlight", regex="rouge")
     expected = ("<text:p>Le Père Noël a une moustache "
                 "<text:span "
                 'text:style-name="highlight">rouge</text:span>.'
                 "</text:p>")
     self.assertEqual(paragraph.serialize(), expected)
Esempio n. 2
0
 def test_offset(self):
     text = "Le Père Noël a une moustache rouge."
     paragraph = Paragraph(text)
     paragraph.set_span("highlight", offset=text.index("moustache"))
     expected = ("<text:p>Le Père Noël a une "
                 '<text:span text:style-name="highlight">moustache '
                 "rouge.</text:span>"
                 "</text:p>")
     self.assertEqual(paragraph.serialize(), expected)
Esempio n. 3
0
 def test_offset_length(self):
     text = "Le Père Noël a une moustache rouge."
     paragraph = Paragraph(text)
     paragraph.set_span("highlight",
                        offset=text.index("moustache"),
                        length=len("moustache"))
     expected = ('<text:p>Le Père Noël a une '
                 '<text:span text:style-name="highlight">moustache'
                 '</text:span> rouge.'
                 '</text:p>')
     self.assertEqual(paragraph.serialize(), expected)
Esempio n. 4
0
 def test_text_several(self):
     text = "Le Père rouge a une moustache rouge."
     paragraph = Paragraph(text)
     paragraph.set_span("highlight", regex="rouge")
     expected = ('<text:p>Le Père '
                 '<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)
Esempio n. 5
0
 def test_set_bookmark_with_after_without_position(self):
     paragraph = Paragraph("aa bb aa aa cc aa dd")
     paragraph.set_span(style="style", regex="bb aa aa")
     paragraph.set_span(style="style", regex="dd")
     paragraph.set_bookmark("bookmark", after="aa")
     expected = (
         '<text:p>aa<text:bookmark text:name="bookmark"/> '
         '<text:span text:style-name="style">bb aa aa'
         "</text:span>"
         ' cc aa <text:span text:style-name="style">dd</text:span>'
         "</text:p>"
     )
     self.assertEqual(paragraph.serialize(), expected)
Esempio n. 6
0
 def test_set_bookmark_with_position(self):
     paragraph = Paragraph("aa bb aa aa cc aa dd")
     paragraph.set_span(style="style", regex="bb aa aa")
     paragraph.set_span(style="style", regex="dd")
     paragraph.set_bookmark("bookmark1", position=0)
     paragraph.set_bookmark("bookmark2", position=2)
     paragraph.set_bookmark("bookmark3", position=len("aa bb aa aa cc aa dd"))
     expected = (
         '<text:p><text:bookmark text:name="bookmark1"/>aa'
         '<text:bookmark text:name="bookmark2"/> '
         '<text:span text:style-name="style">bb aa aa</text:span>'
         ' cc aa <text:span text:style-name="style">dd'
         '<text:bookmark text:name="bookmark3"/></text:span>'
         "</text:p>"
     )
     self.assertEqual(paragraph.serialize(), expected)
Esempio n. 7
0
 def test_set_bookmark_with_end(self):
     paragraph = Paragraph("aa bb aa aa cc aa dd")
     paragraph.set_span(style="style", regex="bb aa aa")
     paragraph.set_span(style="style", regex="dd")
     paragraph.set_bookmark("bookmark1", after="cc", position=-1)
     paragraph.set_bookmark("bookmark2", position=-1)
     expected = (
         "<text:p>aa "
         '<text:span text:style-name="style">'
         "bb aa aa"
         "</text:span>"
         ' cc<text:bookmark text:name="bookmark1"/> aa '
         '<text:span text:style-name="style">dd</text:span>'
         '<text:bookmark text:name="bookmark2"/>'
         "</text:p>"
     )
     self.assertEqual(paragraph.serialize(), expected)