testtext.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2007 Søren Roug, European Environment Agency
  4. #
  5. # This is free software. You may redistribute it under the terms
  6. # of the Apache license and the GNU General Public License Version
  7. # 2 or at your option any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public
  15. # License along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. #
  18. # Contributor(s):
  19. #
  20. import unittest
  21. import os, sys
  22. from odf.opendocument import OpenDocumentText, load
  23. from odf import text
  24. from odf.namespaces import TEXTNS
  25. if sys.version_info[0]==3:
  26. unicode=str
  27. class TestText(unittest.TestCase):
  28. def test_softpagebreak(self):
  29. """ Create a soft page break """
  30. textdoc = OpenDocumentText()
  31. spb = text.SoftPageBreak()
  32. textdoc.text.addElement(spb)
  33. self.assertEqual(1, 1)
  34. def test_1stpara(self):
  35. """ Grab 1st paragraph and convert to string value """
  36. poem_odt = os.path.join(
  37. os.path.dirname(__file__), u"examples", u"serious_poem.odt")
  38. d = load(poem_odt)
  39. shouldbe = 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. "
  40. #self.assertEqual(shouldbe, d.body)
  41. self.assertEqual(shouldbe, unicode(d.body))
  42. def test_link(self):
  43. """ Create a link """
  44. textdoc = OpenDocumentText()
  45. para = text.P()
  46. anchor = text.A(href="http://www.com/", text="A link label")
  47. para.addElement(anchor)
  48. textdoc.text.addElement(para)
  49. self.assertEqual(1, 1)
  50. def test_simple_link(self):
  51. """ Create a link """
  52. textdoc = OpenDocumentText()
  53. para = text.P()
  54. anchor = text.A(href="http://www.com/", type="simple", text="A link label")
  55. para.addElement(anchor)
  56. textdoc.text.addElement(para)
  57. def test_extended_link(self):
  58. """ Create a link """
  59. textdoc = OpenDocumentText()
  60. para = text.P()
  61. self.assertRaises(ValueError, text.A, href="http://www.com/", type="extended", text="A link label")
  62. if __name__ == '__main__':
  63. unittest.main()