test_parser_xml.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import os
  2. import unittest
  3. from odml.tools import xmlparser
  4. from odml.tools.parser_utils import ParserException, InvalidVersionException
  5. class TestXMLParser(unittest.TestCase):
  6. def setUp(self):
  7. dir_path = os.path.dirname(os.path.realpath(__file__))
  8. self.basepath = os.path.join(dir_path, "resources")
  9. self.xml_reader = xmlparser.XMLReader()
  10. def test_invalid_root(self):
  11. filename = "invalid_root.xml"
  12. message = "Expecting <odML>"
  13. with self.assertRaises(ParserException) as exc:
  14. _ = self.xml_reader.from_file(os.path.join(self.basepath, filename))
  15. self.assertIn(message, str(exc.exception))
  16. def test_missing_version(self):
  17. filename = "missing_version.xml"
  18. message = "Could not find format version attribute"
  19. with self.assertRaises(ParserException) as exc:
  20. _ = self.xml_reader.from_file(os.path.join(self.basepath, filename))
  21. self.assertIn(message, str(exc.exception))
  22. def test_invalid_version(self):
  23. filename = "invalid_version.xml"
  24. with self.assertRaises(InvalidVersionException):
  25. _ = self.xml_reader.from_file(os.path.join(self.basepath, filename))