8000 gh-129061: Fix `FORCE_COLOR` and `NO_COLOR` when empty strings by hugovk · Pull Request #129140 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-129061: Fix FORCE_COLOR and NO_COLOR when empty strings #129140

8000
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

Merged
merged 8 commits into from
Jan 27, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test cases for empty values
  • Loading branch information
hugovk committed Jan 25, 2025
commit 5027272232e49b98d1999ea552007f089293811d
7 changes: 7 additions & 0 deletions Lib/test/test__colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ def check(env, fallback, expected):
check({'TERM': ''}, fallback, fallback)
check({'FORCE_COLOR': '1'}, fallback, True)
check({'FORCE_COLOR': '0'}, fallback, True)
check({'FORCE_COLOR': ''}, fallback, fallback)
check({'NO_COLOR': '1'}, fallback, False)
check({'NO_COLOR': '0'}, fallback, False)
check({'NO_COLOR': ''}, fallback, fallback)

check({'TERM': 'dumb', 'FORCE_COLOR': '1'}, False, True)
check({'FORCE_COLOR': '1', 'NO_COLOR': '1'}, True, False)
check({'FORCE_COLOR': '1', 'NO_COLOR': ''}, True, True)
check({'FORCE_COLOR': '', 'NO_COLOR': '1'}, True, False)
check({'FORCE_COLOR': '', 'NO_COLOR': ''}, True, True)

for ignore_environment in False, True:
# Simulate running with or without `-E`.
Expand All @@ -64,7 +69,9 @@ def check(env, fallback, expected):

check({'TERM': 'dumb', 'PYTHON_COLORS': '1'}, False, not ignore_environment)
check({'NO_COLOR': '1', 'PYTHON_COLORS': '1'}, False, not ignore_environment)
check({'NO_COLOR': '', 'PYTHON_COLORS': '1'}, False, not ignore_environment)
check({'FORCE_COLOR': '1', 'PYTHON_COLORS': '0'}, True, ignore_environment)
check({'FORCE_COLOR': '', 'PYTHON_COLORS': '0'}, True, ignore_environment)

@unittest.skipUnless(sys.platform == "win32", "requires Windows")
def test_colorized_detection_checks_on_windows(self):
Expand Down
0