Skip to content

Commit fcb871a

Browse files
author
danameyer
committed
add tests for parse_xml_file. Refs #5.
1 parent 2814868 commit fcb871a

59 files changed

Lines changed: 18 additions & 523 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/unit_tests/parse_textlines_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import os
22
import unittest
3+
from unittest.mock import patch
4+
5+
from flow_preprocessor.exceptions.exceptions import ParseTextLinesException
36
from flow_preprocessor.preprocessing_logic.parse_textlines import Line, PageParser, Metadata, Coordinate, Page
47
from lxml import etree as et
58

@@ -228,6 +231,21 @@ def test_get_line_text_without_abbreviations(self):
228231
expected_output = "Int erste quam den Steden en breff van dem hertogen van Sleswik"
229232
self.assertEqual(expected_output, result)
230233

234+
def test_parse_xml_file_with_invalid_xml(self):
235+
invalid_xml = "<invalid><xml></invalid>"
236+
237+
with patch('builtins.open', unittest.mock.mock_open(read_data=invalid_xml)):
238+
with self.assertRaises(ParseTextLinesException):
239+
self.parser_transkribus.parse_xml_file("invalid_file.xml")
240+
241+
self.assertIn("invalid_file.xml", self.parser_transkribus.failed_processing)
242+
243+
def test_parse_xml_file_with_nonexistent_file(self):
244+
with self.assertRaises(ParseTextLinesException):
245+
self.parser_transkribus.parse_xml_file("nonexistent_file.xml")
246+
247+
self.assertIn("nonexistent_file.xml", self.parser_transkribus.failed_processing)
248+
231249

232250
if __name__ == '__main__':
233251
unittest.main()

0 commit comments

Comments
 (0)