diff options
Diffstat (limited to 'tests/test_extractors.py')
| -rw-r--r-- | tests/test_extractors.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_extractors.py b/tests/test_extractors.py index c497267..09b688e 100644 --- a/tests/test_extractors.py +++ b/tests/test_extractors.py @@ -90,5 +90,39 @@ class EpubExtractionTests(unittest.TestCase): text.index("Second chapter text.")) +class ExtractSectionsTests(unittest.TestCase): + def setUp(self): + try: + import ebooklib # noqa: F401 + except ImportError: + self.skipTest("ebooklib not installed") + + def test_epub_sections_split_on_chapters(self): + from converter.extractors import extract_sections + + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / "book.epub" + _build_test_epub(path) + sections = extract_sections(path) + + self.assertEqual(len(sections), 2) + self.assertEqual(sections[0].title, "One") + self.assertEqual(sections[1].title, "Two") + self.assertIn("First chapter text.", sections[0].text) + self.assertIn("Second chapter text.", sections[1].text) + + def test_txt_is_single_section(self): + from converter.extractors import extract_sections + + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / "book.txt" + path.write_text("Hello world.", encoding="utf-8") + sections = extract_sections(path) + + self.assertEqual(len(sections), 1) + self.assertEqual(sections[0].title, "book") + self.assertEqual(sections[0].text, "Hello world.") + + if __name__ == "__main__": unittest.main() |
