-
Notifications
You must be signed in to change notification settings - Fork 1
🎨 Palette: Enhance CLI interaction (Graceful Exit & Dynamic Progress) #193
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
Changes from all commits
79aebc9
c62bfa1
f77ce5e
50343f4
b989de9
01f4d27
1ed4ab8
bb2927b
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 | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -532,3 +532,102 @@ | |||||||||||||||||||||||||||||||||||||||||
| # Color codes (accessing instance Colors or m.Colors) | ||||||||||||||||||||||||||||||||||||||||||
| assert m.Colors.CYAN in combined | ||||||||||||||||||||||||||||||||||||||||||
| assert m.Colors.ENDC in combined | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Case 14: get_validated_input handles KeyboardInterrupt gracefully | ||||||||||||||||||||||||||||||||||||||||||
| def test_get_validated_input_interrupt(monkeypatch, capsys): | ||||||||||||||||||||||||||||||||||||||||||
| m = reload_main_with_env(monkeypatch) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Mock input to raise KeyboardInterrupt | ||||||||||||||||||||||||||||||||||||||||||
| monkeypatch.setattr("builtins.input", MagicMock(side_effect=KeyboardInterrupt)) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| with pytest.raises(SystemExit) as e: | ||||||||||||||||||||||||||||||||||||||||||
| m.get_validated_input("Prompt: ", lambda x: True, "Error") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Check exit code is 130 | ||||||||||||||||||||||||||||||||||||||||||
| assert e.value.code == 130 | ||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Check friendly message | ||||||||||||||||||||||||||||||||||||||||||
| captured = capsys.readouterr() | ||||||||||||||||||||||||||||||||||||||||||
| assert "Input cancelled" in captured.out | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+537
to
+552
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. This test is great for # Case 14: get_validated_input handles graceful exit on interrupt/EOF
@pytest.mark.parametrize("exception", [KeyboardInterrupt, EOFError])
@pytest.mark.parametrize("is_password, mock_path", [
(False, "builtins.input"),
(True, "getpass.getpass"),
])
def test_get_validated_input_graceful_exit(monkeypatch, capsys, exception, is_password, mock_path):
m = reload_main_with_env(monkeypatch)
# Mock input to raise the specified exception
monkeypatch.setattr(mock_path, MagicMock(side_effect=exception))
with pytest.raises(SystemExit) as e:
m.get_validated_input("Prompt: ", lambda x: True, "Error", is_password=is_password)
# Check exit code is 130
assert e.value.code == 130
# Check friendly message
captured = capsys.readouterr()
assert "Input cancelled" in captured.out
|
||||||||||||||||||||||||||||||||||||||||||
| assert "Input cancelled" in captured.out | |
| assert "Input cancelled" in captured.out | |
| # Case 15: get_validated_input handles EOFError gracefully | |
| def test_get_validated_input_eof(monkeypatch, capsys): | |
| m = reload_main_with_env(monkeypatch) | |
| # Mock input to raise EOFError to simulate end-of-input (e.g., Ctrl-D) | |
| monkeypatch.setattr("builtins.input", MagicMock(side_effect=EOFError)) | |
| with pytest.raises(SystemExit) as e: | |
| m.get_validated_input("Prompt: ", lambda x: True, "Error") | |
| # Check exit code is 130, same as KeyboardInterrupt | |
| assert e.value.code == 130 | |
| # Check the same friendly cancellation message is shown | |
| captured = capsys.readouterr() | |
| assert "Input cancelled" in captured.out |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
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 new cancellation handling also covers EOFError (Ctrl+D), but the tests only exercise KeyboardInterrupt. Add a test case for EOFError (or parametrize the test to cover both exceptions) so this new behavior is guarded against regressions.