Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 17 additions & 13 deletions rege/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,23 @@ def test_colors_defined(self):

def test_colors_disable(self):
"""Test colors can be disabled."""
# Save original values
original_red = Colors.RED
original_reset = Colors.RESET

# Disable
Colors.disable()

assert Colors.RED == ""
assert Colors.RESET == ""

# Restore
Colors.RED = original_red
Colors.RESET = original_reset
# Save original values: disable() blanks every uppercase attribute,
# so snapshot the full class state — restoring only some attributes
# leaks blanked colors to later tests in the same process.
original = {
attr: getattr(Colors, attr) for attr in dir(Colors) if attr.isupper()
}

try:
# Disable
Colors.disable()

assert Colors.RED == ""
assert Colors.RESET == ""
finally:
# Restore
for attr, value in original.items():
setattr(Colors, attr, value)


class TestColorize:
Expand Down
30 changes: 17 additions & 13 deletions rege/tests/test_formatting_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ class TestColorsDisable:
def test_colors_disable_sets_empty_strings(self):
"""Test Colors.disable sets all uppercase attrs to empty strings."""
from rege.formatting import Colors
# Save original values
original_reset = Colors.RESET
original_red = Colors.RED
# Save original values: disable() blanks every uppercase attribute,
# so snapshot the full class state — restoring only some attributes
# leaks blanked colors to later tests in the same process.
original = {
attr: getattr(Colors, attr) for attr in dir(Colors) if attr.isupper()
}

Colors.disable()

assert Colors.RESET == ""
assert Colors.RED == ""
assert Colors.GREEN == ""
assert Colors.BOLD_RED == ""
assert Colors.DIM == ""
try:
Colors.disable()

# Restore for other tests
Colors.RESET = original_reset
Colors.RED = original_red
assert Colors.RESET == ""
assert Colors.RED == ""
assert Colors.GREEN == ""
assert Colors.BOLD_RED == ""
assert Colors.DIM == ""
finally:
# Restore for other tests
for attr, value in original.items():
setattr(Colors, attr, value)

def test_colors_disable_no_color_env(self):
"""Test that NO_COLOR env triggers disable at import time."""
Expand Down
Loading