testmoinmoin.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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, os, os.path
  21. from odf.opendocument import OpenDocumentText
  22. from odf import style, text
  23. from odf.text import P, H, LineBreak
  24. from odf import odf2moinmoin
  25. class TestSimple(unittest.TestCase):
  26. def setUp(self):
  27. textdoc = OpenDocumentText()
  28. p = P(text=u"Hello World!")
  29. textdoc.text.addElement(p)
  30. textdoc.save(u"TEST.odt")
  31. self.saved = True
  32. def tearDown(self):
  33. if self.saved:
  34. os.unlink(u"TEST.odt")
  35. def test_simple(self):
  36. result = odf2moinmoin.ODF2MoinMoin(u"TEST.odt")
  37. self.assertEqual(u'Hello World!\n', result.toString())
  38. class TestHeadings(unittest.TestCase):
  39. saved = False
  40. def tearDown(self):
  41. if self.saved:
  42. os.unlink(u"TEST.odt")
  43. def test_headings(self):
  44. textdoc = OpenDocumentText()
  45. textdoc.text.addElement(H(outlinelevel=1, text=u"Heading 1"))
  46. textdoc.text.addElement(P(text=u"Hello World!"))
  47. textdoc.text.addElement(H(outlinelevel=2, text=u"Heading 2"))
  48. textdoc.save(u"TEST.odt")
  49. self.saved = True
  50. result = odf2moinmoin.ODF2MoinMoin(u"TEST.odt")
  51. self.assertEqual(u'= Heading 1 =\n\nHello World!\n== Heading 2 ==\n\n', result.toString())
  52. def test_linebreak(self):
  53. textdoc = OpenDocumentText()
  54. p = P(text=u"Hello World!")
  55. textdoc.text.addElement(p)
  56. p.addElement(LineBreak())
  57. p.addText(u"Line 2")
  58. textdoc.save(u"TEST.odt")
  59. self.saved = True
  60. result = odf2moinmoin.ODF2MoinMoin(u"TEST.odt")
  61. self.assertEqual(u'Hello World![[BR]]Line 2\n', result.toString())
  62. class TestExampleDocs(unittest.TestCase):
  63. def test_twolevellist(self):
  64. twolevellist_odt = os.path.join(
  65. os.path.dirname(__file__), u"examples", u"twolevellist.odt")
  66. result = odf2moinmoin.ODF2MoinMoin(twolevellist_odt)
  67. #FIXME: Item c must only have one newline before
  68. self.assertEqual(u"Line 1\n * Item A\n * Item B\n * Subitem B.1\n * '''Subitem B.2 (bold)'''\n\n * Item C\n\nLine 4\n", result.toString())
  69. def test_simplestyles(self):
  70. """ The simplestyles.odt has BOLD set in the paragraph style which is
  71. then turned OFF in the text styles. That is difficult to implement
  72. in MoinMoin, and currently ignored.
  73. """
  74. simplestyles_odt = os.path.join(
  75. os.path.dirname(__file__), u"examples", u"simplestyles.odt")
  76. result = odf2moinmoin.ODF2MoinMoin(simplestyles_odt)
  77. # The correct expected:
  78. #expected = "\nPlain text\n\n'''Bold'''\n\n''Italic''\n\n'''''Bold italic'''''\n\n__Underline__\n\n''__Underline italic__''\n\n'''''__Underline bold italic__'''''\n\nKm^2^ - superscript\n\nH,,2,,O - subscript\n\n~~Strike-through~~\n"
  79. # The simple-minded expected
  80. expected = u"Plain text\n\n'''Bold'''\n\n'''''Italic'''''\n\n'''''Bold italic'''''\n\n'''''__Underline__'''''\n\n'''''__Underline italic__'''''\n\n'''''__Underline bold italic__'''''\n\nKm^2^ - superscript\n\nH,,2,,O - subscript\n\n\n"
  81. self.assertEqual(expected, result.toString())
  82. def test_parastyles(self):
  83. parastyles_odt = os.path.join(
  84. os.path.dirname(__file__), u"examples", u"parastyles.odt")
  85. result = odf2moinmoin.ODF2MoinMoin(parastyles_odt)
  86. expected = u"Plain text\n\n'''Bold'''\n\n''Italic''\n\n'''''Bold italic'''''\n\n__Underline__\n\n''__Underline italic__''\n\n'''''__Underline bold italic__'''''\n\nKm^2^ - superscript\n\nH,,2,,O - subscript\n\n~~Strike-through~~\n"
  87. self.assertEqual(expected, result.toString())
  88. def test_simplelist(self):
  89. simplelist_odt = os.path.join(
  90. os.path.dirname(__file__), u"examples", u"simplelist.odt")
  91. result = odf2moinmoin.ODF2MoinMoin(simplelist_odt)
  92. self.assertEqual(u"Line 1\n * Item A\n * Item B\n\nLine 4\n", result.toString())
  93. def test_simpletable(self):
  94. simpletable_odt = os.path.join(
  95. os.path.dirname(__file__), u"examples", u"simpletable.odt")
  96. result = odf2moinmoin.ODF2MoinMoin(simpletable_odt)
  97. self.assertEqual(u"\n||Cell 1||Cell 2||\n||'''Cell 3 (bold)'''||''Cell 4 (italic)''||\n", result.toString())
  98. if __name__ == '__main__':
  99. unittest.main()