File size: 837 Bytes
db06ffa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import tempfile
import unittest
from pathlib import Path

from zsgdp.config import load_config
from zsgdp.parsers.text_parser import TextParser
from zsgdp.profiling import profile_document


class TextParserTests(unittest.TestCase):
    def test_text_parser_extracts_elements_and_tables(self):
        with tempfile.TemporaryDirectory() as tmp:
            path = Path(tmp) / "sample.md"
            path.write_text("# Report\n\nParagraph.\n\n| A | B |\n| --- | --- |\n| 1 | 2 |\n", encoding="utf-8")
            profile = profile_document(path)

            candidate = TextParser().parse(path, profile, load_config())

        self.assertEqual(candidate.parser_name, "text")
        self.assertGreaterEqual(len(candidate.elements), 2)
        self.assertEqual(len(candidate.tables), 1)


if __name__ == "__main__":
    unittest.main()