Initial release: cd-browser v0.1.0
This commit is contained in:
46
tests/test_filesystem.py
Normal file
46
tests/test_filesystem.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app.filesystem import DirectoryEntry, has_subdirectories, list_directories
|
||||
|
||||
|
||||
def test_has_subdirectories_detects_nested_directory(tmp_path: Path) -> None:
|
||||
parent = tmp_path / "parent"
|
||||
child = parent / "child"
|
||||
child.mkdir(parents=True)
|
||||
|
||||
assert has_subdirectories(parent) is True
|
||||
|
||||
|
||||
def test_has_subdirectories_returns_false_without_nested_directories(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
directory = tmp_path / "empty"
|
||||
directory.mkdir()
|
||||
(directory / "file.txt").write_text("content", encoding="utf-8")
|
||||
|
||||
assert has_subdirectories(directory) is False
|
||||
|
||||
|
||||
def test_list_directories_returns_sorted_directory_metadata(tmp_path: Path) -> None:
|
||||
alpha = tmp_path / "alpha"
|
||||
beta = tmp_path / "Beta"
|
||||
file_path = tmp_path / "notes.txt"
|
||||
|
||||
alpha.mkdir()
|
||||
beta.mkdir()
|
||||
(beta / "nested").mkdir()
|
||||
file_path.write_text("ignore me", encoding="utf-8")
|
||||
|
||||
assert list_directories(tmp_path) == [
|
||||
DirectoryEntry(name="alpha", path=alpha, has_children=False),
|
||||
DirectoryEntry(name="Beta", path=beta, has_children=True),
|
||||
]
|
||||
|
||||
|
||||
def test_list_directories_raises_for_missing_directory(tmp_path: Path) -> None:
|
||||
missing_path = tmp_path / "missing"
|
||||
|
||||
with pytest.raises(FileNotFoundError):
|
||||
list_directories(missing_path)
|
||||
Reference in New Issue
Block a user