#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2007 Søren Roug, European Environment Agency
#
# This is free software. You may redistribute it under the terms
# of the Apache license and the GNU General Public License Version
# 2 or at your option any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Contributor(s):
#
import unittest, os
import io
import zipfile
from odf import teletype
from odf.opendocument import OpenDocumentText, load
from odf import style, text
from odf.text import P
class TestWhite(unittest.TestCase):
def test_create(self):
""" Test that tabs and newlines are converted to elements """
para = P()
teletype.addTextToElement(para,
u"The boy stood on the burning deck,\n" +
u"\tHis feet\twere\t\tfull of blisters.\n" +
u"The captain stood in\tthe public house\n" +
u" With beer running down his whiskers. " );
outfp = io.StringIO()
para.toXml(1,outfp)
self.assertEqual(u'''The boy stood on the burning deck,''' +
u'''His feetwerefull of blisters.''' +
u'''The captain stood inthe public house''' +
u''' With beer running down his whiskers. ''', outfp.getvalue())
def test_extract(self):
""" Convert a paragraph to plain text """
poem_odt = os.path.join(
os.path.dirname(__file__), u"examples", u"serious_poem.odt")
d = load(poem_odt)
allparas = d.getElementsByType(P)
content = u"""The boy stood on the burning deck,Whence allbuthim had fled.The flames that litthe battle'swreck, Shone o'er him, round the dead. """
self.assertEqual(u"The boy stood on the burning deck,\n\tWhence all\tbut\t\thim had fled.\nThe flames that lit\tthe battle's\twreck,\n Shone o'er him, round the dead. ", teletype.extractText(allparas[0]))
def test_extract_with_span(self):
""" Extract a text with a bold/italic span """
poem_odt = os.path.join(
os.path.dirname(__file__), u"examples", u"simplestyles.odt")
d = load(poem_odt)
teletype.extractText(d.body)
self.assertEqual(u'Plain textBoldItalicBold italicUnderlineUnderline italicUnderline bold italicKm2 - superscriptH2O - subscript', teletype.extractText(d.body))
if __name__ == '__main__':
unittest.main()