-
Notifications
You must be signed in to change notification settings - Fork 0
🧪 Add tests for Output.success in console.py #10
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
Open
acathon
wants to merge
1
commit into
main
Choose a base branch
from
test-console-success-1766197546182321515
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import pytest | ||
| from unittest.mock import patch, MagicMock | ||
|
|
||
| from fastman.console import Output, Style, Icons | ||
|
|
||
| class TestOutput: | ||
|
|
||
| @patch("fastman.console.HAS_RICH", True) | ||
| @patch("fastman.console.console") | ||
| @patch("fastman.console.logger.info") | ||
| def test_success_with_rich(self, mock_logger, mock_console): | ||
| Output.success("Rich success message", icon=True, prefix="[PRE]") | ||
|
|
||
| # Verify console print was called correctly | ||
| mock_console.print.assert_called_once_with(f"[success]{Icons.SUCCESS} [/success][PRE] Rich success message") | ||
|
|
||
| # Verify logger was called | ||
| mock_logger.assert_called_once_with("Rich success message") | ||
|
|
||
| @patch("fastman.console.HAS_RICH", False) | ||
| @patch("fastman.console.logger.info") | ||
| def test_success_without_rich(self, mock_logger, capsys): | ||
| Output.success("Normal success message", icon=True, prefix="[PRE]") | ||
|
|
||
| # Verify stdout | ||
| captured = capsys.readouterr() | ||
| expected_out = f"{Style.BRIGHT_GREEN}{Icons.SUCCESS} {Style.RESET}[PRE] Normal success message\n" | ||
| assert captured.out == expected_out | ||
|
|
||
| # Verify logger | ||
| mock_logger.assert_called_once_with("Normal success message") | ||
|
|
||
| @patch("fastman.console.HAS_RICH", False) | ||
| @patch("fastman.console.logger.info") | ||
| @patch("builtins.print", side_effect=[UnicodeEncodeError("ascii", "", 0, 1, "mock"), None]) | ||
| def test_success_without_rich_unicode_fallback(self, mock_print, mock_logger, capsys): | ||
| # We patch print with a side_effect that raises UnicodeEncodeError on the first call, | ||
| # then succeeds on the second (fallback) call. | ||
| # But wait, capsys won't capture patched print if we do it this way easily, so let's verify mock_print calls. | ||
| Output.success("Unicode fallback message", icon=True, prefix="[PRE]") | ||
|
|
||
| # Verify fallback print logic | ||
| assert mock_print.call_count == 2 | ||
| mock_print.assert_any_call(f"{Style.GREEN}[OK]{Style.RESET} [PRE] Unicode fallback message") | ||
|
|
||
| # Verify logger | ||
| mock_logger.assert_called_once_with("Unicode fallback message") | ||
|
|
||
| @patch("fastman.console.HAS_RICH", False) | ||
| @patch("fastman.console.logger.info") | ||
| def test_success_no_icon_no_prefix(self, mock_logger, capsys): | ||
| Output.success("Plain message", icon=False, prefix="") | ||
|
|
||
| captured = capsys.readouterr() | ||
| expected_out = f"{Style.BRIGHT_GREEN}{Style.RESET}Plain message\n" | ||
| assert captured.out == expected_out | ||
| mock_logger.assert_called_once_with("Plain message") | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Clean up stray developer comment and remove unused
capsysparameter.Lines 37–39 read like an in-progress internal thought ("But wait, capsys won't capture patched print if we do it this way easily, so let's verify mock_print calls.") that should not land in the committed test. Additionally,
capsysis declared on line 36 but never used —builtins.printis mocked, so the parameter is dead. Both should be removed for clarity.🧹 Proposed cleanup
🤖 Prompt for AI Agents