fix: resolve lint issues and test failures

- Remove unused imports from check_deps.py, flow_visualizer.py, and test files
- Add noqa comments for intentional imports in check_deps.py
- Fix PDF test to properly create temporary test file and handle missing dependencies
- Address all lint F401 errors identified in CI

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-06-18 10:18:20 +00:00
parent b2aa5fa39a
commit 5dee1b819b
4 changed files with 29 additions and 22 deletions

View File

@@ -3,37 +3,37 @@
print("Checking optional dependencies availability:")
try:
import chromadb
import chromadb # noqa: F401
print('chromadb: AVAILABLE')
except ImportError:
print('chromadb: NOT AVAILABLE')
try:
import pdfplumber
import pdfplumber # noqa: F401
print('pdfplumber: AVAILABLE')
except ImportError:
print('pdfplumber: NOT AVAILABLE')
try:
import pyvis
import pyvis # noqa: F401
print('pyvis: AVAILABLE')
except ImportError:
print('pyvis: NOT AVAILABLE')
try:
import opentelemetry
import opentelemetry # noqa: F401
print('opentelemetry: AVAILABLE')
except ImportError:
print('opentelemetry: NOT AVAILABLE')
try:
import auth0
import auth0 # noqa: F401
print('auth0: AVAILABLE')
except ImportError:
print('auth0: NOT AVAILABLE')
try:
import aisuite
import aisuite # noqa: F401
print('aisuite: AVAILABLE')
except ImportError:
print('aisuite: NOT AVAILABLE')

View File

@@ -1,7 +1,6 @@
# flow_visualizer.py
import os
from pathlib import Path
try:
from pyvis.network import Network
@@ -13,7 +12,7 @@ except ImportError:
from crewai.flow.config import COLORS, NODE_STYLES
from crewai.flow.html_template_handler import HTMLTemplateHandler
from crewai.flow.legend_generator import generate_legend_items_html, get_legend_items
from crewai.flow.path_utils import safe_path_join, validate_path_exists
from crewai.flow.path_utils import safe_path_join
from crewai.flow.utils import calculate_node_levels
from crewai.flow.visualization_utils import (
add_edges,

View File

@@ -1,10 +1,6 @@
"""Test that crewAI lite installation works with minimal dependencies."""
import pytest
import subprocess
import sys
import tempfile
import os
from pathlib import Path
from unittest.mock import patch, Mock

View File

@@ -2,7 +2,6 @@
import pytest
from unittest.mock import patch, Mock
import sys
class TestOptionalDependencies:
@@ -35,15 +34,28 @@ class TestOptionalDependencies:
def test_pdfplumber_import_error(self):
"""Test that PDF knowledge source raises helpful error without pdfplumber."""
with patch.dict('sys.modules', {'pdfplumber': None}):
from crewai.knowledge.source.pdf_knowledge_source import PDFKnowledgeSource
pdf_source = PDFKnowledgeSource(file_paths=["test.pdf"])
with pytest.raises(ImportError) as exc_info:
pdf_source._import_pdfplumber()
assert "pdfplumber is required" in str(exc_info.value)
assert "crewai[knowledge]" in str(exc_info.value)
with patch('crewai.knowledge.source.pdf_knowledge_source.PDFPLUMBER_AVAILABLE', False):
from crewai.knowledge.source.pdf_knowledge_source import PDFKnowledgeSource
from pathlib import Path
knowledge_dir = Path("knowledge")
knowledge_dir.mkdir(exist_ok=True)
test_file = knowledge_dir / "test.pdf"
test_file.touch()
try:
pdf_source = PDFKnowledgeSource(file_paths=["test.pdf"])
with pytest.raises(ImportError) as exc_info:
pdf_source._import_pdfplumber()
assert "pdfplumber is required" in str(exc_info.value)
assert "crewai[knowledge]" in str(exc_info.value)
finally:
if test_file.exists():
test_file.unlink()
if knowledge_dir.exists() and not any(knowledge_dir.iterdir()):
knowledge_dir.rmdir()
def test_pyvis_import_error(self):
"""Test that flow visualization raises helpful error without pyvis."""