Skip to content

Commit beadad6

Browse files
author
Yoshihiro Takahara
committed
Improve test coverage, modify description
1 parent aecd5f7 commit beadad6

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/test_text_editor.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,35 @@ async def test_read_file_contents_with_start_beyond_total(editor, tmp_path):
536536
assert content_hash == editor.calculate_hash("")
537537
assert total_lines == 3
538538
assert content_size == 0
539+
540+
541+
@pytest.mark.asyncio
542+
async def test_create_file_directory_creation_failure(editor, tmp_path, monkeypatch):
543+
"""Test handling of directory creation failure when creating a new file."""
544+
# Create a path with multiple nested directories
545+
deep_path = tmp_path / "deeply" / "nested" / "path" / "test.txt"
546+
547+
# Mock os.makedirs to raise an OSError
548+
def mock_makedirs(*args, **kwargs):
549+
raise OSError("Permission denied")
550+
551+
monkeypatch.setattr("os.makedirs", mock_makedirs)
552+
553+
# Attempt to create a new file
554+
result = await editor.edit_file_contents(
555+
str(deep_path),
556+
"", # Empty hash for new file
557+
[
558+
{
559+
"line_start": 1,
560+
"contents": "test content\n",
561+
}
562+
],
563+
)
564+
565+
# Verify proper error handling
566+
assert result["result"] == "error"
567+
assert "Failed to create directory" in result["reason"]
568+
assert "Permission denied" in result["reason"]
569+
assert result["file_hash"] is None
570+
assert result["content"] is None

0 commit comments

Comments
 (0)