testwrite.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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
  21. import io
  22. import zipfile
  23. from odf.opendocument import OpenDocumentText
  24. from odf import style, text
  25. from odf.text import P
  26. class TestWrite(unittest.TestCase):
  27. def test_write(self):
  28. """ document's write method """
  29. outfp = io.BytesIO()
  30. textdoc = OpenDocumentText()
  31. p = P(text=u"Æblegrød")
  32. p.addText(u' Blåbærgrød')
  33. textdoc.text.addElement(p)
  34. textdoc.write(outfp)
  35. outfp.seek(0)
  36. # outfp now contains the document.
  37. z = zipfile.ZipFile(outfp,"r")
  38. self.assertEqual(None, z.testzip())
  39. outfp.close()
  40. def test_topnode(self):
  41. """ Check that topnode is correct """
  42. textdoc = OpenDocumentText()
  43. self.assertEqual(8, len(textdoc.topnode.childNodes))
  44. self.assertEqual(textdoc, textdoc.topnode.ownerDocument)
  45. self.assertEqual(textdoc, textdoc.styles.ownerDocument)
  46. self.assertEqual(textdoc, textdoc.settings.ownerDocument)
  47. if __name__ == '__main__':
  48. unittest.main()