-
Notifications
You must be signed in to change notification settings - Fork 7
Suppress expected file not found error LOG #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,6 +188,44 @@ async def test_delete_prefix_list_failure(self, mock_list_files: AsyncMock) -> N | |
with pytest.raises(Exception, match="Failed to list files"): | ||
await ObjectStore.delete_prefix(prefix="prefix/") | ||
|
||
@patch("application_sdk.services.objectstore.DaprClient") | ||
@patch("application_sdk.services.objectstore.logger") | ||
async def test_get_content_file_not_found_logs_debug( | ||
self, mock_logger: MagicMock, mock_dapr_client: MagicMock | ||
) -> None: | ||
"""Test that file not found errors are logged at DEBUG level.""" | ||
mock_client = MagicMock() | ||
mock_client.invoke_binding.side_effect = Exception("file not found") | ||
mock_dapr_client.return_value.__enter__.return_value = mock_client | ||
|
||
with pytest.raises(Exception): | ||
await ObjectStore.get_content("nonexistent/file.txt") | ||
|
||
# Verify debug log was called instead of error log | ||
mock_logger.debug.assert_called_once_with( | ||
"File not found in object store: nonexistent/file.txt" | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Incorrect Debug Log in File Not Found TestThe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure about tests code would love any input |
||
mock_logger.error.assert_not_called() | ||
|
||
@patch("application_sdk.services.objectstore.DaprClient") | ||
@patch("application_sdk.services.objectstore.logger") | ||
async def test_get_content_other_error_logs_error( | ||
self, mock_logger: MagicMock, mock_dapr_client: MagicMock | ||
) -> None: | ||
"""Test that non-file-not-found errors are still logged at ERROR level.""" | ||
mock_client = MagicMock() | ||
mock_client.invoke_binding.side_effect = Exception("Connection timeout") | ||
mock_dapr_client.return_value.__enter__.return_value = mock_client | ||
|
||
with pytest.raises(Exception): | ||
await ObjectStore.get_content("test/file.txt") | ||
|
||
# Verify error log was called for non-file-not-found errors | ||
mock_logger.error.assert_called_once_with( | ||
"Error getting file content for test/file.txt: Connection timeout" | ||
) | ||
mock_logger.debug.assert_not_called() | ||
|
||
# @patch("application_sdk.services.objectstore.ObjectStore.list_files", new_callable=AsyncMock) | ||
# @patch("application_sdk.services.objectstore.ObjectStore._download_file", new_callable=AsyncMock) | ||
# async def test_download_directory_success( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string matching logic is too broad and could incorrectly classify non-file-related "not found" errors. Consider using more specific error detection, such as checking exception types or more precise error message patterns that are specific to file operations.
Copilot uses AI. Check for mistakes.