-
Notifications
You must be signed in to change notification settings - Fork 1
🎨 Palette: Improved Dry Run Output #150
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
bf892e0
19a419b
6f2f5cd
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 |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import sys | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Missing module docstring Warning test
Missing module docstring
Check warningCode scanning / Pylint (reported by Codacy) Missing module docstring Warning test
Missing module docstring
|
||
| from unittest.mock import MagicMock | ||
| import main | ||
|
|
||
| def test_print_dry_run_plan_with_colors(monkeypatch): | ||
| """Verify print_dry_run_plan output with colors enabled.""" | ||
| # Force colors on | ||
| monkeypatch.setattr(main, "USE_COLORS", True) | ||
|
|
||
| # Since Colors class is evaluated at import time, we need to manually set color codes | ||
| # if the module was imported in a non-TTY environment | ||
| for attr, code in { | ||
| "HEADER": "\033[95m", | ||
Check warningCode scanning / Pylint (reported by Codacy) Wrong hanging indentation before block (add 4 spaces). Warning test
Wrong hanging indentation before block (add 4 spaces).
|
||
| "BLUE": "\033[94m", | ||
Check warningCode scanning / Pylint (reported by Codacy) Wrong hanging indentation before block (add 4 spaces). Warning test
Wrong hanging indentation before block (add 4 spaces).
|
||
| "CYAN": "\033[96m", | ||
Check warningCode scanning / Pylint (reported by Codacy) Wrong hanging indentation before block (add 4 spaces). Warning test
Wrong hanging indentation before block (add 4 spaces).
|
||
| "GREEN": "\033[92m", | ||
Check warningCode scanning / Pylint (reported by Codacy) Wrong hanging indentation before block (add 4 spaces). Warning test
Wrong hanging indentation before block (add 4 spaces).
|
||
| "WARNING": "\033[93m", | ||
Check warningCode scanning / Pylint (reported by Codacy) Wrong hanging indentation before block (add 4 spaces). Warning test
Wrong hanging indentation before block (add 4 spaces).
|
||
| "FAIL": "\033[91m", | ||
Check warningCode scanning / Pylint (reported by Codacy) Wrong hanging indentation before block (add 4 spaces). Warning test
Wrong hanging indentation before block (add 4 spaces).
|
||
| "ENDC": "\033[0m", | ||
Check warningCode scanning / Pylint (reported by Codacy) Wrong hanging indentation before block (add 4 spaces). Warning test
Wrong hanging indentation before block (add 4 spaces).
|
||
| "BOLD": "\033[1m", | ||
Check warningCode scanning / Pylint (reported by Codacy) Wrong hanging indentation before block (add 4 spaces). Warning test
Wrong hanging indentation before block (add 4 spaces).
|
||
| "UNDERLINE": "\033[4m", | ||
Check warningCode scanning / Pylint (reported by Codacy) Wrong hanging indentation before block (add 4 spaces). Warning test
Wrong hanging indentation before block (add 4 spaces).
|
||
| }.items(): | ||
| monkeypatch.setattr(main.Colors, attr, code) | ||
|
Comment on lines
+8
to
+23
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. The current method of enabling colors for this test is a bit brittle. By manually setting each color code, the test can become outdated if the # Force a TTY-like environment to test color output correctly
monkeypatch.setattr(sys.stdout, "isatty", lambda: True)
monkeypatch.setattr(sys.stderr, "isatty", lambda: True)
monkeypatch.delenv("NO_COLOR", raising=False)
# Reload the main module to re-evaluate USE_COLORS and the Colors class
# based on the mocked environment.
import importlib
importlib.reload(main) |
||
|
|
||
| # Mock stdout to capture print output | ||
| mock_stdout = MagicMock() | ||
| monkeypatch.setattr(sys, "stdout", mock_stdout) | ||
|
|
||
| plan = { | ||
| "profile": "test_profile", | ||
| "folders": [ | ||
| {"name": "Test Folder 1", "rules": 10}, | ||
| {"name": "Test Folder 2", "rules": 20}, | ||
| ] | ||
| } | ||
|
|
||
| main.print_dry_run_plan(plan) | ||
|
|
||
| # Aggregate all writes | ||
| # print() typically calls write(string) and write('\n') | ||
| combined_output = "".join([str(args[0]) for args, _ in mock_stdout.write.call_args_list]) | ||
|
|
||
| assert "📝 Dry Run Plan for Profile:" in combined_output | ||
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 noticeCode scanning / Bandit (reported by Codacy) 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.
|
||
| assert "test_profile" in combined_output | ||
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 noticeCode scanning / Bandit (reported by Codacy) 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.
|
||
| assert "Test Folder 1" in combined_output | ||
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 noticeCode scanning / Bandit (reported by Codacy) 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.
|
||
| assert "10 rules" in combined_output | ||
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 noticeCode scanning / Bandit (reported by Codacy) 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.
|
||
| # ANSI codes should be present (main.Colors.HEADER starts with \033[95m) | ||
| assert "\033[" in combined_output | ||
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 noticeCode scanning / Bandit (reported by Codacy) 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.
|
||
|
|
||
| def test_print_dry_run_plan_no_colors(monkeypatch): | ||
| """Verify print_dry_run_plan output without colors.""" | ||
| monkeypatch.setattr(main, "USE_COLORS", False) | ||
|
|
||
| mock_stdout = MagicMock() | ||
| monkeypatch.setattr(sys, "stdout", mock_stdout) | ||
|
|
||
| plan = { | ||
| "profile": "test_profile", | ||
| "folders": [ | ||
| {"name": "Test Folder 1", "rules": 10}, | ||
| ] | ||
| } | ||
|
|
||
| main.print_dry_run_plan(plan) | ||
|
|
||
| combined_output = "".join([str(args[0]) for args, _ in mock_stdout.write.call_args_list]) | ||
|
|
||
| assert "📝 Dry Run Plan for Profile:" in combined_output | ||
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 noticeCode scanning / Bandit (reported by Codacy) 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.
|
||
| assert "test_profile" in combined_output | ||
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 noticeCode scanning / Bandit (reported by Codacy) 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.
|
||
| assert "Test Folder 1" in combined_output | ||
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 noticeCode scanning / Bandit (reported by Codacy) 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.
|
||
| assert "10 rules" in combined_output | ||
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 noticeCode scanning / Bandit (reported by Codacy) 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.
|
||
| # No ANSI codes | ||
| assert "\033[" not in combined_output | ||
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 noticeCode scanning / Bandit (reported by Codacy) 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.
Comment on lines
+50
to
+73
|
||
|
|
||
| def test_print_dry_run_plan_empty_folders(monkeypatch): | ||
| """Verify output when no folders are present.""" | ||
| monkeypatch.setattr(main, "USE_COLORS", False) | ||
| mock_stdout = MagicMock() | ||
| monkeypatch.setattr(sys, "stdout", mock_stdout) | ||
|
|
||
| plan = { | ||
| "profile": "test_profile", | ||
| "folders": [] | ||
| } | ||
|
|
||
| main.print_dry_run_plan(plan) | ||
|
|
||
| combined_output = "".join([str(args[0]) for args, _ in mock_stdout.write.call_args_list]) | ||
| assert "(No folders found to sync)" in combined_output | ||
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 noticeCode scanning / Bandit (reported by Codacy) 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.
Comment on lines
+75
to
+89
|
||
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Missing function or method docstring Warning