1
1

test_fileio.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import os
  2. import sys
  3. import unittest
  4. try:
  5. from StringIO import StringIO
  6. except ImportError:
  7. from io import StringIO
  8. import odml
  9. from .util import TEST_RESOURCES_DIR as RES_DIR
  10. class TestTypes(unittest.TestCase):
  11. def setUp(self):
  12. self.file = os.path.join(RES_DIR, "example.odml")
  13. # Do not allow anything to be printed on STDOUT
  14. self.captured_stdout = StringIO()
  15. sys.stdout = self.captured_stdout
  16. def test_load_save(self):
  17. doc = odml.load(self.file)
  18. self.assertTrue(isinstance(doc, odml.doc.BaseDocument))
  19. file_name = "%s_copy" % self.file
  20. odml.save(doc, file_name)
  21. os.remove(file_name)
  22. def test_display(self):
  23. doc = odml.load(self.file)
  24. odml.display(doc)
  25. def test_invalid_parser(self):
  26. with self.assertRaises(NotImplementedError):
  27. odml.load(self.file, "html")
  28. doc = odml.load(self.file)
  29. with self.assertRaises(NotImplementedError):
  30. file_name = "%s_copy_html" % self.file
  31. odml.save(doc, file_name, "html")
  32. with self.assertRaises(NotImplementedError):
  33. odml.display(doc, "html")