From 5dee1b819b37fde43368b36c90e47f98f9d85036 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 18 Jun 2025 10:18:20 +0000 Subject: [PATCH] fix: resolve lint issues and test failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- check_deps.py | 12 +++++------ src/crewai/flow/flow_visualizer.py | 3 +-- tests/test_lite_installation.py | 4 ---- tests/test_optional_dependencies.py | 32 ++++++++++++++++++++--------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/check_deps.py b/check_deps.py index 49a4f5b51..70d77a639 100644 --- a/check_deps.py +++ b/check_deps.py @@ -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') diff --git a/src/crewai/flow/flow_visualizer.py b/src/crewai/flow/flow_visualizer.py index a6b38ecf9..f2f0dc70d 100644 --- a/src/crewai/flow/flow_visualizer.py +++ b/src/crewai/flow/flow_visualizer.py @@ -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, diff --git a/tests/test_lite_installation.py b/tests/test_lite_installation.py index 77b13efca..12b25115a 100644 --- a/tests/test_lite_installation.py +++ b/tests/test_lite_installation.py @@ -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 diff --git a/tests/test_optional_dependencies.py b/tests/test_optional_dependencies.py index 157511b49..ef913e1d3 100644 --- a/tests/test_optional_dependencies.py +++ b/tests/test_optional_dependencies.py @@ -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."""