Skip to content

Commit 1e06529

Browse files
committed
test(tests/test_text_editor.py): enhance error handling tests for environment validation and file reading
feat(tests/test_text_editor.py): add test for handling FileNotFoundError when reading a non-existent file
1 parent 72a6884 commit 1e06529

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tests/test_text_editor.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,17 @@ def mock_validate_environment(self):
902902
monkeypatch.setattr(TextEditor, "_validate_environment", mock_validate_environment)
903903

904904
# Verify that initialization fails with the expected error
905-
with pytest.raises(EnvironmentError) as excinfo:
905+
with pytest.raises(EnvironmentError, match="Failed to validate environment"):
906906
TextEditor()
907907

908-
assert "Failed to validate environment" in str(excinfo.value)
908+
909+
@pytest.mark.asyncio
910+
async def test_read_file_not_found_error(editor, tmp_path):
911+
"""Test FileNotFoundError handling when reading a non-existent file."""
912+
non_existent_file = tmp_path / "does_not_exist.txt"
913+
914+
with pytest.raises(FileNotFoundError) as excinfo:
915+
await editor._read_file(str(non_existent_file))
916+
917+
assert "File not found:" in str(excinfo.value)
918+
assert str(non_existent_file) in str(excinfo.value)

0 commit comments

Comments
 (0)