"""Pytest configuration and fixtures for LocalFS tests."""
import tempfile
import shutil
from pathlib import Path
import pytest
@pytest.fixture
def temp_root():
"""Create a temporary root directory for testing."""
temp_dir = tempfile.mkdtemp(prefix="localfs_test_")
root_path = Path(temp_dir)
yield root_path
# Cleanup after test
shutil.rmtree(temp_dir, ignore_errors=True)
@pytest.fixture
def populated_temp_root(temp_root):
"""Create a temporary root directory with sample files and directories."""
# Create directory structure
(temp_root / "dir1").mkdir()
(temp_root / "dir2").mkdir()
(temp_root / "dir1" / "subdir1").mkdir()
(temp_root / "dir1" / "subdir2").mkdir()
(temp_root / "empty_dir").mkdir()
# Create text files
(temp_root / "file1.txt").write_text("Hello World\nThis is a test file.\nPython is awesome!")
(temp_root / "file2.txt").write_text("Another test file\nWith multiple lines\nFor testing")
(temp_root / "dir1" / "nested.txt").write_text("Nested file content\nInside dir1")
(temp_root / "dir1" / "subdir1" / "deep.txt").write_text("Deep nested file\nIn subdir1")
# Create files with different extensions
(temp_root / "script.py").write_text("#!/usr/bin/env python\nprint('Hello')")
(temp_root / "data.json").write_text('{"key": "value", "number": 42}')
(temp_root / "config.yml").write_text("setting: true\nvalue: 123")
(temp_root / "readme.md").write_text("# README\n\nThis is a readme file.")
# Create binary file
(temp_root / "binary.bin").write_bytes(b"\x00\x01\x02\x03\x04\x05\xff\xfe\xfd")
# Create files for search testing
(temp_root / "dir1" / "search_test.txt").write_text(
"This file contains the word SEARCH multiple times.\nSEARCH is here too."
)
(temp_root / "dir2" / "another.txt").write_text("Different content without the keyword")
yield temp_root
@pytest.fixture
def file_service(temp_root):
"""Create a FileService instance with temp root."""
from local_filesystem.services.file_service import FileService
return FileService(root=temp_root, max_file_size_mb=10)
@pytest.fixture
def directory_service(temp_root):
"""Create a DirectoryService instance with temp root."""
from local_filesystem.services.directory_service import DirectoryService
return DirectoryService(root=temp_root)
@pytest.fixture
def search_service(temp_root):
"""Create a SearchService instance with temp root."""
from local_filesystem.services.search_service import SearchService
return SearchService(root=temp_root, max_search_depth=10, max_file_size_mb=10)