fix: raise ImportError during PDFKnowledgeSource instantiation when pdfplumber is missing

- Add __init__ method to PDFKnowledgeSource that checks PDFPLUMBER_AVAILABLE
- Update test_optional_dependencies.py to expect ImportError during instantiation
- Fixes test_optional_pdf_import_error in test_lite_installation.py
- Ensures consistent behavior across all optional dependency implementations

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-06-18 10:40:59 +00:00
parent 8e97e6e5f3
commit c1984e4406
2 changed files with 10 additions and 3 deletions

View File

@@ -44,10 +44,8 @@ class TestOptionalDependencies:
test_file.touch()
try:
pdf_source = PDFKnowledgeSource(file_paths=["test.pdf"])
with pytest.raises(ImportError) as exc_info:
pdf_source._import_pdfplumber()
PDFKnowledgeSource(file_paths=["test.pdf"])
assert "pdfplumber is required" in str(exc_info.value)
assert "crewai[knowledge]" in str(exc_info.value)