Add a unit test for the workaround, and fix a bug
This commit is contained in:
@@ -683,9 +683,9 @@ def fix_ansi_codes_for_github_actions(text: str) -> str:
|
|||||||
ansi_codes: list[str] = []
|
ansi_codes: list[str] = []
|
||||||
output = ""
|
output = ""
|
||||||
|
|
||||||
for line in text.split("\n"):
|
for line in text.splitlines(keepends=True):
|
||||||
# add the current ANSI codes to the beginning of the line
|
# add the current ANSI codes to the beginning of the line
|
||||||
output += "".join(ansi_codes) + line + "\n"
|
output += "".join(ansi_codes) + line
|
||||||
|
|
||||||
# split the line at each ANSI code
|
# split the line at each ANSI code
|
||||||
parts = ansi_code_regex.split(line)
|
parts = ansi_code_regex.split(line)
|
||||||
|
|||||||
+35
-1
@@ -1,10 +1,16 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import textwrap
|
||||||
from pathlib import PurePath
|
from pathlib import PurePath
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from cibuildwheel.util import find_compatible_wheel, format_safe, prepare_command
|
from cibuildwheel.util import (
|
||||||
|
find_compatible_wheel,
|
||||||
|
fix_ansi_codes_for_github_actions,
|
||||||
|
format_safe,
|
||||||
|
prepare_command,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_format_safe():
|
def test_format_safe():
|
||||||
@@ -90,3 +96,31 @@ def test_find_compatible_wheel_found(wheel: str, identifier: str):
|
|||||||
)
|
)
|
||||||
def test_find_compatible_wheel_not_found(wheel: str, identifier: str):
|
def test_find_compatible_wheel_not_found(wheel: str, identifier: str):
|
||||||
assert find_compatible_wheel([PurePath(wheel)], identifier) is None
|
assert find_compatible_wheel([PurePath(wheel)], identifier) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_fix_ansi_codes_for_github_actions():
|
||||||
|
input = textwrap.dedent(
|
||||||
|
"""
|
||||||
|
This line is normal
|
||||||
|
\033[1mThis line is bold
|
||||||
|
This line is also bold
|
||||||
|
\033[31m this line is red and bold
|
||||||
|
This line is red and bold, too\033[0m
|
||||||
|
This line is normal again
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
expected = textwrap.dedent(
|
||||||
|
"""
|
||||||
|
This line is normal
|
||||||
|
\033[1mThis line is bold
|
||||||
|
\033[1mThis line is also bold
|
||||||
|
\033[1m\033[31m this line is red and bold
|
||||||
|
\033[1m\033[31mThis line is red and bold, too\033[0m
|
||||||
|
This line is normal again
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
output = fix_ansi_codes_for_github_actions(input)
|
||||||
|
|
||||||
|
assert output == expected
|
||||||
|
|||||||
Reference in New Issue
Block a user