def test_strip_escapes(): assert "Hi there" == strip_escapes( colorize("Hi there", Colors.Red, start=3) ) assert strip_escapes( colorize("Hi", None, bold=True) + " there, " + colorize("stranger", Colors.Green, bold=True) ) == "Hi there, stranger"
def test_colorize_v2(): assert ( get_code(Colors.Red) + "Hi there" + get_code(None) ) == colorize("Hi there", Colors.Red) assert ( "H" + get_code(Colors.Red) + "i ther" + get_code(None) + "e" ) == colorize("Hi there", Colors.Red, start=1, end=7)
def _get_colorize_formatter_map(violation): formatter_map = _get_formatter_map(violation) colorized_formatter_map = {} for key, value in formatter_map.items(): if key in FORMAT_COLOR_MAP: Color = FORMAT_COLOR_MAP[key] colorized_formatter_map[key] = colorize(str(value), Color()) else: colorized_formatter_map[key] = value return colorized_formatter_map
def test_colorize1(): assert ( get_code(Colors.Red) + "Hi there" + get_code(None) ) == colorize("Hi there", Colors.Red)
from ansicolor import Colors from ansicolor import colorize print(colorize('''"I'm blue", said the smurf.''', Colors.Blue, start=1, end=9))
from ansicolor import Colors from ansicolor import colorize print(colorize("I'm blue", Colors.Blue))