From b80fa9db6bab6cdb2856874b606a93149cfc1af2 Mon Sep 17 00:00:00 2001 From: historia Date: Mon, 17 Aug 2026 19:19:40 -0400 Subject: feat(converter): add per-chapter and m4b output --- tests/test_extractors.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests/test_extractors.py') 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() -- cgit v1.2.3