aboutsummaryrefslogtreecommitdiff
path: root/app/tests/test_extractors.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-26 01:18:56 -0400
committerhistoria <historiavg@proton.me>2026-08-26 01:18:56 -0400
commit104a0d65c1ba37847c15b64212b7fec8ba371ccb (patch)
tree71555cb9dfce790c0be998267c2dbe8be5549cc5 /app/tests/test_extractors.py
parent29aa2c8f18516e82429a9e751a74d48284f67e9c (diff)
downloadtts-audiobook-generator-104a0d65c1ba37847c15b64212b7fec8ba371ccb.tar.gz
fix: broken venv imports
Diffstat (limited to 'app/tests/test_extractors.py')
-rw-r--r--app/tests/test_extractors.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/app/tests/test_extractors.py b/app/tests/test_extractors.py
index ae1794c..64666ba 100644
--- a/app/tests/test_extractors.py
+++ b/app/tests/test_extractors.py
@@ -7,6 +7,25 @@ from pathlib import Path
from converter.extractors import extract_text
+def _ebooklib_usable() -> bool:
+ """True when ebooklib's EPUB reader imports (it needs a working lxml)."""
+ try:
+ from ebooklib import epub # noqa: F401
+ except Exception:
+ return False
+ return True
+
+
+# The managed env can end up with compiled wheels that cannot load on this
+# platform (e.g. glibc lxml under a musl interpreter) — the tool repairs or
+# degrades at runtime, and these tests must degrade with it instead of
+# failing. Relaunch audiobook.py once (or delete app/envs/tts) to rebuild.
+requires_epub = unittest.skipUnless(
+ _ebooklib_usable(),
+ "ebooklib is unusable in this environment "
+ "(its compiled dependency failed to import)")
+
+
class TxtExtractionTests(unittest.TestCase):
def _extract(self, data: bytes) -> str:
with tempfile.TemporaryDirectory() as tmp:
@@ -67,6 +86,7 @@ class EpubExtractionTests(unittest.TestCase):
except ImportError:
self.skipTest("ebooklib not installed")
+ @requires_epub
def test_ebooklib_extraction(self):
# Regression test: the ebooklib path used to silently return "" due to
# isinstance(item, ebooklib.ITEM_DOCUMENT) (an int, not a class).
@@ -81,6 +101,7 @@ class EpubExtractionTests(unittest.TestCase):
self.assertIn("First chapter text.", html)
self.assertIn("Second chapter text.", html)
+ @requires_epub
def test_epub_extraction_follows_spine_order(self):
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "book.epub"
@@ -100,6 +121,7 @@ class ExtractSectionsTests(unittest.TestCase):
except ImportError:
self.skipTest("ebooklib not installed")
+ @requires_epub
def test_epub_sections_split_on_chapters(self):
from converter.extractors import extract_sections
@@ -126,6 +148,7 @@ class ExtractSectionsTests(unittest.TestCase):
self.assertEqual(sections[0].title, "book")
self.assertEqual(sections[0].text, "Hello world.")
+ @requires_epub
def test_single_chapter_epub_keeps_chapter_title(self):
from converter.extractors import extract_sections
@@ -152,6 +175,7 @@ class ExtractBookTests(unittest.TestCase):
self.assertEqual(book.author, "")
self.assertEqual(len(book.sections), 1)
+ @requires_epub
def test_epub_metadata_harvested(self):
try:
import ebooklib # noqa: F401