Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/crewai-tools/src/crewai_tools/rag/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ def get_file_type(path: str) -> DataType | None:
".xml": DataType.XML,
".txt": DataType.TEXT_FILE,
}
path_lower = path.lower()
for ext, dtype in mapping.items():
if path.endswith(ext):
if path_lower.endswith(ext):
return dtype
return None

Expand Down
60 changes: 60 additions & 0 deletions lib/crewai-tools/tests/rag/test_data_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import tempfile
from collections.abc import Callable, Iterator

from crewai_tools.rag.data_types import DataType, DataTypes
import pytest


@pytest.fixture
def temp_file() -> Iterator[Callable[[str], str]]:
created_files: list[str] = []

def _create(suffix: str) -> str:
f = tempfile.NamedTemporaryFile(mode="w", suffix=suffix, delete=False)
f.write("content")
f.close()
created_files.append(f.name)
return f.name

yield _create

for path in created_files:
os.unlink(path)


class TestDataTypesFromContent:
@pytest.mark.parametrize(
"suffix,expected",
[
(".pdf", DataType.PDF_FILE),
(".PDF", DataType.PDF_FILE),
(".csv", DataType.CSV),
(".CSV", DataType.CSV),
(".docx", DataType.DOCX),
(".DOCX", DataType.DOCX),
(".json", DataType.JSON),
(".Json", DataType.JSON),
(".xml", DataType.XML),
(".XML", DataType.XML),
(".md", DataType.MDX),
(".MD", DataType.MDX),
],
)
def test_file_extension_detection_is_case_insensitive(
self, temp_file: Callable[[str], str], suffix: str, expected: DataType
) -> None:
path = temp_file(suffix)
assert DataTypes.from_content(path) == expected

def test_uppercase_pdf_url_is_detected_as_pdf(self) -> None:
assert (
DataTypes.from_content("https://example.com/file.PDF")
== DataType.PDF_FILE
)

def test_lowercase_pdf_url_is_detected_as_pdf(self) -> None:
assert (
DataTypes.from_content("https://example.com/file.pdf")
== DataType.PDF_FILE
)